98#define X25519_REDUCE_256 38
229 parts.high_260bit ) ];
277 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
278 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
279 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
280 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xed
300static const uint8_t x25519_121665_raw[] = { 0x01, 0xdb, 0x41 };
333 sizeof ( x25519_121665_raw ) );
442 static_assert (
sizeof ( step1->product ) >=
sizeof ( step1->
parts ) );
466 static_assert (
sizeof ( step2->product ) >=
sizeof ( step2->value ) );
467 static_assert (
sizeof ( step2->product ) >=
sizeof ( step2->
parts ) );
505 memset ( &step3->value, 0, sizeof ( step3->value ) );
549 for ( i = 253 ; i >= 0 ; i-- ) {
555 if ( ( i != 2 ) && ( i != 4 ) ) {
743 static const uint8_t zero[] = { 0 };
744 static const uint8_t one[] = { 1 };
757 for ( i = 254 ; i >= 0 ; i-- ) {
758 bit = ( ( scalar->
raw[ i / 8 ] >> ( i % 8 ) ) & 1 );
823 tmp->raw[31] |= 0x40;
pseudo_bit_t value[0x00020]
static const uint32_t multiplier
Port multiplier number.
#define build_assert(condition)
Assert a condition at build time (after dead code elimination)
#define assert(condition)
Assert a condition at run-time.
#define __unused
Declare a variable or data structure as unused.
#define INIT_NORMAL
Normal initialisation.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define ENOTTY
Inappropriate I/O control operation.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
#define bigint_grow(source, dest)
Grow big integer.
#define bigint_subtract(subtrahend, value)
Subtract big integers.
static unsigned int unsigned int bit
#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_swap(first, second, swap)
Conditionally swap big integers (in constant time)
#define bigint_init(value, data, len)
Initialise big integer.
uint8_t product
Product string.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
#define __init_fn(init_order)
Declare an initialisation functon.
uint32_t high
High 32 bits of address.
uint32_t low
Low 16 bits of address.
void step(void)
Single-step a single process.
#define offsetof(type, field)
Get offset of a field within a structure.
#define container_of(ptr, type, field)
Get containing structure.
An initialisation function.
An X25519 elliptic curve point in projective coordinates.
union x25519_quad257 X
X coordinate.
union x25519_quad257 Z
Z coordinate.
An X25519 Montgomery ladder step.
struct x25519_projective x_n
X[n]/Z[n].
struct x25519_projective x_n1
X[n+1]/Z[n+1].
uint8_t raw[32]
Raw value.
X25519 multiplication step 1 result.
bigint_t(X25519_SIZE+X25519_SIZE) product
Raw product.
struct x25519_multiply_step1::@143326331223017073312237123340004167004022061343 parts
Partition into low-order and high-order bits.
X25519 multiplication step 2 result.
bigint_t(bigint_required_size((260+7)/8)+bigint_required_size((6+7)/8))
Raw product.
X25519 multiplication step 3 result.
X25519 multiplication temporary working space.
union x25519_multiply_step1 step1
Step 1 result.
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.
union x25519_multiply_step2 step2
Step 2 result.
union x25519_multiply_step3 step3
Step 3 result.
An X25519 unsigned 258-bit integer.
x25519_t value
Big integer value.
An X25519 unsigned 257-bit integer.
x25519_t value
Big integer value.
const union x25519_oct258 oct258
X25519 unsigned 258-bit integer.
u16 keysize
Length of encryption key to be used, network byte order.
int x25519_is_zero(const struct x25519_value *value)
Check if X25519 value is zero.
void x25519_multiply(const union x25519_oct258 *multiplicand, const union x25519_oct258 *multiplier, union x25519_quad257 *result)
Multiply big integers modulo field prime.
#define X25519_REDUCE_256
X25519 reduction constant.
static void x25519_step(const union x25519_quad257 *base, int bit, struct x25519_step *step)
Compute next step of the Montgomery ladder.
struct elliptic_curve x25519_curve
X25519 elliptic curve.
static void x25519_reduce_by(const x25519_t *subtrahend, x25519_t *value)
Reduce big integer via conditional subtraction.
void x25519_reduce(union x25519_quad257 *value)
Reduce big integer to canonical range.
static const uint8_t x25519_p_raw[]
Constant p=2^255-19 (the finite field prime)
static x25519_t x25519_2p
Constant 2p=2^256-38.
static x25519_t x25519_4p
Constant 4p=2^257-76.
static struct x25519_value x25519_generator
Constant g=9 (the group generator)
static void x25519_reverse(struct x25519_value *value)
Reverse X25519 value endianness.
void x25519_key(const struct x25519_value *base, const struct x25519_value *scalar, struct x25519_value *result)
Calculate X25519 key.
static int x25519_curve_is_infinity(const void *point)
Check if this is the point at infinity.
static union x25519_oct258 x25519_121665
Constant 121665 (used in the Montgomery ladder)
static void x25519_ladder(const union x25519_quad257 *base, struct x25519_value *scalar, union x25519_quad257 *result)
Multiply X25519 elliptic curve point.
static const uint8_t x25519_reduce_256_raw[]
Reduction constant (used during multiplication)
static void x25519_add(const union x25519_quad257 *augend, const union x25519_quad257 *addend, union x25519_oct258 *result)
Add big integers modulo field prime.
void x25519_invert(const union x25519_oct258 *invertend, union x25519_quad257 *result)
Compute multiplicative inverse.
static int x25519_curve_multiply(const void *base, const void *scalar, void *result)
Multiply scalar by curve point.
static void x25519_init_constants(void)
Initialise constants.
static void x25519_subtract(const union x25519_quad257 *minuend, const union x25519_quad257 *subtrahend, union x25519_oct258 *result)
Subtract big integers modulo field prime.
static int x25519_curve_add(const void *addend __unused, const void *augend __unused, void *result __unused)
Add curve points (as a one-off operation)
static x25519_t x25519_p
Constant p=2^255-19 (the finite field prime)
#define X25519_SIZE
X25519 unsigned big integer size.