static int
test_adds(void) {
#if defined(HAVE_UINT128) && !defined(ED25519_SSE2)
static const bignum25519 max_bignum = {
0x7ffffffffffff,0x8000000001230,0x7ffffffffffff,0x7ffffffffffff,0x7ffffffffffff
};
#if 0#endif
static const unsigned char max_bignum2_squared_raw[32] = {
0x10,0x05,0x00,0x00,0x00,0x00,0x80,0xdc,0x51,0x00,0x00,0x00,0x00,0x61,0xed,0x4a,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
static const unsigned char max_bignum3_squared_raw[32] = {
0x64,0x0b,0x00,0x00,0x00,0x00,0x20,0x30,0xb8,0x00,0x00,0x00,0x40,0x1a,0x96,0xe8,
0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
#else
static const bignum25519 ALIGN(16) max_bignum = {
0x3ffffff,0x2000300,0x3ffffff,0x1ffffff,0x3ffffff,
0x1ffffff,0x3ffffff,0x1ffffff,0x3ffffff,0x1ffffff
};
static const unsigned char max_bignum2_squared_raw[32] = {
0x10,0x05,0x00,0x40,0xc2,0x06,0x40,0x80,0x41,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
static const unsigned char max_bignum3_squared_raw[32] = {
0x64,0x0b,0x00,0x10,0x35,0x0f,0x90,0x60,0x13,0x05,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
#endif
unsigned char result[32];
bignum25519 ALIGN(16) a, b ;
curve25519_add(a, max_bignum, max_bignum);
curve25519_mul(b, a, a);
curve25519_contract(result, b);
if (memcmp(result, max_bignum2_squared_raw, 32) != 0)
return -1;
curve25519_square(b, a);
curve25519_contract(result, b);
if (memcmp(result, max_bignum2_squared_raw, 32) != 0)
return -1;
curve25519_add_after_basic(b, a, max_bignum);
curve25519_mul(a, b, b);
curve25519_contract(result, a);
if (memcmp(result, max_bignum3_squared_raw, 32) != 0)
return -1;
curve25519_square(a, b);
curve25519_contract(result, a);
if (memcmp(result, max_bignum3_squared_raw, 32) != 0)
return -1;
return 0;
}
static int
test_subs(void) {
#if defined(HAVE_UINT128) && !defined(ED25519_SSE2)
static const bignum25519 max_bignum = {
0x7ffffffffffff,0x8000000001230,0x7ffffffffffff,0x7ffffffffffff,0x7ffffffffffff
};
static const unsigned char max_bignum_raw[32] = {
0x12,0x00,0x00,0x00,0x00,0x00,0x88,0x91,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
static const unsigned char max_bignum_squared_raw[32] = {
0x44,0x01,0x00,0x00,0x00,0x00,0x20,0x77,0x14,0x00,0x00,0x00,0x40,0x58,0xbb,0x52,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
#else
static const bignum25519 ALIGN(16) max_bignum = {
0x3ffffff,0x2000300,0x3ffffff,0x1ffffff,0x3ffffff,
0x1ffffff,0x3ffffff,0x1ffffff,0x3ffffff,0x1ffffff
};
static const unsigned char max_bignum_raw[32] = {
0x12,0x00,0x00,0x04,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
static const unsigned char max_bignum_squared_raw[32] = {
0x44,0x01,0x00,0x90,0xb0,0x01,0x10,0x60,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
#endif
unsigned char result[32];
static const bignum25519 ALIGN(16) zero = {0};
bignum25519 ALIGN(16) a, b ;
curve25519_sub(a, max_bignum, zero);
curve25519_contract(result, a);
if (memcmp(result, max_bignum_raw, 32) != 0)
return -1;
curve25519_mul(b, a, a);
curve25519_contract(result, b);
if (memcmp(result, max_bignum_squared_raw, 32) != 0)
return -1;
curve25519_square(b, a);
curve25519_contract(result, b);
if (memcmp(result, max_bignum_squared_raw, 32) != 0)
return -1;
curve25519_sub_after_basic(b, a, zero);
curve25519_contract(result, b);
if (memcmp(result, max_bignum_raw, 32) != 0)
return -1;
curve25519_mul(a, b, b);
curve25519_contract(result, a);
if (memcmp(result, max_bignum_squared_raw, 32) != 0)
return -1;
curve25519_square(a, b);
curve25519_contract(result, a);
if (memcmp(result, max_bignum_squared_raw, 32) != 0)
return -1;
return 0;
}
#if 0#endif
int
ed25519_donna_selftest(void)
{
int ret = 0;
ret |= test_adds();
ret |= test_subs();
return (ret == 0) ? 0 : -1;
}