97 #define X25519_REDUCE_256 38 276 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
277 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
278 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
279 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xed
299 static const uint8_t x25519_121665_raw[] = { 0x01, 0xdb, 0x41 };
332 sizeof ( x25519_121665_raw ) );
464 static_assert (
sizeof ( step2->product ) >= sizeof ( step2->value ) );
503 memset ( &step3->value, 0, sizeof ( step3->value ) );
547 for ( i = 253 ; i >= 0 ; i-- ) {
553 if ( ( i != 2 ) && ( i != 4 ) ) {
566 unsigned int max_bit = ( ( 8 *
sizeof ( *value ) ) - 1 );
742 static const uint8_t one[] = { 1 };
755 for ( i = 254 ; i >= 0 ; i-- ) {
756 bit = ( (
scalar->raw[ i / 8 ] >> ( i % 8 ) ) & 1 );
808 tmp->raw[31] |= 0x40;
union x25519_multiply_step1 __attribute__
bigint_t(bigint_required_size((260+7)/8)+bigint_required_size((6+7)/8))
Raw product.
static void x25519_step(const union x25519_quad257 *base, int bit, struct x25519_step *step)
Compute next step of the Montgomery ladder.
int x25519_key(const struct x25519_value *base, const struct x25519_value *scalar, struct x25519_value *result)
Calculate X25519 key.
void x25519_reduce(union x25519_quad257 *value)
Reduce big integer to canonical range.
uint32_t low
Low 16 bits of address.
static const void const void void * result
void x25519_multiply(const union x25519_oct258 *multiplicand, const union x25519_oct258 *multiplier, union x25519_quad257 *result)
Multiply big integers modulo field prime.
const union x25519_oct258 oct258
X25519 unsigned 258-bit integer.
static unsigned int unsigned int bit
struct elliptic_curve x25519_curve
X25519 elliptic curve.
static void x25519_init_constants(void)
Initialise constants.
An X25519 unsigned 257-bit integer.
static const uint8_t x25519_reduce_256_raw[]
Reduction constant (used during multiplication)
An X25519 Montgomery ladder step.
static const void const void * scalar
struct x25519_projective x_n
X[n]/Z[n].
#define bigint_grow(source, dest)
Grow big integer.
union x25519_multiply_step3 step3
Step 3 result.
An X25519 unsigned 258-bit integer.
#define bigint_init(value, data, len)
Initialise big integer.
uint32_t zero
Must be zero.
#define offsetof(type, field)
Get offset of a field within a structure.
#define static_assert(x)
Assert a condition at build time.
union x25519_quad257 Z
Z coordinate.
#define bigint_is_zero(value)
Test if big integer is equal to zero.
static const void * base
Base address.
uint8_t multiplier
Port multiplier number.
static x25519_t x25519_4p
Constant 4p=2^257-76.
static x25519_t x25519_p
Constant p=2^255-19 (the finite field prime)
static __always_inline off_t userptr_t subtrahend
static bigint_t(bigint_required_size(sizeof(x25519_reduce_256_raw)))
Reduction constant (used during multiplication)
#define INIT_NORMAL
Normal initialisation.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void x25519_reduce_by(const x25519_t *subtrahend, x25519_t *value)
Reduce big integer via conditional subtraction.
static void x25519_ladder(const union x25519_quad257 *base, struct x25519_value *scalar, union x25519_quad257 *result)
Multiply X25519 elliptic curve point.
An initialisation function.
static void x25519_subtract(const union x25519_quad257 *minuend, const union x25519_quad257 *subtrahend, union x25519_oct258 *result)
Subtract big integers modulo field prime.
X25519 multiplication step 2 result.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
uint8_t pad[sizeof(union x25519_multiply_step2) - offsetof(union x25519_multiply_step1, parts.high_260bit)]
Padding to avoid collision between steps 1 and 2.
bigint_t(X25519_SIZE+X25519_SIZE) product
Raw product.
#define bigint_copy(source, dest)
Copy big integer.
static void x25519_add(const union x25519_quad257 *augend, const union x25519_quad257 *addend, union x25519_oct258 *result)
Add big integers modulo field prime.
#define build_assert(condition)
Assert a condition at build time (after dead code elimination)
static x25519_t x25519_2p
Constant 2p=2^256-38.
struct x25519_multiply_step1::@432 parts
Partition into low-order and high-order bits.
x25519_t value
Big integer value.
static void x25519_reverse(struct x25519_value *value)
Reverse X25519 value endianness.
#define bigint_done(value, out, len)
Finalise big integer.
const char * name
Curve name.
pseudo_bit_t value[0x00020]
uint32_t high
High 32 bits of address.
#define bigint_required_size(len)
Determine number of elements required for a big-integer type.
union x25519_quad257 X
X coordinate.
X25519 multiplication step 3 result.
#define X25519_REDUCE_256
X25519 reduction constant.
X25519 multiplication step 1 result.
#define bigint_swap(first, second, swap)
Conditionally swap big integers (in constant time)
static const uint8_t x25519_p_raw[]
Constant p=2^255-19 (the finite field prime)
X25519 multiplication temporary working space.
static int x25519_curve_multiply(const void *base, const void *scalar, void *result)
Multiply scalar by curve point.
#define EPERM
Operation not permitted.
union x25519_multiply_step2 step2
Step 2 result.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define X25519_SIZE
X25519 unsigned big integer size.
static struct x25519_value x25519_generator
Constant g=9 (the group generator)
struct x25519_projective x_n1
X[n+1]/Z[n+1].
void step(void)
Single-step a single process.
An X25519 elliptic curve point in projective coordinates.
#define bigint_multiply(multiplicand, multiplier, result)
Multiply big integers.
uint8_t raw[32]
Raw value.
uint8_t product
Product string.
void x25519_invert(const union x25519_oct258 *invertend, union x25519_quad257 *result)
Compute multiplicative inverse.
struct init_fn x25519_init_fn __init_fn(INIT_NORMAL)
Initialisation function.
#define bigint_bit_is_set(value, bit)
Test if bit is set in big integer.
union x25519_multiply_step1 step1
Step 1 result.
#define bigint_subtract(subtrahend, value)
Subtract big integers.
#define bigint_add(addend, value)
Add big integers.
static union x25519_oct258 x25519_121665
Constant 121665 (used in the Montgomery ladder)
x25519_t value
Big integer value.
void * memset(void *dest, int character, size_t len) __nonnull