ct: adds chained memcmp test

This commit is contained in:
Henry Case 2021-06-30 23:40:09 +01:00
джерело be7a0bbdb8
коміт a2cd3fb88d

@ -83,3 +83,30 @@ TEST(ConstantTime, CtCheck_memcmp) {
ct_purify(&ret, 1);
ASSERT_EQ(ret,1);
}
TEST(ConstantTime, CtCheck_memcmp_chained) {
unsigned char a[16], b[16], c[16], d[16];
memset(a, 42, sizeof(a));
memset(b, 42, sizeof(b));
memset(d, 42, sizeof(b));
memset(c, 41, sizeof(c));
uint8_t ret;
ct_poison(a, 16);
ct_expect_umr();
// obviously must generate UMR if if first check fails
// and second is not done
ret = (ct_memcmp(a,c,16)==0) && (ct_memcmp(a,b,16)==0);
ct_require_umr();
ct_purify(&ret, 1);
ASSERT_EQ(ret,0);
ct_expect_umr();
// it's still UMR even if both checks are OK
ret = (ct_memcmp(a,d,16)==0) && (ct_memcmp(a,b,16)==0);
ct_require_umr();
ct_purify(&ret, 1);
ASSERT_EQ(ret,1);
}