|
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. | |
| #define | WEIERSTRASS_REGISTER(name) |
| Construct big integer register index. | |
| #define | WEIERSTRASS_OP(opcode, dest, left, right) |
| Define a bytecode operation. | |
| #define | WEIERSTRASS_OPCODE(op) |
| Extract bytecode operation code. | |
| #define | WEIERSTRASS_DEST(op) |
| Extract destination big integer register. | |
| #define | WEIERSTRASS_LEFT(op) |
| Extract left source big integer register. | |
| #define | WEIERSTRASS_RIGHT(op) |
| Extract right source big integer register. | |
| #define | WEIERSTRASS_ADD3(dest, augend, addend) |
| Define a three-argument addition operation. | |
| #define | WEIERSTRASS_ADD2(augend, addend) |
| Define a two-argument addition operation. | |
| #define | WEIERSTRASS_MOV(dest, source) |
| Define a move operation. | |
| #define | WEIERSTRASS_SUB3(dest, minuend, subtrahend, multiple) |
| Define a three-argument subtraction operation. | |
| #define | WEIERSTRASS_SUB2(minuend, subtrahend, multiple) |
| Define a two-argument subtraction operation. | |
| #define | WEIERSTRASS_STOP WEIERSTRASS_SUB2 ( zero, zero, 0N ) |
| Define a stop operation. | |
| #define | WEIERSTRASS_MUL3(dest, multiplicand, multiplier) |
| Define a three-argument multiplication operation. | |
| #define | WEIERSTRASS_MUL2(multiplicand, multiplier) |
| Define a two-argument multiplication operation. | |
| #define | weierstrass_add(curve, augend, addend, result) |
| Add points on curve. | |
| #define | weierstrass_verify(curve, point) |
| Verify freshly initialised point is on curve. | |
| #define | weierstrass_init(curve, point, temp, data) |
| Initialise curve point. | |
| #define | weierstrass_done(curve, point, temp, out) |
| Finalise curve point. | |
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) | |
| FILE_SECBOOT (PERMITTED) | |
| static void | weierstrass_init_curve (struct elliptic_curve *curve) |
| Initialise curve. | |
| static void | weierstrass_exec (const struct elliptic_curve *curve, void **regs, unsigned int size, unsigned int op) |
| Execute bytecode instruction. | |
| static void | weierstrass_add_raw (const struct elliptic_curve *curve, const bigint_element_t *augend0, const bigint_element_t *addend0, bigint_element_t *result0) |
| Add points on curve. | |
| 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. | |
| static int | weierstrass_verify_raw (const struct elliptic_curve *curve, const bigint_element_t *point0) |
| Verify freshly initialised point is on curve. | |
| static int | weierstrass_init_raw (struct elliptic_curve *curve, bigint_element_t *point0, bigint_element_t *temp0, const void *data) |
| Initialise curve point. | |
| static void | weierstrass_done_raw (struct elliptic_curve *curve, bigint_element_t *point0, bigint_element_t *temp0, void *out) |
| Finalise curve point. | |
| int | weierstrass_is_infinity (struct elliptic_curve *curve, const void *point) |
| Check if this is the point at infinity. | |
| int | weierstrass_multiply (struct elliptic_curve *curve, const void *base, const void *scalar, void *result) |
| Multiply curve point by scalar. | |
| int | weierstrass_add_once (struct elliptic_curve *curve, const void *addend, const void *augend, void *result) |
| Add curve points (as a one-off operation). | |
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 93 of file weierstrass.c.
| #define WEIERSTRASS_REGISTER | ( | name | ) |
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 120 of file weierstrass.c.
| #define WEIERSTRASS_OPCODE | ( | op | ) |
Extract bytecode operation code.
Definition at line 127 of file weierstrass.c.
Referenced by weierstrass_exec().
| #define WEIERSTRASS_DEST | ( | op | ) |
Extract destination big integer register.
Definition at line 130 of file weierstrass.c.
Referenced by weierstrass_exec().
| #define WEIERSTRASS_LEFT | ( | op | ) |
Extract left source big integer register.
Definition at line 133 of file weierstrass.c.
Referenced by weierstrass_exec().
| #define WEIERSTRASS_RIGHT | ( | op | ) |
Extract right source big integer register.
Definition at line 136 of file weierstrass.c.
Referenced by weierstrass_exec().
| #define WEIERSTRASS_ADD3 | ( | dest, | |
| augend, | |||
| addend ) |
Define a three-argument addition operation.
Definition at line 139 of file weierstrass.c.
Referenced by weierstrass_add_raw(), and weierstrass_verify_raw().
| #define WEIERSTRASS_ADD2 | ( | augend, | |
| addend ) |
Define a two-argument addition operation.
Definition at line 143 of file weierstrass.c.
Referenced by weierstrass_add_raw(), and weierstrass_verify_raw().
| #define WEIERSTRASS_MOV | ( | dest, | |
| source ) |
Define a move operation.
Definition at line 147 of file weierstrass.c.
Referenced by weierstrass_add_raw(), and weierstrass_verify_raw().
| #define WEIERSTRASS_SUB3 | ( | dest, | |
| minuend, | |||
| subtrahend, | |||
| multiple ) |
Define a three-argument subtraction operation.
Definition at line 151 of file weierstrass.c.
| #define WEIERSTRASS_SUB2 | ( | minuend, | |
| subtrahend, | |||
| multiple ) |
Define a two-argument subtraction operation.
Definition at line 156 of file weierstrass.c.
Referenced by weierstrass_add_raw(), and weierstrass_verify_raw().
| #define WEIERSTRASS_STOP WEIERSTRASS_SUB2 ( zero, zero, 0N ) |
Define a stop operation.
Definition at line 160 of file weierstrass.c.
Referenced by weierstrass_add_raw(), and weierstrass_verify_raw().
| #define WEIERSTRASS_MUL3 | ( | dest, | |
| multiplicand, | |||
| multiplier ) |
Define a three-argument multiplication operation.
Definition at line 163 of file weierstrass.c.
Referenced by weierstrass_add_raw(), and weierstrass_verify_raw().
| #define WEIERSTRASS_MUL2 | ( | multiplicand, | |
| multiplier ) |
Define a two-argument multiplication operation.
Definition at line 167 of file weierstrass.c.
Referenced by weierstrass_add_raw(), and weierstrass_verify_raw().
| #define weierstrass_add | ( | curve, | |
| augend, | |||
| addend, | |||
| result ) |
Add points on curve.
| curve | Elliptic 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 635 of file weierstrass.c.
Referenced by weierstrass_add_ladder(), and weierstrass_add_once().
| #define weierstrass_verify | ( | curve, | |
| point ) |
Verify freshly initialised point is on curve.
| curve | Elliptic curve |
| point | Point (x,y,z) to be verified |
| rc | Return status code |
Definition at line 774 of file weierstrass.c.
Referenced by weierstrass_init_raw().
| #define weierstrass_init | ( | curve, | |
| point, | |||
| temp, | |||
| data ) |
Initialise curve point.
| curve | Elliptic 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 853 of file weierstrass.c.
Referenced by weierstrass_add_once(), and weierstrass_multiply().
| #define weierstrass_done | ( | curve, | |
| point, | |||
| temp, | |||
| out ) |
Finalise curve point.
| curve | Elliptic curve |
| point | Point (x,y,z) |
| temp | Temporary point buffer |
| out | Output buffer |
| rc | Return status code |
Definition at line 917 of file weierstrass.c.
Referenced by weierstrass_add_once(), and weierstrass_multiply().
| enum weierstrass_register |
Big integer register names.
Definition at line 53 of file weierstrass.c.
| enum weierstrass_opcode |
Bytecode operation codes.
Definition at line 99 of file weierstrass.c.
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
| FILE_SECBOOT | ( | PERMITTED | ) |
|
static |
Initialise curve.
| curve | Elliptic curve |
Definition at line 175 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, elliptic_curve::name, weierstrass_curve::one, weierstrass_curve::prime, weierstrass_curve::prime_raw, elliptic_curve::priv, product, size, weierstrass_curve::size, weierstrass_curve::square, WEIERSTRASS_NUM_MONT, and WEIERSTRASS_NUM_MULTIPLES.
Referenced by weierstrass_init_raw().
|
static |
Execute bytecode instruction.
Definition at line 270 of file weierstrass.c.
References __attribute__, assert, bigint_add, bigint_copy, bigint_montgomery_relaxed, bigint_multiply, bigint_ntoa, bigint_subtract, bigint_t, DBGCP, dest, elliptic_curve::name, NULL, op, weierstrass_curve::prime, elliptic_curve::priv, 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 | Elliptic 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 371 of file weierstrass.c.
References __attribute__, weierstrass_curve::a, assert, weierstrass_curve::b3, bigint_ntoa, bigint_t, DBGC2, elliptic_curve::name, op, weierstrass_curve::prime, elliptic_curve::priv, 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 650 of file weierstrass.c.
References __attribute__, __unused, assert, bigint_size, ctx, elliptic_curve::priv, result, size, weierstrass_curve::size, tmp, weierstrass_add, and weierstrass_t.
Referenced by weierstrass_multiply().
|
static |
Verify freshly initialised point is on curve.
| curve | Elliptic 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 682 of file weierstrass.c.
References __attribute__, weierstrass_curve::a, weierstrass_curve::b3, bigint_grow, bigint_is_zero, bigint_montgomery, bigint_t, DBGC, EINVAL, elliptic_curve::name, op, weierstrass_curve::prime, elliptic_curve::priv, 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 | Elliptic 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 787 of file weierstrass.c.
References __attribute__, bigint_copy, bigint_init, bigint_is_zero, bigint_montgomery_relaxed, bigint_multiply, bigint_ntoa, bigint_t, data, DBGC, len, weierstrass_curve::len, memset(), elliptic_curve::name, offset, weierstrass_curve::one, weierstrass_curve::prime, elliptic_curve::priv, 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 | Elliptic curve |
| point0 | Element 0 of point (x,y,z) |
| temp0 | Element 0 of temporary point buffer |
| out | Output buffer |
Definition at line 866 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, len, weierstrass_curve::len, elliptic_curve::name, offset, weierstrass_curve::one, out, weierstrass_curve::prime, elliptic_curve::priv, product, size, weierstrass_curve::size, WEIERSTRASS_AXES, and weierstrass_t.
| int weierstrass_is_infinity | ( | struct elliptic_curve * | curve, |
| const void * | point ) |
Check if this is the point at infinity.
| curve | Elliptic curve |
| point | Curve point |
| is_infinity | This is the point at infinity |
Definition at line 929 of file weierstrass.c.
References bigint_init, bigint_is_zero, bigint_ntoa, bigint_t, DBGC, len, weierstrass_curve::len, elliptic_curve::name, offset, elliptic_curve::priv, size, weierstrass_curve::size, and WEIERSTRASS_AXES.
| int weierstrass_multiply | ( | struct elliptic_curve * | curve, |
| const void * | base, | ||
| const void * | scalar, | ||
| void * | result ) |
Multiply curve point by scalar.
| rc | Return status code |
Definition at line 963 of file weierstrass.c.
References __attribute__, base, bigint_copy, bigint_init, bigint_ladder, bigint_ntoa, bigint_required_size, bigint_t, DBGC, len, weierstrass_curve::len, memset(), elliptic_curve::name, NULL, weierstrass_curve::one, elliptic_curve::priv, rc, result, size, weierstrass_curve::size, weierstrass_add_ladder(), weierstrass_done, weierstrass_init, and weierstrass_t.
| int weierstrass_add_once | ( | struct elliptic_curve * | curve, |
| const void * | addend, | ||
| const void * | augend, | ||
| void * | result ) |
Add curve points (as a one-off operation).
| curve | Elliptic curve |
| addend | Curve point to add |
| augend | Curve point to add |
| result | Curve point to hold result |
| rc | Return status code |
Definition at line 1011 of file weierstrass.c.
References elliptic_curve::priv, rc, result, size, weierstrass_curve::size, weierstrass_add, weierstrass_done, weierstrass_init, and weierstrass_t.