diff options
| author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2026-07-02 01:12:51 +0200 |
|---|---|---|
| committer | Sander Vrijders <sander@ouroboros.rocks> | 2026-07-08 11:02:23 +0200 |
| commit | 92258b43691a7c8fa420941a4d3b3f870e05d55f (patch) | |
| tree | 1940da81b2f80f7b2b455c755c6a28d8da0bdb08 /src/lib/tests/crypt_test.c | |
| parent | 4c836008dcac27e0a8258b07270a8a529b2d9167 (diff) | |
| download | ouroboros-92258b43691a7c8fa420941a4d3b3f870e05d55f.tar.gz ouroboros-92258b43691a7c8fa420941a4d3b3f870e05d55f.zip | |
lib: Harden crypto unit tests
Stop the non-OpenSSL runners from masking a real failure as SKIP by
only downgrading to SKIP if they passed.
Fix a stray call that ran test_kex_dhe_wrong_algo in the skip branch.
Fix double free + free of an uninitialised pointer in test_store_add.
Test that a KDF- less derive must fail.
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/lib/tests/crypt_test.c')
| -rw-r--r-- | src/lib/tests/crypt_test.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/lib/tests/crypt_test.c b/src/lib/tests/crypt_test.c index 2d752238..f00618d8 100644 --- a/src/lib/tests/crypt_test.c +++ b/src/lib/tests/crypt_test.c @@ -528,6 +528,47 @@ static int test_crypt_headsz(void) return TEST_RC_FAIL; } +static int test_crypt_ct_cmp(void) +{ + uint8_t a[64]; + uint8_t b[64]; + size_t i; + + TEST_START(); + + for (i = 0; i < sizeof(a); i++) + a[i] = (uint8_t) i; + + memcpy(b, a, sizeof(a)); + + if (crypt_ct_cmp(a, b, sizeof(a)) != 0) { + printf("Equal buffers should compare equal.\n"); + goto fail; + } + + if (crypt_ct_cmp(a, b, 0) != 0) { + printf("Zero length should compare equal.\n"); + goto fail; + } + + for (i = 0; i < sizeof(a); i++) { + b[i] ^= 0x01; + if (crypt_ct_cmp(a, b, sizeof(a)) == 0) { + printf("Difference at byte %zu not detected.\n", i); + goto fail; + } + + b[i] ^= 0x01; + } + + TEST_SUCCESS(); + + return TEST_RC_SUCCESS; + fail: + TEST_FAIL(); + return TEST_RC_FAIL; +} + int crypt_test(int argc, char ** argv) { @@ -538,6 +579,7 @@ int crypt_test(int argc, ret |= test_crypt_create_destroy(); ret |= test_encrypt_decrypt_all(); + ret |= test_crypt_ct_cmp(); #ifdef HAVE_OPENSSL ret |= test_cipher_nid_values(); ret |= test_md_nid_values(); @@ -549,7 +591,8 @@ int crypt_test(int argc, (void) test_aad_tamper_all; (void) test_crypt_headsz; - return TEST_RC_SKIP; + if (ret == 0) + ret = TEST_RC_SKIP; #endif return ret; } |
