add and use constant time 32 byte equality function

This commit is contained in:
moneromooo-monero 2018-06-13 18:23:06 +01:00
parent 510dbf3329
commit d2e26c23f3
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
9 changed files with 130 additions and 14 deletions

View file

@ -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);
}
}
}