all repos — TinyCrypT @ 39728dd7e0d3c64d6c747076bdd4472b9d7f9ff8

Short and sweet classical cryptographic primitives

Disabled tests for x25519 by default (now that all pass)
Juniper Beatitudes [email protected]
Sun, 11 Jan 2026 05:28:58 -0600
commit

39728dd7e0d3c64d6c747076bdd4472b9d7f9ff8

parent

95faecf39b87b4d6d12e0a8b53c50192046edc6f

2 files changed, 86 insertions(+), 11 deletions(-)

jump to
M meson.buildmeson.build

@@ -98,15 +98,16 @@ dependencies: test_dep,

install: false ) ) - test( - 'x25519_tests', - executable( - 'x25519_tests', - x25519_test_sources, - include_directories: incdir, - link_with: target, - dependencies: test_dep, - install: false - ) - ) + # Not included by default because it takes ~256 seconds to execute (includes a million-repetition test case) + # test( + # 'x25519_tests', + # executable( + # 'x25519_tests', + # x25519_test_sources, + # include_directories: incdir, + # link_with: target, + # dependencies: test_dep, + # install: false + # ) + # ) endif
M tests/src/x25519/all.cpptests/src/x25519/all.cpp

@@ -42,4 +42,78 @@ 0xa1, 0x52, 0xe6, 0xf8, 0xf7, 0x64, 0x7a, 0xac, 0x79, 0x57 };

uint8_t actual[sizeof (EXPECTED)]; tct_x25519 (SCALAR, U, actual); EXPECT_EQ (memcmp (actual, EXPECTED, sizeof (EXPECTED)), 0); +} + +TEST (X25519, x25519_repetition_1) +{ + uint8_t buf[96]; + uint8_t *k = buf; + uint8_t *u = buf + 32; + uint8_t *out = buf + 64; + for (unsigned int i = 0; i < 32; ++i) + { + k[i] = u[i] = 0x0; + } + k[0] = 0x9; + u[0] = 0x9; + tct_x25519 (k, u, out); + const uint8_t EXPECTED[] + = { 0x42, 0x2c, 0x8e, 0x7a, 0x62, 0x27, 0xd7, 0xbc, 0xa1, 0x35, 0x0b, + 0x3e, 0x2b, 0xb7, 0x27, 0x9f, 0x78, 0x97, 0xb8, 0x7b, 0xb6, 0x85, + 0x4b, 0x78, 0x3c, 0x60, 0xe8, 0x03, 0x11, 0xae, 0x30, 0x79 }; + EXPECT_EQ (memcmp (out, EXPECTED, sizeof (EXPECTED)), 0); +} + +TEST (X25519, x25519_repetition_1000) +{ + uint8_t buf[96]; + uint8_t *k = buf; + uint8_t *u = buf + 32; + uint8_t *out = buf + 64; + for (unsigned int i = 0; i < 32; ++i) + { + k[i] = u[i] = 0x0; + } + k[0] = 0x9; + u[0] = 0x9; + for (unsigned int i = 0; i < 1000; ++i) + { + tct_x25519 (k, u, out); + uint8_t *tmp = k; + k = out; + out = u; + u = tmp; + } + const uint8_t EXPECTED[] + = { 0x68, 0x4c, 0xf5, 0x9b, 0xa8, 0x33, 0x09, 0x55, 0x28, 0x00, 0xef, + 0x56, 0x6f, 0x2f, 0x4d, 0x3c, 0x1c, 0x38, 0x87, 0xc4, 0x93, 0x60, + 0xe3, 0x87, 0x5f, 0x2e, 0xb9, 0x4d, 0x99, 0x53, 0x2c, 0x51 }; + EXPECT_EQ (memcmp (k, EXPECTED, sizeof (EXPECTED)), 0); +} + +TEST (X25519, x25519_repetition_1000000) +{ + uint8_t buf[96]; + uint8_t *k = buf; + uint8_t *u = buf + 32; + uint8_t *out = buf + 64; + for (unsigned int i = 0; i < 32; ++i) + { + k[i] = u[i] = 0x0; + } + k[0] = 0x9; + u[0] = 0x9; + for (unsigned int i = 0; i < 1000000; ++i) + { + tct_x25519 (k, u, out); + uint8_t *tmp = k; + k = out; + out = u; + u = tmp; + } + const uint8_t EXPECTED[] + = { 0x7c, 0x39, 0x11, 0xe0, 0xab, 0x25, 0x86, 0xfd, 0x86, 0x44, 0x97, + 0x29, 0x7e, 0x57, 0x5e, 0x6f, 0x3b, 0xc6, 0x01, 0xc0, 0x88, 0x3c, + 0x30, 0xdf, 0x5f, 0x4d, 0xd2, 0xd2, 0x4f, 0x66, 0x54, 0x24 }; + EXPECT_EQ (memcmp (k, EXPECTED, sizeof (EXPECTED)), 0); }