Browse Source

ct: adds chained memcmp test

blog/frodo_constant_time_issue
Henry Case 3 years ago
parent
commit
a2cd3fb88d
1 changed files with 27 additions and 0 deletions
  1. +27
    -0
      test/ct.cpp

+ 27
- 0
test/ct.cpp View File

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

Loading…
Cancel
Save