iPXE
|
Weierstrass elliptic curves. More...
Go to the source code of this file.
Macros | |
#define | WEIERSTRASS_zero WEIERSTRASS_a |
Zero register (for add/subtract operations. More... | |
#define | WEIERSTRASS_REGISTER(name) _C2 ( WEIERSTRASS_, name ) |
Construct big integer register index. More... | |
#define | WEIERSTRASS_OP(opcode, dest, left, right) |
Define a bytecode operation. More... | |
#define | WEIERSTRASS_OPCODE(op) ( ( (op) >> 12 ) & 0xf ) |
Extract bytecode operation code. More... | |
#define | WEIERSTRASS_DEST(op) ( ( (op) >> 8 ) & 0xf ) |
Extract destination big integer register. More... | |
#define | WEIERSTRASS_LEFT(op) ( ( (op) >> 4 ) & 0xf ) |
Extract left source big integer register. More... | |
#define | WEIERSTRASS_RIGHT(op) ( ( (op) >> 0 ) & 0xf ) |
Extract right source big integer register. More... | |
#define | WEIERSTRASS_ADD3(dest, augend, addend) WEIERSTRASS_OP ( WEIERSTRASS_OP_ADD, dest, augend, addend ) |
Define a three-argument addition operation. More... | |
#define | WEIERSTRASS_ADD2(augend, addend) WEIERSTRASS_ADD3 ( augend, augend, addend ) |
Define a two-argument addition operation. More... | |
#define | WEIERSTRASS_MOV(dest, source) WEIERSTRASS_ADD3( dest, source, zero ) |
Define a move operation. More... | |
#define | WEIERSTRASS_SUB3(dest, minuend, subtrahend, multiple) |
Define a three-argument subtraction operation. More... | |
#define | WEIERSTRASS_SUB2(minuend, subtrahend, multiple) WEIERSTRASS_SUB3 ( minuend, minuend, subtrahend, multiple ) |
Define a two-argument subtraction operation. More... | |
#define | WEIERSTRASS_STOP WEIERSTRASS_SUB2 ( zero, zero, 0N ) |
Define a stop operation. More... | |
#define | WEIERSTRASS_MUL3(dest, multiplicand, multiplier) WEIERSTRASS_OP ( WEIERSTRASS_OP_MUL, dest, multiplicand, multiplier ) |
Define a three-argument multiplication operation. More... | |
#define | WEIERSTRASS_MUL2(multiplicand, multiplier) WEIERSTRASS_MUL3 ( multiplicand, multiplicand, multiplier ) |
Define a two-argument multiplication operation. More... | |
#define | weierstrass_add(curve, augend, addend, result) |
Add points on curve. More... | |
#define | weierstrass_verify(curve, point) |
Verify point is on curve. More... | |
Enumerations | |
enum | weierstrass_register { WEIERSTRASS_a = 0, WEIERSTRASS_3b, WEIERSTRASS_x1, WEIERSTRASS_y1, WEIERSTRASS_z1, WEIERSTRASS_x2, WEIERSTRASS_y2, WEIERSTRASS_z2, WEIERSTRASS_Wt, WEIERSTRASS_Wxy, WEIERSTRASS_Wyz, WEIERSTRASS_Wzx, WEIERSTRASS_Wp, WEIERSTRASS_x3, WEIERSTRASS_y3, WEIERSTRASS_z3, WEIERSTRASS_NUM_REGISTERS = 16 } |
Big integer register names. More... | |
enum | weierstrass_opcode { WEIERSTRASS_OP_SUB_0N = 0, WEIERSTRASS_OP_SUB_2N = WEIERSTRASS_2N, WEIERSTRASS_OP_SUB_4N = WEIERSTRASS_4N, WEIERSTRASS_OP_ADD, WEIERSTRASS_OP_MUL } |
Bytecode operation codes. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static void | weierstrass_init (struct weierstrass_curve *curve) |
Initialise curve. More... | |
static void | weierstrass_exec (const struct weierstrass_curve *curve, void **regs, unsigned int size, unsigned int op) |
Execute bytecode instruction. More... | |
static void | weierstrass_add_raw (const struct weierstrass_curve *curve, const bigint_element_t *augend0, const bigint_element_t *addend0, bigint_element_t *result0) |
Add points on curve. More... | |
static void | weierstrass_add_ladder (const bigint_element_t *operand0, bigint_element_t *result0, unsigned int size, const void *ctx, void *tmp __unused) |
Add points on curve as part of a Montgomery ladder. More... | |
static int | weierstrass_verify_raw (const struct weierstrass_curve *curve, const bigint_element_t *point0) |
Verify point is on curve. More... | |
int | weierstrass_multiply (struct weierstrass_curve *curve, const void *base, const void *scalar, void *result) |
Multiply curve point by scalar. More... | |
Weierstrass elliptic curves.
The implementation is based upon Algorithm 1 from "Complete addition formulas for prime order elliptic curves" (Joost Renes, Craig Costello, and Lejla Batina), available from
https://www.microsoft.com/en-us/research/wp-content/uploads/2016/06/complete-2.pdf
The steps within the algorithm have been reordered and temporary variables shuffled to reduce stack usage, and calculations are carried out modulo small multiples of the field prime in order to elide reductions after intermediate addition and subtraction operations.
The algorithm is encoded using a bytecode representation, since this substantially reduces the code size compared to direct implementation of the big integer operations.
Definition in file weierstrass.c.
#define WEIERSTRASS_zero WEIERSTRASS_a |
Zero register (for add/subtract operations.
Definition at line 91 of file weierstrass.c.
Construct big integer register index.
Definition at line 94 of file weierstrass.c.
Define a bytecode operation.
opcode | Operation code |
dest | Destination big integer register name |
left | Left source big integer register name |
right | Right source big integer register name |
Definition at line 118 of file weierstrass.c.
Extract bytecode operation code.
Definition at line 125 of file weierstrass.c.
Extract destination big integer register.
Definition at line 128 of file weierstrass.c.
Extract left source big integer register.
Definition at line 131 of file weierstrass.c.
Extract right source big integer register.
Definition at line 134 of file weierstrass.c.
#define WEIERSTRASS_ADD3 | ( | dest, | |
augend, | |||
addend | |||
) | WEIERSTRASS_OP ( WEIERSTRASS_OP_ADD, dest, augend, addend ) |
Define a three-argument addition operation.
Definition at line 137 of file weierstrass.c.
#define WEIERSTRASS_ADD2 | ( | augend, | |
addend | |||
) | WEIERSTRASS_ADD3 ( augend, augend, addend ) |
Define a two-argument addition operation.
Definition at line 141 of file weierstrass.c.
#define WEIERSTRASS_MOV | ( | dest, | |
source | |||
) | WEIERSTRASS_ADD3( dest, source, zero ) |
Define a move operation.
Definition at line 145 of file weierstrass.c.
#define WEIERSTRASS_SUB3 | ( | dest, | |
minuend, | |||
subtrahend, | |||
multiple | |||
) |
Define a three-argument subtraction operation.
Definition at line 149 of file weierstrass.c.
#define WEIERSTRASS_SUB2 | ( | minuend, | |
subtrahend, | |||
multiple | |||
) | WEIERSTRASS_SUB3 ( minuend, minuend, subtrahend, multiple ) |
Define a two-argument subtraction operation.
Definition at line 154 of file weierstrass.c.
#define WEIERSTRASS_STOP WEIERSTRASS_SUB2 ( zero, zero, 0N ) |
Define a stop operation.
Definition at line 158 of file weierstrass.c.
#define WEIERSTRASS_MUL3 | ( | dest, | |
multiplicand, | |||
multiplier | |||
) | WEIERSTRASS_OP ( WEIERSTRASS_OP_MUL, dest, multiplicand, multiplier ) |
Define a three-argument multiplication operation.
Definition at line 161 of file weierstrass.c.
#define WEIERSTRASS_MUL2 | ( | multiplicand, | |
multiplier | |||
) | WEIERSTRASS_MUL3 ( multiplicand, multiplicand, multiplier ) |
Define a two-argument multiplication operation.
Definition at line 165 of file weierstrass.c.
#define weierstrass_add | ( | curve, | |
augend, | |||
addend, | |||
result | |||
) |
Add points on curve.
curve | Weierstrass curve |
augend | Point (x1,y1,z1) to be added |
addend | Point (x2,y2,z2) to be added |
result0 | Point (x3,y3,z3) to hold result |
Definition at line 629 of file weierstrass.c.
#define weierstrass_verify | ( | curve, | |
point | |||
) |
Verify point is on curve.
curve | Weierstrass curve |
point | Point (x,y,z) to be verified |
rc | Return status code |
Definition at line 757 of file weierstrass.c.
enum weierstrass_register |
Big integer register names.
Definition at line 51 of file weierstrass.c.
enum weierstrass_opcode |
Bytecode operation codes.
Definition at line 97 of file weierstrass.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
Initialise curve.
curve | Weierstrass curve |
Definition at line 173 of file weierstrass.c.
References __attribute__, weierstrass_curve::a, weierstrass_curve::a_raw, weierstrass_curve::b3, weierstrass_curve::b_raw, bigint_add, bigint_copy, bigint_init, bigint_montgomery, bigint_multiply, bigint_ntoa, bigint_reduce, bigint_subtract, bigint_t(), DBGC, weierstrass_curve::fermat, len, weierstrass_curve::len, weierstrass_curve::mont, weierstrass_curve::name, weierstrass_curve::one, weierstrass_curve::prime, weierstrass_curve::prime_raw, product, size, weierstrass_curve::size, weierstrass_curve::square, WEIERSTRASS_NUM_MONT, and WEIERSTRASS_NUM_MULTIPLES.
Referenced by weierstrass_multiply().
|
static |
Execute bytecode instruction.
curve | Weierstrass curve |
regs | Registers |
size | Big integer size |
op | Operation |
Definition at line 267 of file weierstrass.c.
References __attribute__, assert(), bigint_add, bigint_copy, bigint_montgomery_relaxed, bigint_multiply, bigint_ntoa, bigint_subtract, bigint_t(), DBGCP, dest, weierstrass_curve::name, NULL, op, weierstrass_curve::prime, product, regs, size, subtrahend, WEIERSTRASS_DEST, WEIERSTRASS_LEFT, WEIERSTRASS_OP_ADD, WEIERSTRASS_OP_MUL, WEIERSTRASS_OP_SUB_0N, WEIERSTRASS_OPCODE, WEIERSTRASS_RIGHT, WEIERSTRASS_Wp, and WEIERSTRASS_Wt.
Referenced by weierstrass_add_raw(), and weierstrass_verify_raw().
|
static |
Add points on curve.
curve | Weierstrass curve |
augend0 | Element 0 of point (x1,y1,z1) to be added |
addend0 | Element 0 of point (x2,y2,z2) to be added |
result0 | Element 0 of point (x3,y3,z3) to hold result |
Points are represented in projective coordinates, with all values in Montgomery form and in the range [0,4N) where N is the field prime.
The augend may have the same value as the addend (i.e. this routine may be used to perform point doubling as well as point addition), and either or both may be the point at infinity.
The result may overlap either input, since the inputs are fully consumed before the result is written.
Definition at line 366 of file weierstrass.c.
References __attribute__, weierstrass_curve::a, assert(), weierstrass_curve::b3, bigint_ntoa, bigint_t(), DBGC2, weierstrass_curve::name, op, weierstrass_curve::prime, regs, result, size, weierstrass_curve::size, WEIERSTRASS_3b, WEIERSTRASS_a, WEIERSTRASS_ADD2, WEIERSTRASS_ADD3, weierstrass_exec(), WEIERSTRASS_MOV, WEIERSTRASS_MUL2, WEIERSTRASS_MUL3, WEIERSTRASS_NUM_REGISTERS, WEIERSTRASS_STOP, WEIERSTRASS_SUB2, weierstrass_t, WEIERSTRASS_Wp, WEIERSTRASS_Wt, WEIERSTRASS_Wxy, WEIERSTRASS_Wyz, WEIERSTRASS_Wzx, WEIERSTRASS_x1, WEIERSTRASS_x2, WEIERSTRASS_x3, WEIERSTRASS_y1, WEIERSTRASS_y2, WEIERSTRASS_y3, WEIERSTRASS_z1, WEIERSTRASS_z2, and WEIERSTRASS_z3.
|
static |
Add points on curve as part of a Montgomery ladder.
operand | Element 0 of first input operand (may overlap result) |
result | Element 0 of second input operand and result |
size | Number of elements in operands and result |
ctx | Operation context |
tmp | Temporary working space (not used) |
Definition at line 644 of file weierstrass.c.
References __attribute__, assert(), bigint_size, ctx, result, size, weierstrass_curve::size, weierstrass_add, and weierstrass_t.
Referenced by weierstrass_multiply().
|
static |
Verify point is on curve.
curve | Weierstrass curve |
point0 | Element 0 of point (x,y,z) to be verified |
rc | Return status code |
As with point addition, points are represented in projective coordinates, with all values in Montgomery form and in the range [0,4N) where N is the field prime.
Definition at line 671 of file weierstrass.c.
References __attribute__, weierstrass_curve::a, weierstrass_curve::b3, bigint_grow, bigint_is_zero, bigint_montgomery, bigint_t(), DBGC, EINVAL, weierstrass_curve::name, op, weierstrass_curve::prime, regs, size, weierstrass_curve::size, WEIERSTRASS_3b, WEIERSTRASS_a, WEIERSTRASS_ADD2, WEIERSTRASS_ADD3, weierstrass_exec(), WEIERSTRASS_MOV, WEIERSTRASS_MUL2, WEIERSTRASS_MUL3, WEIERSTRASS_NUM_REGISTERS, WEIERSTRASS_STOP, WEIERSTRASS_SUB2, weierstrass_t, WEIERSTRASS_Wp, WEIERSTRASS_Wt, WEIERSTRASS_x1, and WEIERSTRASS_y1.
int weierstrass_multiply | ( | struct weierstrass_curve * | curve, |
const void * | base, | ||
const void * | scalar, | ||
void * | result | ||
) |
Multiply curve point by scalar.
curve | Weierstrass curve |
base | Base point (or NULL to use generator) |
scalar | Scalar multiple |
result | Result point to fill in |
rc | Return status code |
Definition at line 770 of file weierstrass.c.
References __attribute__, weierstrass_curve::base, base, bigint_copy, bigint_done, bigint_grow, bigint_init, bigint_ladder, bigint_mod_exp_ladder(), bigint_montgomery, bigint_montgomery_relaxed, bigint_multiply, bigint_ntoa, bigint_required_size, bigint_t(), DBGC, weierstrass_curve::fermat, len, weierstrass_curve::len, memset(), weierstrass_curve::name, NULL, offset, weierstrass_curve::one, weierstrass_curve::prime, rc, result, size, weierstrass_curve::size, weierstrass_curve::square, WEIERSTRASS_2N, weierstrass_add_ladder(), WEIERSTRASS_AXES, weierstrass_init(), weierstrass_t, and weierstrass_verify.