92 #define WEIERSTRASS_zero WEIERSTRASS_a 95 #define WEIERSTRASS_REGISTER( name ) _C2 ( WEIERSTRASS_, name ) 119 #define WEIERSTRASS_OP( opcode, dest, left, right ) \ 120 ( ( (opcode) << 12 ) | \ 121 ( WEIERSTRASS_REGISTER ( dest ) << 8 ) | \ 122 ( WEIERSTRASS_REGISTER ( left ) << 4 ) | \ 123 ( WEIERSTRASS_REGISTER ( right ) << 0 ) ) 126 #define WEIERSTRASS_OPCODE( op ) ( ( (op) >> 12 ) & 0xf ) 129 #define WEIERSTRASS_DEST( op ) ( ( (op) >> 8 ) & 0xf ) 132 #define WEIERSTRASS_LEFT( op ) ( ( (op) >> 4 ) & 0xf ) 135 #define WEIERSTRASS_RIGHT( op ) ( ( (op) >> 0 ) & 0xf ) 138 #define WEIERSTRASS_ADD3( dest, augend, addend ) \ 139 WEIERSTRASS_OP ( WEIERSTRASS_OP_ADD, dest, augend, addend ) 142 #define WEIERSTRASS_ADD2( augend, addend ) \ 143 WEIERSTRASS_ADD3 ( augend, augend, addend ) 146 #define WEIERSTRASS_MOV( dest, source ) \ 147 WEIERSTRASS_ADD3( dest, source, zero ) 150 #define WEIERSTRASS_SUB3( dest, minuend, subtrahend, multiple ) \ 151 WEIERSTRASS_OP ( _C2 ( WEIERSTRASS_OP_SUB_, multiple ), \ 152 dest, minuend, subtrahend ) 155 #define WEIERSTRASS_SUB2( minuend, subtrahend, multiple ) \ 156 WEIERSTRASS_SUB3 ( minuend, minuend, subtrahend, multiple ) 159 #define WEIERSTRASS_STOP WEIERSTRASS_SUB2 ( zero, zero, 0N ) 162 #define WEIERSTRASS_MUL3( dest, multiplicand, multiplier ) \ 163 WEIERSTRASS_OP ( WEIERSTRASS_OP_MUL, dest, multiplicand, multiplier ) 166 #define WEIERSTRASS_MUL2( multiplicand, multiplier ) \ 167 WEIERSTRASS_MUL3 ( multiplicand, multiplicand, multiplier ) 177 ( (
void * ) curve->
prime[0] );
179 ( (
void * ) curve->
fermat );
181 ( (
void * ) curve->
square );
183 ( (
void * ) curve->
one );
185 ( (
void * ) curve->
a );
187 ( (
void * ) curve->
b3 );
189 ( (
void * ) curve->
mont[0] );
191 ( (
void * ) curve->
prime[1] );
196 static const uint8_t one_raw[] = { 1 };
197 static const uint8_t two_raw[] = { 2 };
203 DBGC ( curve,
"WEIERSTRASS %s N = %s\n",
208 DBGC ( curve,
"WEIERSTRASS %s R^2 = %s mod N\n",
213 DBGC ( curve,
"WEIERSTRASS %s b = %s\n",
221 DBGC ( curve,
"WEIERSTRASS %s a = %s\n",
233 static const char *names[] = {
" ",
" a",
"3b" };
236 DBGC ( curve,
"WEIERSTRASS %s %sR = %s mod N\n",
248 DBGC ( curve,
"WEIERSTRASS %s N-2 = %s\n",
255 DBGC ( curve,
"WEIERSTRASS %s %dN = %s\n",
272 *prime = ( (
const void * ) curve->
prime[0] );
280 unsigned int op_code;
281 unsigned int op_dest;
282 unsigned int op_left;
283 unsigned int op_right;
291 left =
regs[op_left];
292 right =
regs[op_right];
303 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d x R%d = %s\n",
304 curve->
name, op_dest, op_left, op_right,
310 if ( op_dest != op_left )
315 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d = %s\n",
324 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d + R%d = ",
325 curve->
name, op_dest, op_left, op_right );
326 addend = ( (
const void * ) right );
328 subtrahend = ( (
const void * ) right );
330 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d - R%d + " 331 "%dN = ", curve->
name, op_dest, op_left,
332 op_right, ( 1 << op_code ) );
333 addend = ( (
const void * ) curve->
prime[op_code] );
335 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d - R%d = ",
336 curve->
name, op_dest, op_left, op_right );
373 *prime = ( (
const void * ) curve->
prime[0] );
375 *a = ( (
const void * ) curve->
a );
377 *b3 = ( (
const void * ) curve->
b3 );
379 *augend = ( (
const void * ) augend0 );
381 *addend = ( (
const void * ) addend0 );
383 *
result = ( (
void * ) result0 );
392 unsigned int schedule;
582 for ( i = 0 ; schedule ; i++, schedule >>= 1 ) {
584 regs[i] = (
regs[ i - 1 ] +
sizeof ( *prime ) );
586 DBGC2 ( curve,
"WEIERSTRASS %s augend (%s,",
590 DBGC2 ( curve,
"WEIERSTRASS %s addend (%s,",
616 DBGC2 ( curve,
"WEIERSTRASS %s result (%s,",
630 #define weierstrass_add( curve, augend, addend, result ) do { \ 631 weierstrass_add_raw ( (curve), (augend)->all.element, \ 632 (addend)->all.element, \ 633 (result)->all.element ); \ 647 unsigned int size,
const void *
ctx,
651 *operand = ( (
const void * ) operand0 );
653 *
result = ( (
void * ) result0 );
680 *
prime = ( (
const void * ) curve->
prime[0] );
682 *
a = ( (
const void * ) curve->
a );
684 *
b3 = ( (
const void * ) curve->
b3 );
686 *point = ( (
const void * ) point0 );
752 DBGC ( curve,
"WEIERSTRASS %s base point is not on curve\n",
767 #define weierstrass_verify( curve, point ) ( { \ 768 weierstrass_verify_raw ( (curve), (point)->all.element ); \ 786 ( (
const void * ) curve->
prime[0] );
790 ( (
const void * ) curve->
square );
792 ( (
const void * ) curve->
one );
794 *point = ( (
void * ) point0 );
798 }
__attribute__ (( may_alias )) *temp = ( (
void * ) temp0 );
811 if ( ! prime2->element[0] )
815 DBGC ( curve,
"WEIERSTRASS %s point (", curve->
name );
818 DBGC ( curve,
"%s%s", ( i ?
"," :
"" ),
824 memset ( &point->z, 0, sizeof ( point->z ) );
826 bigint_copy ( one, &point->axis[ is_infinite ? 1 : 2 ] );
827 DBGC ( curve,
")\n" );
845 #define weierstrass_init( curve, point, temp, data ) ( { \ 846 weierstrass_init_raw ( (curve), (point)->all.element, \ 847 (temp)->all.element, (data) ); \ 864 ( (
const void * ) curve->
prime[0] );
866 ( (
const void * ) curve->
fermat );
868 ( (
const void * ) curve->
one );
870 *point = ( (
void * ) point0 );
874 }
__attribute__ (( may_alias )) *temp = ( (
void * ) temp0 );
884 DBGC ( curve,
"WEIERSTRASS %s result (", curve->
name );
892 DBGC ( curve,
"%s%s", ( i ?
"," :
"" ),
896 DBGC ( curve,
")\n" );
908 #define weierstrass_done( curve, point, temp, out ) ( { \ 909 weierstrass_done_raw ( (curve), (point)->all.element, \ 910 (temp)->all.element, (out) ); \ 920 const void *point ) {
931 DBGC ( curve,
"WEIERSTRASS %s point (", curve->
name );
934 DBGC ( curve,
"%s%s", ( i ?
"," :
"" ),
938 DBGC ( curve,
") is%s infinity\n", ( is_finite ?
" not" :
"" ) );
940 return ( ! is_finite );
953 const void *scalar,
void *
result ) {
957 ( (
const void * ) curve->
one );
972 memset ( &temp.result, 0, sizeof ( temp.result ) );
977 DBGC ( curve,
"WEIERSTRASS %s scalar %s\n",
981 bigint_ladder ( &temp.result.all, &temp.multiple.all, &temp.scalar,
1000 const void *addend,
const void *augend,
#define weierstrass_init(curve, point, temp, data)
Initialise curve point.
#define EINVAL
Invalid argument.
struct arbelprm_rc_send_wqe rc
bigint_element_t * square
Cached Montgomery constant (R^2 mod N)
#define WEIERSTRASS_RIGHT(op)
Extract right source big integer register.
#define WEIERSTRASS_STOP
Define a stop operation.
weierstrass_register
Big integer register names.
bigint_element_t * prime[WEIERSTRASS_NUM_CACHED]
Cached field prime "N" (and multiples thereof)
static void weierstrass_exec(const struct weierstrass_curve *curve, void **regs, unsigned int size, unsigned int op)
Execute bytecode instruction.
uint16_t size
Buffer size.
#define WEIERSTRASS_AXES
Number of axes in Weierstrass curve point representation.
bigint_element_t * mont[WEIERSTRASS_NUM_MONT]
#define WEIERSTRASS_OPCODE(op)
Extract bytecode operation code.
Weierstrass elliptic curves.
#define bigint_grow(source, dest)
Grow big integer.
#define bigint_init(value, data, len)
Initialise big integer.
#define weierstrass_verify(curve, point)
Verify freshly initialised point is on curve.
struct golan_eq_context ctx
#define bigint_is_zero(value)
Test if big integer is equal to zero.
#define bigint_montgomery_relaxed(modulus, value, result)
Perform relaxed Montgomery reduction (REDC) of a big integer.
bigint_element_t * b3
Cached constant "3b", in Montgomery form.
static void weierstrass_done_raw(struct weierstrass_curve *curve, bigint_element_t *point0, bigint_element_t *temp0, void *out)
Finalise curve point.
static void weierstrass_init_curve(struct weierstrass_curve *curve)
Initialise curve.
#define WEIERSTRASS_MOV(dest, source)
Define a move operation.
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.
#define weierstrass_add(curve, augend, addend, result)
Add points on curve.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define weierstrass_t(size)
Define a Weierstrass projective co-ordinate type.
#define weierstrass_done(curve, point, temp, out)
Finalise curve point.
#define __unused
Declare a variable or data structure as unused.
#define bigint_copy(source, dest)
Copy big integer.
uint32_t bigint_element_t
Element of a big integer.
#define WEIERSTRASS_MUL3(dest, multiplicand, multiplier)
Define a three-argument multiplication operation.
static void weierstrass_add_raw(const struct weierstrass_curve *curve, const bigint_element_t *augend0, const bigint_element_t *addend0, bigint_element_t *result0)
Add points on curve.
bigint_element_t * fermat
Cached constant "N-2" (for Fermat's little theorem)
const uint8_t * b_raw
Constant "b".
int weierstrass_add_once(struct weierstrass_curve *curve, const void *addend, const void *augend, void *result)
Add curve points (as a one-off operation)
#define bigint_done(value, out, len)
Finalise big integer.
Subtract big integers (and add 2N)
bigint_element_t * a
Cached constant "a", in Montgomery form.
#define bigint_required_size(len)
Determine number of elements required for a big-integer type.
#define WEIERSTRASS_NUM_MONT
Number of cached in Montgomery form for each Weierstrass curve.
const char * name
Curve name.
#define WEIERSTRASS_SUB2(minuend, subtrahend, multiple)
Define a two-argument subtraction operation.
size_t len
Length of raw scalar values.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
bigint_element_t * one
Cached constant "1", in Montgomery form.
int weierstrass_is_infinity(struct weierstrass_curve *curve, const void *point)
Check if this is the point at infinity.
Subtract big integers (and add nothing)
static uint16_t struct vmbus_xfer_pages_operations * op
static int weierstrass_init_raw(struct weierstrass_curve *curve, bigint_element_t *point0, bigint_element_t *temp0, const void *data)
Initialise curve point.
#define bigint_montgomery(modulus, value, result)
Perform classic Montgomery reduction (REDC) of a big integer.
#define bigint_size(bigint)
Determine number of elements in big-integer type.
#define bigint_multiply(multiplicand, multiplier, result)
Multiply big integers.
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" return dest
uint8_t data[48]
Additional event data.
#define bigint_reduce(modulus, result)
Reduce big integer R^2 modulo N.
uint8_t product
Product string.
#define WEIERSTRASS_MUL2(multiplicand, multiplier)
Define a two-argument multiplication operation.
#define WEIERSTRASS_LEFT(op)
Extract left source big integer register.
#define bigint_ladder(result, multiple, exponent, op, ctx, tmp)
Perform generalised exponentiation via a Montgomery ladder.
const unsigned int size
Number of elements in scalar values.
#define WEIERSTRASS_DEST(op)
Extract destination big integer register.
Multiply big integers (and perform Montgomery reduction)
static int weierstrass_verify_raw(const struct weierstrass_curve *curve, const bigint_element_t *point0)
Verify freshly initialised point is on curve.
weierstrass_opcode
Bytecode operation codes.
Subtract big integers (and add 4N)
uint16_t offset
Offset to command line.
#define WEIERSTRASS_ADD3(dest, augend, addend)
Define a three-argument addition operation.
#define bigint_subtract(subtrahend, value)
Subtract big integers.
int weierstrass_multiply(struct weierstrass_curve *curve, const void *base, const void *scalar, void *result)
Multiply curve point by scalar.
#define bigint_add(addend, value)
Add big integers.
#define bigint_ntoa(value)
Transcribe big integer (for debugging)
#define NULL
NULL pointer (VOID *)
const uint8_t * prime_raw
Field prime.
#define WEIERSTRASS_ADD2(augend, addend)
Define a two-argument addition operation.
typedef bigint_t(X25519_SIZE) x25519_t
An X25519 unsigned big integer used in internal calculations.
const uint8_t * a_raw
Constant "a".
void * memset(void *dest, int character, size_t len) __nonnull
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.
A Weierstrass elliptic curve.