-
Notifications
You must be signed in to change notification settings - Fork 46
/
gentests.py
38 lines (32 loc) · 1.02 KB
/
gentests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import testdata
import string
def fn_for_hash(h):
return 'fastpbkdf2_hmac_' + h
def fmt(xs):
out = []
# in C hex escapes are the longest possible sequence of hex
# digits. make sure we don't form one longer than two digits!
lasthex = False
for x in xs:
if x.isalpha() and not (lasthex and x in string.hexdigits):
out.append(x)
lasthex = False
else:
out.append('\\x%02x' % ord(x))
lasthex = True
return ''.join(out)
for hash, tests in sorted(testdata.tests.items()):
print ' printf("%s (%d tests):\\n");' % (hash, len(tests))
for t in tests:
print """ check(%s,
"%s", %d,
"%s", %d,
%d,
"%s", %d);
""" % (fn_for_hash(hash),
fmt(t['password']), len(t['password']),
fmt(t['salt']), len(t['salt']),
t['iterations'],
fmt(t['output']), len(t['output']))
print ' printf("ok\\n");'
print