1#ifndef _IPXE_WEIERSTRASS_H
2#define _IPXE_WEIERSTRASS_H
18#define WEIERSTRASS_AXES 2
46#define WEIERSTRASS_MAX_MULT_LOG2 5
54#define weierstrass_size( len ) \
55 bigint_required_size ( (len) + \
56 ( ( 2 * WEIERSTRASS_MAX_MULT_LOG2 + 7 ) \
65#define weierstrass_t( size ) \
67 bigint_t ( size ) axis[3]; \
69 bigint_t ( size ) x; \
70 bigint_t ( size ) y; \
71 bigint_t ( size ) z; \
73 bigint_t ( size * 2 ) xy; \
74 bigint_t ( size * 3 ) all; \
86#define WEIERSTRASS_NUM_MONT 3
89#define WEIERSTRASS_NUM_CACHED \
90 ( WEIERSTRASS_NUM_MULTIPLES + \
92 WEIERSTRASS_NUM_MONT )
136 const void *
base,
const void *scalar,
139 const void *addend,
const void *augend,
142 const void *
private,
void *
public );
144 const void *
private,
const void *
partner,
148#define WEIERSTRASS_CURVE( _name, _curve, _len, _prime, _a, _b, _base, \
150 static bigint_t ( weierstrass_size(_len) ) \
151 _name ## _cache[WEIERSTRASS_NUM_CACHED]; \
152 static struct weierstrass_curve _name ## _weierstrass = { \
153 .size = weierstrass_size(_len), \
155 .prime_raw = (_prime), \
160 (_name ## _cache)[0].element, \
161 (_name ## _cache)[1].element, \
162 (_name ## _cache)[2].element, \
164 .fermat = (_name ## _cache)[3].element, \
165 .square = (_name ## _cache)[4].element, \
166 .one = (_name ## _cache)[5].element, \
167 .a = (_name ## _cache)[6].element, \
168 .b3 = (_name ## _cache)[7].element, \
170 struct elliptic_curve _curve = { \
172 .pointsize = ( (_len) * WEIERSTRASS_AXES ), \
176 .is_infinity = weierstrass_is_infinity, \
177 .multiply = weierstrass_multiply, \
178 .add = weierstrass_add_once, \
179 .priv = &_name ## _weierstrass, \
uint32_t bigint_element_t
Element of a big integer.
struct eth_slow_lacp_entity_tlv partner
Partner information.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
A key exchange algorithm.
A Weierstrass elliptic curve.
bigint_element_t * mont[WEIERSTRASS_NUM_MONT]
const uint8_t * base
Base point.
bigint_element_t * prime[WEIERSTRASS_NUM_CACHED]
Cached field prime "N" (and multiples thereof).
size_t len
Length of raw scalar values.
const uint8_t * a_raw
Constant "a".
bigint_element_t * one
Cached constant "1", in Montgomery form.
bigint_element_t * square
Cached Montgomery constant (R^2 mod N).
bigint_element_t * b3
Cached constant "3b", in Montgomery form.
const unsigned int size
Number of elements in scalar values.
const uint8_t * b_raw
Constant "b".
bigint_element_t * fermat
Cached constant "N-2" (for Fermat's little theorem).
bigint_element_t * a
Cached constant "a", in Montgomery form.
const uint8_t * prime_raw
Field prime.
int weierstrass_is_infinity(struct elliptic_curve *curve, const void *point)
Check if this is the point at infinity.
#define WEIERSTRASS_NUM_MONT
Number of cached in Montgomery form for each Weierstrass curve.
void weierstrass_share(struct exchange_algorithm *exchange, const void *private, void *public)
#define WEIERSTRASS_NUM_CACHED
Number of cached big integers for each Weierstrass curve.
int weierstrass_agree(struct exchange_algorithm *exchange, const void *private, const void *partner, void *shared)
weierstrass_multiple
Indexes for stored multiples of the field prime.
@ WEIERSTRASS_NUM_MULTIPLES
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).