aboutsummaryrefslogtreecommitdiff
path: root/lib/tst/blake2s_genkat.py
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2023-03-05 14:38:54 +0200
committeraqua <aqua@iserlohn-fortress.net>2023-03-05 14:38:54 +0200
commit787c1a6016dd2fdb51f20fcb5ca0ac5e461892d6 (patch)
tree7db9f5102adc3d50ca85a8175ce67465256b8908 /lib/tst/blake2s_genkat.py
parentAdd TARGETBIN and TARGETLIB rules (diff)
downloadkernel-787c1a6016dd2fdb51f20fcb5ca0ac5e461892d6.tar.xz
Move all tests next to the code they're testing
Diffstat (limited to 'lib/tst/blake2s_genkat.py')
-rwxr-xr-xlib/tst/blake2s_genkat.py40
1 files changed, 0 insertions, 40 deletions
diff --git a/lib/tst/blake2s_genkat.py b/lib/tst/blake2s_genkat.py
deleted file mode 100755
index 2dd5370..0000000
--- a/lib/tst/blake2s_genkat.py
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/env python3
-# Known Answer Test generator
-
-import json
-import hashlib
-import secrets
-
-def blake2s(w, key):
- ctx = hashlib.blake2s(key=key)
- ctx.update(w)
- return ctx.digest().hex()
-
-def out(s):
- o = [s[i:i+2] for i in range(0, len(s), 2)] # split into pairs
- o = [f'0x{i}' for i in o] # prepend 0x and join
- return ', '.join(o)
-
-if __name__ == '__main__':
- w = b''
- for i in range(0, 256):
- w += i.to_bytes(1, 'little')
- k = secrets.token_bytes(32)
-
- print('#pragma once\n')
- print(f'static const unsigned KATs_len = 256;')
- print(f'static const uint8_t KAT_secret[32] = {{ {", ".join([hex(i) for i in k])} }};')
-
- print(f'static const uint8_t KATs[256][32] = {{')
- for i in range(0, 256):
- o = blake2s(w[0:i], b'')
- print(f' // {i}')
- print(f' {{ {out(o)} }},')
- print(f'}};')
-
- print(f'static const uint8_t secret_KATs[256][32] = {{')
- for i in range(0, 256):
- o = blake2s(w[0:i], k)
- print(f' // {i}')
- print(f' {{ {out(o)} }},')
- print(f'}};')