Debian Codegraph @

src/test/make_tests_poly1305_load_m.py

raw symbols SCIP
1 """Make unit test for poly1305_load_m()"""
2
3 import struct
4
5 from common import counter, make_main, split64
6
7 def make_test(secret):
8
9 assert len(secret) <= 16
10
11 padded = secret + b"\x01" + b"\x00" * (20 - len(secret) - 1)
12 split = struct.unpack('<IIIII', padded)
13 m_out = [ "0x%08xUL" % x for x in split ]
14
15 print("")
16 print("void test_%d(void) {" % next(counter))
17 print(" uint8_t secret[%d] = {" % len(secret), end=' ')
18 print(",".join([str(x) for x in secret]) + "};")
19 print(" uint32_t m[5] = { 0 };")
20 print(" const uint32_t expected_m[5] = {" + ", ".join(m_out) + "};")
21 print("")
22 print(" poly1305_load_m(m, secret, %d);" % len(secret))
23 print(" assert(memcmp(m, expected_m, sizeof(m)) == 0);")
24 print("}")
25 print("")
26
27
28 print("#ifdef NDEBUG")
29 print("#undef NDEBUG")
30 print("#endif")
31 print("#include <assert.h>")
32 print("#include <string.h>")
33 print("#include <stdint.h>")
34 print("#include <stdio.h>")
35 print()
36 print("void poly1305_load_m(uint32_t r[5], const uint8_t data[], size_t len);")
37
38 for len_secret in range(1, 16+1):
39 make_test(b"\xaa" * len_secret)
40 make_test(b"\xcc" * 16)
41 make_test(b"\xff" * 16)
42 make_test(b"12\x00kjskskjp39027")
43 make_test(b"\x00")
44 make_test(b"\x00" * 16)
45 make_main()