91 #define WEIERSTRASS_zero WEIERSTRASS_a 94 #define WEIERSTRASS_REGISTER( name ) _C2 ( WEIERSTRASS_, name ) 118 #define WEIERSTRASS_OP( opcode, dest, left, right ) \ 119 ( ( (opcode) << 12 ) | \ 120 ( WEIERSTRASS_REGISTER ( dest ) << 8 ) | \ 121 ( WEIERSTRASS_REGISTER ( left ) << 4 ) | \ 122 ( WEIERSTRASS_REGISTER ( right ) << 0 ) ) 125 #define WEIERSTRASS_OPCODE( op ) ( ( (op) >> 12 ) & 0xf ) 128 #define WEIERSTRASS_DEST( op ) ( ( (op) >> 8 ) & 0xf ) 131 #define WEIERSTRASS_LEFT( op ) ( ( (op) >> 4 ) & 0xf ) 134 #define WEIERSTRASS_RIGHT( op ) ( ( (op) >> 0 ) & 0xf ) 137 #define WEIERSTRASS_ADD3( dest, augend, addend ) \ 138 WEIERSTRASS_OP ( WEIERSTRASS_OP_ADD, dest, augend, addend ) 141 #define WEIERSTRASS_ADD2( augend, addend ) \ 142 WEIERSTRASS_ADD3 ( augend, augend, addend ) 145 #define WEIERSTRASS_MOV( dest, source ) \ 146 WEIERSTRASS_ADD3( dest, source, zero ) 149 #define WEIERSTRASS_SUB3( dest, minuend, subtrahend, multiple ) \ 150 WEIERSTRASS_OP ( _C2 ( WEIERSTRASS_OP_SUB_, multiple ), \ 151 dest, minuend, subtrahend ) 154 #define WEIERSTRASS_SUB2( minuend, subtrahend, multiple ) \ 155 WEIERSTRASS_SUB3 ( minuend, minuend, subtrahend, multiple ) 158 #define WEIERSTRASS_STOP WEIERSTRASS_SUB2 ( zero, zero, 0N ) 161 #define WEIERSTRASS_MUL3( dest, multiplicand, multiplier ) \ 162 WEIERSTRASS_OP ( WEIERSTRASS_OP_MUL, dest, multiplicand, multiplier ) 165 #define WEIERSTRASS_MUL2( multiplicand, multiplier ) \ 166 WEIERSTRASS_MUL3 ( multiplicand, multiplicand, multiplier ) 176 ( (
void * ) curve->
prime[0] );
178 ( (
void * ) curve->
fermat );
180 ( (
void * ) curve->
square );
182 ( (
void * ) curve->
one );
184 ( (
void * ) curve->
a );
186 ( (
void * ) curve->
b3 );
188 ( (
void * ) curve->
mont[0] );
190 ( (
void * ) curve->
prime[1] );
195 static const uint8_t one_raw[] = { 1 };
196 static const uint8_t two_raw[] = { 2 };
202 DBGC ( curve,
"WEIERSTRASS %s N = %s\n",
207 DBGC ( curve,
"WEIERSTRASS %s R^2 = %s mod N\n",
212 DBGC ( curve,
"WEIERSTRASS %s b = %s\n",
220 DBGC ( curve,
"WEIERSTRASS %s a = %s\n",
232 static const char *names[] = {
" ",
" a",
"3b" };
235 DBGC ( curve,
"WEIERSTRASS %s %sR = %s mod N\n",
247 DBGC ( curve,
"WEIERSTRASS %s N-2 = %s\n",
254 DBGC ( curve,
"WEIERSTRASS %s %dN = %s\n",
271 *prime = ( (
const void * ) curve->
prime[0] );
279 unsigned int op_code;
280 unsigned int op_dest;
281 unsigned int op_left;
282 unsigned int op_right;
290 left =
regs[op_left];
291 right =
regs[op_right];
302 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d x R%d = %s\n",
303 curve->
name, op_dest, op_left, op_right,
309 if ( op_dest != op_left )
314 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d = %s\n",
323 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d + R%d = ",
324 curve->
name, op_dest, op_left, op_right );
325 addend = ( (
const void * ) right );
329 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d - R%d + " 330 "%dN = ", curve->
name, op_dest, op_left,
331 op_right, ( 1 << op_code ) );
332 addend = ( (
const void * ) curve->
prime[op_code] );
334 DBGCP ( curve,
"WEIERSTRASS %s R%d := R%d - R%d = ",
335 curve->
name, op_dest, op_left, op_right );
372 *prime = ( (
const void * ) curve->
prime[0] );
374 *a = ( (
const void * ) curve->
a );
376 *b3 = ( (
const void * ) curve->
b3 );
378 *augend = ( (
const void * ) augend0 );
380 *addend = ( (
const void * ) addend0 );
382 *
result = ( (
void * ) result0 );
391 unsigned int schedule;
581 for ( i = 0 ; schedule ; i++, schedule >>= 1 ) {
583 regs[i] = (
regs[ i - 1 ] +
sizeof ( *prime ) );
585 DBGC2 ( curve,
"WEIERSTRASS %s augend (%s,",
589 DBGC2 ( curve,
"WEIERSTRASS %s addend (%s,",
615 DBGC2 ( curve,
"WEIERSTRASS %s result (%s,",
629 #define weierstrass_add( curve, augend, addend, result ) do { \ 630 weierstrass_add_raw ( (curve), (augend)->all.element, \ 631 (addend)->all.element, \ 632 (result)->all.element ); \ 646 unsigned int size,
const void *
ctx,
650 *operand = ( (
const void * ) operand0 );
652 *
result = ( (
void * ) result0 );
675 *
prime = ( (
const void * ) curve->
prime[0] );
677 *
a = ( (
const void * ) curve->
a );
679 *
b3 = ( (
const void * ) curve->
b3 );
681 *point = ( (
const void * ) point0 );
742 DBGC ( curve,
"WEIERSTRASS %s base point is not on curve\n",
757 #define weierstrass_verify( curve, point ) ( { \ 758 weierstrass_verify_raw ( (curve), (point)->all.element ); \ 771 const void *scalar,
void *
result ) {
775 ( (
const void * ) curve->
prime[0] );
779 ( (
const void * ) curve->
fermat );
781 ( (
const void * ) curve->
square );
783 ( (
const void * ) curve->
one );
806 if ( ! prime2->element[0] )
814 DBGC ( curve,
"WEIERSTRASS %s base (", curve->
name );
817 DBGC ( curve,
"%s%s", ( i ?
"," :
"" ),
822 &temp.multiple.axis[i] );
825 DBGC ( curve,
")\n" );
832 memset ( &temp.result, 0, sizeof ( temp.result ) );
837 DBGC ( curve,
"WEIERSTRASS %s scalar %s\n",
841 bigint_ladder ( &temp.result.all, &temp.multiple.all, &temp.scalar,
850 DBGC ( curve,
"WEIERSTRASS %s result (", curve->
name );
855 &temp.result.axis[i] );
856 bigint_grow ( &temp.result.axis[i], &temp.product_out );
858 &temp.result.axis[i] );
859 DBGC ( curve,
"%s%s", ( i ?
"," :
"" ),
863 DBGC ( curve,
")\n" );
#define EINVAL
Invalid argument.
struct arbelprm_rc_send_wqe rc
const uint8_t * base
Base point.
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.
uint8_t size
Entry size (in 32-bit words)
#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 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.
#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.
static void weierstrass_init(struct weierstrass_curve *curve)
Initialise curve.
#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 __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".
#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.
Subtract big integers (and add nothing)
static uint16_t struct vmbus_xfer_pages_operations * op
#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
#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.
uint16_t offset
Offset to command line.
#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 point is on curve.
weierstrass_opcode
Bytecode operation codes.
Subtract big integers (and add 4N)
static __always_inline off_t userptr_t subtrahend
#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.