summaryrefslogtreecommitdiff
path: root/test/default/core_ed25519.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/default/core_ed25519.c')
-rw-r--r--test/default/core_ed25519.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/test/default/core_ed25519.c b/test/default/core_ed25519.c
index 54ceeed9..9a9bebb5 100644
--- a/test/default/core_ed25519.c
+++ b/test/default/core_ed25519.c
@@ -17,6 +17,11 @@ static const unsigned char not_main_subgroup_p[32] = {
0x95, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99,
0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99
};
+/* A point of order 8 */
+static const unsigned char torsion8_p[32] = {
+ 0x26, 0xe8, 0x95, 0x8f, 0xc2, 0xb2, 0x27, 0xb0, 0x45, 0xc3, 0xf4, 0x89, 0xf2, 0xef, 0x98, 0xf0,
+ 0xd5, 0xdf, 0xac, 0x05, 0xd3, 0xc6, 0x33, 0x39, 0xb1, 0x38, 0x02, 0x88, 0x6d, 0x53, 0xfc, 0x05
+};
static const unsigned char L_p1[32] = {
0xee, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
@@ -37,6 +42,13 @@ static const unsigned char sc_highbit[32] = {
0x08, 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, 0x00, 0x00, 0x00, 0x80
};
+/* Checks that inversion runs enough steps. */
+static const unsigned char sc_slow_invert[32] = {
+ 0x78, 0x0d, 0xb2, 0xb5, 0x94, 0x5a, 0xcf, 0xdc,
+ 0x38, 0x69, 0xae, 0x85, 0xf3, 0xb2, 0x6a, 0x90,
+ 0x3f, 0xf4, 0x48, 0x35, 0x9b, 0xef, 0xb2, 0x68,
+ 0xd1, 0x2f, 0xe5, 0xcb, 0x0b, 0x91, 0x14, 0x0f
+};
static void
add_P(unsigned char * const S)
@@ -52,6 +64,19 @@ add_P(unsigned char * const S)
}
static void
+check_scalar_invert(const unsigned char *s)
+{
+ unsigned char inv[crypto_core_ed25519_SCALARBYTES];
+
+ if (crypto_core_ed25519_scalar_invert(inv, s) != 0) {
+ printf("crypto_core_ed25519_scalar_invert() failed\n");
+ }
+ crypto_core_ed25519_scalar_mul(inv, inv, s);
+ assert(inv[0] == 1);
+ assert(sodium_is_zero(inv + 1, crypto_core_ed25519_SCALARBYTES - 1));
+}
+
+static void
add_l64(unsigned char * const S)
{
static const unsigned char l[crypto_core_ed25519_NONREDUCEDSCALARBYTES] =
@@ -153,6 +178,14 @@ main(void)
assert(crypto_core_ed25519_is_valid_point(non_canonical_p) == 0);
assert(crypto_core_ed25519_is_valid_point(not_main_subgroup_p) == 0);
+ for (i = 0; i < 100; i++) {
+ crypto_core_ed25519_random(p2);
+ for (j = 1; j < 8; j++) {
+ crypto_core_ed25519_add(p2, p2, torsion8_p);
+ assert(crypto_core_ed25519_is_valid_point(p2) == 0);
+ }
+ }
+
memcpy(p2, p, crypto_core_ed25519_BYTES);
add_P(p2);
crypto_core_ed25519_add(p3, p2, p2);
@@ -332,11 +365,20 @@ main(void)
crypto_core_ed25519_scalar_add(sc3, sc, sc2);
assert(!sodium_is_zero(sc, crypto_core_ed25519_SCALARBYTES));
crypto_core_ed25519_scalar_sub(sc3, sc3, sc2);
- assert(!sodium_is_zero(sc, crypto_core_ed25519_SCALARBYTES));
crypto_core_ed25519_scalar_sub(sc3, sc3, sc);
assert(sodium_is_zero(sc3, crypto_core_ed25519_SCALARBYTES));
+ check_scalar_invert(sc);
}
+ check_scalar_invert(L_1);
+ check_scalar_invert(L_p1);
+ check_scalar_invert(sc_highbit);
+ check_scalar_invert(sc_slow_invert);
+ if (crypto_core_ed25519_scalar_invert(sc, L) != 0) {
+ printf("crypto_core_ed25519_scalar_invert() failed\n");
+ }
+ assert(sodium_is_zero(sc, crypto_core_ed25519_SCALARBYTES));
+
memset(sc, 0x69, crypto_core_ed25519_SCALARBYTES);
memset(sc2, 0x42, crypto_core_ed25519_SCALARBYTES);
crypto_core_ed25519_scalar_add(sc, sc, sc2);