93#define WEIERSTRASS_zero WEIERSTRASS_a
96#define WEIERSTRASS_REGISTER( name ) _C2 ( WEIERSTRASS_, name )
120#define WEIERSTRASS_OP( opcode, dest, left, right ) \
121 ( ( (opcode) << 12 ) | \
122 ( WEIERSTRASS_REGISTER ( dest ) << 8 ) | \
123 ( WEIERSTRASS_REGISTER ( left ) << 4 ) | \
124 ( WEIERSTRASS_REGISTER ( right ) << 0 ) )
127#define WEIERSTRASS_OPCODE( op ) ( ( (op) >> 12 ) & 0xf )
130#define WEIERSTRASS_DEST( op ) ( ( (op) >> 8 ) & 0xf )
133#define WEIERSTRASS_LEFT( op ) ( ( (op) >> 4 ) & 0xf )
136#define WEIERSTRASS_RIGHT( op ) ( ( (op) >> 0 ) & 0xf )
139#define WEIERSTRASS_ADD3( dest, augend, addend ) \
140 WEIERSTRASS_OP ( WEIERSTRASS_OP_ADD, dest, augend, addend )
143#define WEIERSTRASS_ADD2( augend, addend ) \
144 WEIERSTRASS_ADD3 ( augend, augend, addend )
147#define WEIERSTRASS_MOV( dest, source ) \
148 WEIERSTRASS_ADD3( dest, source, zero )
151#define WEIERSTRASS_SUB3( dest, minuend, subtrahend, multiple ) \
152 WEIERSTRASS_OP ( _C2 ( WEIERSTRASS_OP_SUB_, multiple ), \
153 dest, minuend, subtrahend )
156#define WEIERSTRASS_SUB2( minuend, subtrahend, multiple ) \
157 WEIERSTRASS_SUB3 ( minuend, minuend, subtrahend, multiple )
160#define WEIERSTRASS_STOP WEIERSTRASS_SUB2 ( zero, zero, 0N )
163#define WEIERSTRASS_MUL3( dest, multiplicand, multiplier ) \
164 WEIERSTRASS_OP ( WEIERSTRASS_OP_MUL, dest, multiplicand, multiplier )
167#define WEIERSTRASS_MUL2( multiplicand, multiplier ) \
168 WEIERSTRASS_MUL3 ( multiplicand, multiplicand, multiplier )
177 unsigned int size = weierstrass->
size;
179 ( (
void * ) weierstrass->
prime[0] );
181 ( (
void * ) weierstrass->
fermat );
183 ( (
void * ) weierstrass->
square );
185 ( (
void * ) weierstrass->
one );
187 ( (
void * ) weierstrass->
a );
189 ( (
void * ) weierstrass->
b3 );
191 ( (
void * ) weierstrass->
mont[0] );
193 ( (
void * ) weierstrass->
prime[1] );
198 static const uint8_t one_raw[] = { 1 };
199 static const uint8_t two_raw[] = { 2 };
200 size_t len = weierstrass->
len;
205 DBGC ( curve,
"WEIERSTRASS %s N = %s\n",
210 DBGC ( curve,
"WEIERSTRASS %s R^2 = %s mod N\n",
215 DBGC ( curve,
"WEIERSTRASS %s b = %s\n",
223 DBGC ( curve,
"WEIERSTRASS %s a = %s\n",
235 static const char *names[] = {
" ",
" a",
"3b" };
238 DBGC ( curve,
"WEIERSTRASS %s %sR = %s mod N\n",
250 DBGC ( curve,
"WEIERSTRASS %s N-2 = %s\n",
257 DBGC ( curve,
"WEIERSTRASS %s %dN = %s\n",
275 *
prime = ( (
const void * ) weierstrass->
prime[0] );
283 unsigned int op_code;
284 unsigned int op_dest;
285 unsigned int op_left;
286 unsigned int op_right;
294 left =
regs[op_left];
295 right =
regs[op_right];
306 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d x R%d = %s\n",
307 curve->
name, op_dest, op_left, op_right,
313 if ( op_dest != op_left )
318 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d = %s\n",
327 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d + R%d = ",
328 curve->
name, op_dest, op_left, op_right );
329 addend = ( (
const void * ) right );
331 subtrahend = ( (
const void * ) right );
333 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d - R%d + "
334 "%dN = ", curve->
name, op_dest, op_left,
335 op_right, ( 1 << op_code ) );
336 addend = ( (
const void * )
337 weierstrass->
prime[op_code] );
339 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d - R%d = ",
340 curve->
name, op_dest, op_left, op_right );
376 unsigned int size = weierstrass->
size;
378 *
prime = ( (
const void * ) weierstrass->
prime[0] );
380 *
a = ( (
const void * ) weierstrass->
a );
382 *
b3 = ( (
const void * ) weierstrass->
b3 );
384 *augend = ( (
const void * ) augend0 );
386 *addend = ( (
const void * ) addend0 );
388 *
result = ( (
void * ) result0 );
397 unsigned int schedule;
587 for ( i = 0 ; schedule ; i++, schedule >>= 1 ) {
589 regs[i] = (
regs[ i - 1 ] +
sizeof ( *prime ) );
591 DBGC2 ( curve,
"WEIERSTRASS %s augend (%s,",
595 DBGC2 ( curve,
"WEIERSTRASS %s addend (%s,",
621 DBGC2 ( curve,
"WEIERSTRASS %s result (%s,",
635#define weierstrass_add( curve, augend, addend, result ) do { \
636 weierstrass_add_raw ( (curve), (augend)->all.element, \
637 (addend)->all.element, \
638 (result)->all.element ); \
652 unsigned int size,
const void *
ctx,
657 *operand = ( (
const void * ) operand0 );
659 *
result = ( (
void * ) result0 );
685 unsigned int size = weierstrass->
size;
687 *
prime = ( (
const void * ) weierstrass->
prime[0] );
689 *
a = ( (
const void * ) weierstrass->
a );
691 *
b3 = ( (
const void * ) weierstrass->
b3 );
693 *point = ( (
const void * ) point0 );
759 DBGC ( curve,
"WEIERSTRASS %s base point is not on curve\n",
774#define weierstrass_verify( curve, point ) ( { \
775 weierstrass_verify_raw ( (curve), (point)->all.element ); \
791 unsigned int size = weierstrass->
size;
792 size_t len = weierstrass->
len;
794 ( (
const void * ) weierstrass->
prime[0] );
798 ( (
const void * ) weierstrass->
square );
800 ( (
const void * ) weierstrass->
one );
802 *point = ( (
void * ) point0 );
806 }
__attribute__ (( may_alias )) *temp = ( (
void * ) temp0 );
819 if ( ! prime2->element[0] )
823 DBGC ( curve,
"WEIERSTRASS %s point (", curve->
name );
826 DBGC ( curve,
"%s%s", ( i ?
"," :
"" ),
832 memset ( &point->z, 0, sizeof ( point->z ) );
834 bigint_copy ( one, &point->axis[ is_infinite ? 1 : 2 ] );
835 DBGC ( curve,
")\n" );
853#define weierstrass_init( curve, point, temp, data ) ( { \
854 weierstrass_init_raw ( (curve), (point)->all.element, \
855 (temp)->all.element, (data) ); \
870 unsigned int size = weierstrass->
size;
871 size_t len = weierstrass->
len;
873 ( (
const void * ) weierstrass->
prime[0] );
875 ( (
const void * ) weierstrass->
fermat );
877 ( (
const void * ) weierstrass->
one );
879 *point = ( (
void * ) point0 );
883 }
__attribute__ (( may_alias )) *temp = ( (
void * ) temp0 );
893 DBGC ( curve,
"WEIERSTRASS %s result (", curve->
name );
901 DBGC ( curve,
"%s%s", ( i ?
"," :
"" ),
905 DBGC ( curve,
")\n" );
917#define weierstrass_done( curve, point, temp, out ) ( { \
918 weierstrass_done_raw ( (curve), (point)->all.element, \
919 (temp)->all.element, (out) ); \
930 const void *point ) {
932 unsigned int size = weierstrass->
size;
933 size_t len = weierstrass->
len;
942 DBGC ( curve,
"WEIERSTRASS %s point (", curve->
name );
945 DBGC ( curve,
"%s%s", ( i ?
"," :
"" ),
949 DBGC ( curve,
") is%s infinity\n", ( is_finite ?
" not" :
"" ) );
951 return ( ! is_finite );
964 const void *scalar,
void *
result ) {
966 unsigned int size = weierstrass->
size;
967 size_t len = weierstrass->
len;
969 ( (
const void * ) weierstrass->
one );
984 memset ( &temp.result, 0, sizeof ( temp.result ) );
989 DBGC ( curve,
"WEIERSTRASS %s scalar %s\n",
993 bigint_ladder ( &temp.result.all, &temp.multiple.all, &temp.scalar,
1012 const void *addend,
const void *augend,
1015 unsigned int size = weierstrass->
size;
#define NULL
NULL pointer (VOID *).
struct golan_eq_context ctx
struct arbelprm_rc_send_wqe rc
uint32_t bigint_element_t
Element of a big integer.
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
#define assert(condition)
Assert a condition at run-time.
void bigint_mod_exp_ladder(const bigint_element_t *multiplier0, bigint_element_t *result0, unsigned int size, const void *ctx, void *tmp)
Perform modular multiplication as part of a Montgomery ladder.
uint16_t offset
Offset to command line.
uint8_t data[48]
Additional event data.
#define __unused
Declare a variable or data structure as unused.
uint16_t size
Buffer size.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define EINVAL
Invalid argument.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
#define bigint_grow(source, dest)
Grow big integer.
#define bigint_ladder(result, multiple, exponent, op, ctx, tmp)
Perform generalised exponentiation via a Montgomery ladder.
#define bigint_montgomery_relaxed(modulus, value, result)
Perform relaxed Montgomery reduction (REDC) of a big integer.
#define bigint_size(bigint)
Determine number of elements in big-integer type.
#define bigint_reduce(modulus, result)
Reduce big integer R^2 modulo N.
#define bigint_subtract(subtrahend, value)
Subtract big integers.
#define bigint_montgomery(modulus, value, result)
Perform classic Montgomery reduction (REDC) of a big integer.
#define bigint_copy(source, dest)
Copy big integer.
#define bigint_is_zero(value)
Test if big integer is equal to zero.
#define bigint_t(size)
Define a big-integer type.
#define bigint_required_size(len)
Determine number of elements required for a big-integer type.
#define bigint_multiply(multiplicand, multiplier, result)
Multiply big integers.
#define bigint_done(value, out, len)
Finalise big integer.
#define bigint_add(addend, value)
Add big integers.
#define bigint_ntoa(value)
Transcribe big integer (for debugging).
#define bigint_init(value, data, len)
Initialise big integer.
uint8_t product
Product string.
void * memset(void *dest, int character, size_t len) __nonnull
static uint16_t struct vmbus_xfer_pages_operations * op
const char * name
Curve name.
void * priv
Algorithm private data.
A Weierstrass elliptic curve.
bigint_element_t * mont[WEIERSTRASS_NUM_MONT]
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.
static int weierstrass_verify_raw(const struct elliptic_curve *curve, const bigint_element_t *point0)
Verify freshly initialised point is on curve.
#define WEIERSTRASS_STOP
Define a stop operation.
static void weierstrass_init_curve(struct elliptic_curve *curve)
Initialise curve.
#define WEIERSTRASS_DEST(op)
Extract destination big integer register.
static int weierstrass_init_raw(struct elliptic_curve *curve, bigint_element_t *point0, bigint_element_t *temp0, const void *data)
Initialise curve point.
#define weierstrass_verify(curve, point)
Verify freshly initialised point is on curve.
#define weierstrass_done(curve, point, temp, out)
Finalise curve point.
#define WEIERSTRASS_MUL3(dest, multiplicand, multiplier)
Define a three-argument multiplication operation.
#define weierstrass_add(curve, augend, addend, result)
Add points on curve.
int weierstrass_is_infinity(struct elliptic_curve *curve, const void *point)
Check if this is the point at infinity.
#define WEIERSTRASS_ADD3(dest, augend, addend)
Define a three-argument addition operation.
static void weierstrass_done_raw(struct elliptic_curve *curve, bigint_element_t *point0, bigint_element_t *temp0, void *out)
Finalise curve point.
#define WEIERSTRASS_RIGHT(op)
Extract right source big integer register.
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.
#define WEIERSTRASS_MUL2(multiplicand, multiplier)
Define a two-argument multiplication operation.
static void weierstrass_exec(const struct elliptic_curve *curve, void **regs, unsigned int size, unsigned int op)
Execute bytecode instruction.
#define WEIERSTRASS_MOV(dest, source)
Define a move operation.
weierstrass_register
Big integer register names.
@ WEIERSTRASS_NUM_REGISTERS
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.
weierstrass_opcode
Bytecode operation codes.
@ WEIERSTRASS_OP_SUB_2N
Subtract big integers (and add 2N).
@ WEIERSTRASS_OP_ADD
Add big integers.
@ WEIERSTRASS_OP_SUB_4N
Subtract big integers (and add 4N).
@ WEIERSTRASS_OP_MUL
Multiply big integers (and perform Montgomery reduction).
@ WEIERSTRASS_OP_SUB_0N
Subtract big integers (and add nothing).
#define WEIERSTRASS_LEFT(op)
Extract left source big integer register.
#define WEIERSTRASS_OPCODE(op)
Extract bytecode operation code.
#define WEIERSTRASS_ADD2(augend, addend)
Define a two-argument addition operation.
#define WEIERSTRASS_SUB2(minuend, subtrahend, multiple)
Define a two-argument subtraction operation.
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).
#define weierstrass_init(curve, point, temp, data)
Initialise curve point.
Weierstrass elliptic curves.
#define WEIERSTRASS_AXES
Number of axes in Weierstrass curve point representation.
#define weierstrass_t(size)
Define a Weierstrass projective co-ordinate type.
#define WEIERSTRASS_NUM_MONT
Number of cached in Montgomery form for each Weierstrass curve.
@ WEIERSTRASS_NUM_MULTIPLES