1 #ifndef _IPXE_WEIERSTRASS_H 2 #define _IPXE_WEIERSTRASS_H 17 #define WEIERSTRASS_AXES 2 39 #define WEIERSTRASS_MAX_MULTIPLE_LOG2 5 47 #define weierstrass_size( len ) \ 48 bigint_required_size ( (len) + \ 49 ( ( WEIERSTRASS_MAX_MULTIPLE_LOG2 + 7 ) \ 58 #define weierstrass_t( size ) \ 60 bigint_t ( size ) axis[3]; \ 62 bigint_t ( size ) x; \ 63 bigint_t ( size ) y; \ 64 bigint_t ( size ) z; \ 66 bigint_t ( size * 2 ) xy; \ 67 bigint_t ( size * 3 ) all; \ 79 #define WEIERSTRASS_NUM_MONT 3 82 #define WEIERSTRASS_NUM_CACHED \ 83 ( WEIERSTRASS_NUM_MULTIPLES + \ 85 WEIERSTRASS_NUM_MONT ) 131 const void *
base,
const void *scalar,
134 const void *addend,
const void *augend,
138 #define WEIERSTRASS_CURVE( _name, _curve, _len, _prime, _a, _b, _base, \ 140 static bigint_t ( weierstrass_size(_len) ) \ 141 _name ## _cache[WEIERSTRASS_NUM_CACHED]; \ 142 static struct weierstrass_curve _name ## _weierstrass = { \ 143 .size = weierstrass_size(_len), \ 146 .prime_raw = (_prime), \ 151 (_name ## _cache)[0].element, \ 152 (_name ## _cache)[1].element, \ 153 (_name ## _cache)[2].element, \ 155 .fermat = (_name ## _cache)[3].element, \ 156 .square = (_name ## _cache)[4].element, \ 157 .one = (_name ## _cache)[5].element, \ 158 .a = (_name ## _cache)[6].element, \ 159 .b3 = (_name ## _cache)[7].element, \ 161 static int _name ## _is_infinity ( const void *point) { \ 162 return weierstrass_is_infinity ( &_name ## _weierstrass,\ 165 static int _name ## _multiply ( const void *base, \ 166 const void *scalar, \ 168 return weierstrass_multiply ( &_name ## _weierstrass, \ 169 base, scalar, result ); \ 171 static int _name ## _add ( const void *addend, \ 172 const void *augend, void *result) { \ 173 return weierstrass_add_once ( &_name ## _weierstrass, \ 174 addend, augend, result ); \ 176 struct elliptic_curve _curve = { \ 178 .pointsize = ( WEIERSTRASS_AXES * (_len) ), \ 182 .is_infinity = _name ## _is_infinity, \ 183 .multiply = _name ## _multiply, \ 184 .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)
int weierstrass_is_infinity(struct weierstrass_curve *curve, const void *point)
Check if this is the point at infinity.
const uint8_t * prime_raw
Field prime.
const uint8_t * a_raw
Constant "a".
A Weierstrass elliptic curve.