diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-06-13 18:23:06 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-08-23 07:56:51 +0000 |
commit | d2e26c23f3caa7928c46c3a6bded85fdc1a68cb3 (patch) | |
tree | 78381c86a73e46cc265d58dd9ff770fd56a1ec99 /tests/unit_tests/crypto.cpp | |
parent | Merge pull request #4249 (diff) | |
download | monero-d2e26c23f3caa7928c46c3a6bded85fdc1a68cb3.tar.xz |
add and use constant time 32 byte equality function
Diffstat (limited to 'tests/unit_tests/crypto.cpp')
-rw-r--r-- | tests/unit_tests/crypto.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp index 9e1680568..29fa88f9d 100644 --- a/tests/unit_tests/crypto.cpp +++ b/tests/unit_tests/crypto.cpp @@ -81,3 +81,18 @@ TEST(Crypto, null_keys) ASSERT_EQ(memcmp(crypto::null_skey.data, zero, 32), 0); ASSERT_EQ(memcmp(crypto::null_pkey.data, zero, 32), 0); } + +TEST(Crypto, verify_32) +{ + // all bytes are treated the same, so we can brute force just one byte + unsigned char k0[32] = {0}, k1[32] = {0}; + for (unsigned int i0 = 0; i0 < 256; ++i0) + { + k0[0] = i0; + for (unsigned int i1 = 0; i1 < 256; ++i1) + { + k1[0] = i1; + ASSERT_EQ(!crypto_verify_32(k0, k1), i0 == i1); + } + } +} |