|
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 freshly initialised point is on curve. More... | |
| #define | weierstrass_init(curve, point, temp, data) |
| Initialise curve point. More... | |
| #define | weierstrass_done(curve, point, temp, out) |
| Finalise curve point. 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_curve (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 freshly initialised point is on curve. More... | |
| static int | weierstrass_init_raw (struct weierstrass_curve *curve, bigint_element_t *point0, bigint_element_t *temp0, const void *data) |
| Initialise curve point. More... | |
| static void | weierstrass_done_raw (struct weierstrass_curve *curve, bigint_element_t *point0, bigint_element_t *temp0, void *out) |
| Finalise curve point. More... | |
| int | weierstrass_is_infinity (struct weierstrass_curve *curve, const void *point) |
| Check if this is the point at infinity. More... | |
| int | weierstrass_multiply (struct weierstrass_curve *curve, const void *base, const void *scalar, void *result) |
| Multiply curve point by scalar. More... | |
| int | weierstrass_add_once (struct weierstrass_curve *curve, const void *addend, const void *augend, void *result) |
| Add curve points (as a one-off operation) 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 freshly initialised point is on curve.
| curve | Weierstrass curve |
| point | Point (x,y,z) to be verified |
| rc | Return status code |
Definition at line 766 of file weierstrass.c.
| #define weierstrass_init | ( | curve, | |
| point, | |||
| temp, | |||
| data | |||
| ) |
Initialise curve point.
| curve | Weierstrass curve |
| point | Point (x,y,z) to be filled in |
| temp | Temporary point buffer |
| data | Raw curve point |
| rc | Return status code |
Definition at line 844 of file weierstrass.c.
| #define weierstrass_done | ( | curve, | |
| point, | |||
| temp, | |||
| out | |||
| ) |
Finalise curve point.
| curve | Weierstrass curve |
| point | Point (x,y,z) |
| temp | Temporary point buffer |
| out | Output buffer |
| rc | Return status code |
Definition at line 907 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, weierstrass_curve::len, 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_init_raw().
|
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, 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 freshly initialised 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.
This verification logic is valid only for points that have been freshly constructed via weierstrass_init() (i.e. must either have z=1 or be the point at infinity (0,1,0)).
Definition at line 675 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, WEIERSTRASS_y1, and WEIERSTRASS_z1.
|
static |
Initialise curve point.
| curve | Weierstrass curve |
| point0 | Element 0 of point (x,y,z) to be filled in |
| temp0 | Element 0 of temporary point buffer |
| data | Raw curve point |
| rc | Return status code |
Definition at line 779 of file weierstrass.c.
References __attribute__, bigint_copy, bigint_init, bigint_is_zero, bigint_montgomery_relaxed, bigint_multiply, bigint_ntoa, bigint_t(), data, DBGC, weierstrass_curve::len, len, memset(), weierstrass_curve::name, offset, weierstrass_curve::one, weierstrass_curve::prime, product, rc, size, weierstrass_curve::size, weierstrass_curve::square, WEIERSTRASS_2N, WEIERSTRASS_AXES, weierstrass_init_curve(), weierstrass_t, and weierstrass_verify.
|
static |
Finalise curve point.
| curve | Weierstrass curve |
| point0 | Element 0 of point (x,y,z) |
| temp0 | Element 0 of temporary point buffer |
| out | Output buffer |
Definition at line 857 of file weierstrass.c.
References __attribute__, bigint_copy, bigint_done, bigint_grow, bigint_ladder, bigint_mod_exp_ladder(), bigint_montgomery, bigint_montgomery_relaxed, bigint_multiply, bigint_ntoa, bigint_t(), DBGC, weierstrass_curve::fermat, weierstrass_curve::len, len, weierstrass_curve::name, offset, weierstrass_curve::one, out, weierstrass_curve::prime, product, size, weierstrass_curve::size, WEIERSTRASS_AXES, and weierstrass_t.
| int weierstrass_is_infinity | ( | struct weierstrass_curve * | curve, |
| const void * | point | ||
| ) |
Check if this is the point at infinity.
| point | Curve point |
| is_infinity | This is the point at infinity |
Definition at line 918 of file weierstrass.c.
References bigint_init, bigint_is_zero, bigint_ntoa, bigint_t(), DBGC, weierstrass_curve::len, len, weierstrass_curve::name, offset, size, weierstrass_curve::size, and WEIERSTRASS_AXES.
| 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 |
| scalar | Scalar multiple |
| result | Result point to fill in |
| rc | Return status code |
Definition at line 951 of file weierstrass.c.
References __attribute__, base, bigint_copy, bigint_init, bigint_ladder, bigint_ntoa, bigint_required_size, bigint_t(), DBGC, weierstrass_curve::len, len, memset(), weierstrass_curve::name, NULL, weierstrass_curve::one, rc, result, size, weierstrass_curve::size, weierstrass_add_ladder(), weierstrass_done, weierstrass_init, and weierstrass_t.
| int weierstrass_add_once | ( | struct weierstrass_curve * | curve, |
| const void * | addend, | ||
| const void * | augend, | ||
| void * | result | ||
| ) |
Add curve points (as a one-off operation)
| curve | Weierstrass curve |
| addend | Curve point to add |
| augend | Curve point to add |
| result | Curve point to hold result |
| rc | Return status code |
Definition at line 998 of file weierstrass.c.
References rc, result, size, weierstrass_curve::size, weierstrass_add, weierstrass_done, weierstrass_init, and weierstrass_t.
1.8.15