Debian Codegraph @

src/test/make_tests_poly1305_reduce.py

raw symbols SCIP
1 """Make unit test for poly1305_reduce()"""
2
3 from common import counter, make_main, split32
4
5
6 def make_test(value):
7
8 result = value % (2**130 - 5)
9
10 h_in = split32(value, 5)
11 h_out = split32(result, 5)
12
13 print("")
14 print("void test_%d(void) {" % next(counter))
15 print(" uint32_t h[5] = {" + ", ".join(h_in) + "};")
16 print(" const uint32_t expected_h[5] = {" + ", ".join(h_out) + "};")
17 print("")
18 print(" poly1305_reduce(h);")
19 print(" assert(memcmp(h, expected_h, sizeof(h)) == 0);")
20 print("}")
21 print("")
22
23
24 print("#ifdef NDEBUG")
25 print("#undef NDEBUG")
26 print("#endif")
27 print("#include <assert.h>")
28 print("#include <string.h>")
29 print("#include <stdint.h>")
30 print("#include <stdio.h>")
31 print()
32 print("void poly1305_reduce(uint32_t h[5]);")
33
34 make_test(0)
35 make_test(2**130-5-1)
36 make_test(2**130-5)
37 make_test(2**130-5+1)
38 make_test(2*(2**130-5))
39 make_test(2*(2**130-5)+9)
40 # make_test(2*(2**130-5)+10) - Fails, since h[5] takes more than 3 bits
41 make_main()