1 #ifndef _IPXE_WEIERSTRASS_H 2 #define _IPXE_WEIERSTRASS_H 16 #define WEIERSTRASS_AXES 2 38 #define WEIERSTRASS_MAX_MULTIPLE_LOG2 5 46 #define weierstrass_size( len ) \ 47 bigint_required_size ( (len) + \ 48 ( ( WEIERSTRASS_MAX_MULTIPLE_LOG2 + 7 ) \ 57 #define weierstrass_t( size ) \ 59 bigint_t ( size ) axis[3]; \ 61 bigint_t ( size ) x; \ 62 bigint_t ( size ) y; \ 63 bigint_t ( size ) z; \ 65 bigint_t ( size * 3 ) all; \ 77 #define WEIERSTRASS_NUM_MONT 3 80 #define WEIERSTRASS_NUM_CACHED \ 81 ( WEIERSTRASS_NUM_MULTIPLES + \ 83 WEIERSTRASS_NUM_MONT ) 127 const void *
base,
const void *scalar,
130 const void *addend,
const void *augend,
134 #define WEIERSTRASS_CURVE( _name, _curve, _len, _prime, _a, _b, _base, \ 136 static bigint_t ( weierstrass_size(_len) ) \ 137 _name ## _cache[WEIERSTRASS_NUM_CACHED]; \ 138 static struct weierstrass_curve _name ## _weierstrass = { \ 139 .size = weierstrass_size(_len), \ 142 .prime_raw = (_prime), \ 147 (_name ## _cache)[0].element, \ 148 (_name ## _cache)[1].element, \ 149 (_name ## _cache)[2].element, \ 151 .fermat = (_name ## _cache)[3].element, \ 152 .square = (_name ## _cache)[4].element, \ 153 .one = (_name ## _cache)[5].element, \ 154 .a = (_name ## _cache)[6].element, \ 155 .b3 = (_name ## _cache)[7].element, \ 157 static int _name ## _multiply ( const void *base, \ 158 const void *scalar, \ 160 return weierstrass_multiply ( &_name ## _weierstrass, \ 161 base, scalar, result ); \ 163 static int _name ## _add ( const void *addend, \ 164 const void *augend, void *result) { \ 165 return weierstrass_add_once ( &_name ## _weierstrass, \ 166 addend, augend, result ); \ 168 struct elliptic_curve _curve = { \ 170 .pointsize = ( WEIERSTRASS_AXES * (_len) ), \ 174 .multiply = _name ## _multiply, \ 175 .add = _name ## _add, \
const uint8_t * base
Base point.
bigint_element_t * square
Cached Montgomery constant (R^2 mod N)
bigint_element_t * prime[WEIERSTRASS_NUM_CACHED]
Cached field prime "N" (and multiples thereof)
weierstrass_multiple
Indexes for stored multiples of the field prime.
bigint_element_t * mont[WEIERSTRASS_NUM_MONT]
bigint_element_t * b3
Cached constant "3b", in Montgomery form.
int weierstrass_multiply(struct weierstrass_curve *curve, const void *base, const void *scalar, void *result)
Multiply curve point by scalar.
#define WEIERSTRASS_NUM_CACHED
Number of cached big integers for each Weierstrass curve.
uint32_t bigint_element_t
Element of a big integer.
bigint_element_t * fermat
Cached constant "N-2" (for Fermat's little theorem)
const uint8_t * b_raw
Constant "b".
bigint_element_t * a
Cached constant "a", in Montgomery form.
#define WEIERSTRASS_NUM_MONT
Number of cached in Montgomery form for each Weierstrass curve.
const char * name
Curve name.
size_t len
Length of raw scalar values.
bigint_element_t * one
Cached constant "1", in Montgomery form.
int weierstrass_add_once(struct weierstrass_curve *curve, const void *addend, const void *augend, void *result)
Add curve points (as a one-off operation)
const unsigned int size
Number of elements in scalar values.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
const uint8_t * prime_raw
Field prime.
const uint8_t * a_raw
Constant "a".
A Weierstrass elliptic curve.