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,
131 #define WEIERSTRASS_CURVE( _name, _curve, _len, _prime, _a, _b, _base ) \ 132 static bigint_t ( weierstrass_size(_len) ) \ 133 _name ## _cache[WEIERSTRASS_NUM_CACHED]; \ 134 static struct weierstrass_curve _name ## _weierstrass = { \ 135 .size = weierstrass_size(_len), \ 138 .prime_raw = (_prime), \ 143 (_name ## _cache)[0].element, \ 144 (_name ## _cache)[1].element, \ 145 (_name ## _cache)[2].element, \ 147 .fermat = (_name ## _cache)[3].element, \ 148 .square = (_name ## _cache)[4].element, \ 149 .one = (_name ## _cache)[5].element, \ 150 .a = (_name ## _cache)[6].element, \ 151 .b3 = (_name ## _cache)[7].element, \ 153 static int _name ## _multiply ( const void *base, \ 154 const void *scalar, \ 156 return weierstrass_multiply ( &_name ## _weierstrass, \ 157 base, scalar, result ); \ 159 struct elliptic_curve _curve = { \ 161 .pointsize = ( WEIERSTRASS_AXES * (_len) ), \ 163 .multiply = _name ## _multiply, \
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.
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.