1 #define TEST_NAME "scalarmult_ed25519"
4 static const unsigned char non_canonical_p[32] = {
5 0xf6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
6 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f
8 static const unsigned char non_canonical_invalid_p[32] = {
9 0xf5, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
10 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f
12 static const unsigned char max_canonical_p[32] = {
13 0xe4, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
14 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f
17 static const unsigned char B[32] = {
18 0x58, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
19 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66
25 unsigned char *n, *p, *q, *q2;
27 n = (unsigned char *) sodium_malloc(crypto_scalarmult_ed25519_SCALARBYTES);
28 p = (unsigned char *) sodium_malloc(crypto_scalarmult_ed25519_BYTES);
29 q = (unsigned char *) sodium_malloc(crypto_scalarmult_ed25519_BYTES);
30 q2 = (unsigned char *) sodium_malloc(crypto_scalarmult_ed25519_BYTES);
32 randombytes_buf(n, crypto_scalarmult_ed25519_SCALARBYTES);
33 if (crypto_scalarmult_ed25519_base(q, n) != 0) {
34 printf("crypto_scalarmult_ed25519_base() failed\n");
36 memcpy(p, B, crypto_scalarmult_ed25519_BYTES);
37 if (crypto_scalarmult_ed25519(q2, n, p) != 0) {
38 printf("crypto_scalarmult_ed25519() failed\n");
40 if (memcmp(q, q2, crypto_scalarmult_ed25519_BYTES) != 0) {
41 printf("crypto_scalarmult_ed25519_base(n) != crypto_scalarmult_ed25519(n, 9)\n");
44 memset(n, 0, crypto_scalarmult_ed25519_SCALARBYTES);
45 if (crypto_scalarmult_ed25519_base(q, n) != -1) {
46 printf("crypto_scalarmult_ed25519_base(0) failed\n");
48 if (crypto_scalarmult_ed25519(q2, n, p) != -1) {
49 printf("crypto_scalarmult_ed25519(0) passed\n");
53 if (crypto_scalarmult_ed25519_base(q, n) != 0) {
54 printf("crypto_scalarmult_ed25519_base() failed\n");
56 if (crypto_scalarmult_ed25519(q2, n, p) != 0) {
57 printf("crypto_scalarmult_ed25519() passed\n");
60 if (crypto_scalarmult_ed25519(q, n, non_canonical_p) != -1) {
61 printf("crypto_scalarmult_ed25519() didn't fail\n");
63 if (crypto_scalarmult_ed25519(q, n, non_canonical_invalid_p) != -1) {
64 printf("crypto_scalarmult_ed25519() didn't fail\n");
66 if (crypto_scalarmult_ed25519(q, n, max_canonical_p) != 0) {
67 printf("crypto_scalarmult_ed25519() failed\n");
70 memset(p, 0, crypto_scalarmult_ed25519_BYTES);
71 if (crypto_scalarmult_ed25519(q, n, p) != -1) {
72 printf("crypto_scalarmult_ed25519() didn't fail\n");
75 if (crypto_scalarmult_ed25519(q, n, p) != -1) {
76 printf("crypto_scalarmult_ed25519() didn't fail\n");
84 assert(crypto_scalarmult_ed25519_BYTES == crypto_scalarmult_ed25519_bytes());
85 assert(crypto_scalarmult_ed25519_SCALARBYTES == crypto_scalarmult_ed25519_scalarbytes());