summaryrefslogtreecommitdiff
path: root/python/genkat_aead.py
blob: 01bed6f70d18a64ccfd22883f34733c3f05e3827 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3

import crypto_aead


MAX_MESSAGE_LENGTH = 32
MAX_ADATA_LENGTH = 32


def print_bstr(output, label, buf):
    print('{l} = {b}'.format(l=label, b=buf.hex().upper()), file=output)


def generate_test_vectors():
    output_path = 'LWC_AEAD_KAT_{key}_{npub}.txt'.format(
        key=crypto_aead.KEYBYTES*8, npub=crypto_aead.NPUBBYTES*8
    )

    npub = bytes(range(crypto_aead.NPUBBYTES))
    key = bytes(range(crypto_aead.KEYBYTES))

    with open(output_path, 'w') as output:

        count = 1
        for mlen in range(MAX_MESSAGE_LENGTH+1):
            for adlen in range(MAX_ADATA_LENGTH+1):
                print('Count = {c}'.format(c=count), file=output)

                msg = bytes(range(mlen))
                ad = bytes(range(adlen))

                print_bstr(output, 'Key', key)
                print_bstr(output, 'Nonce', npub)
                print_bstr(output, 'PT', msg)
                print_bstr(output, 'AD', ad)

                ct = crypto_aead.encrypt(msg, ad, npub, key)

                print_bstr(output, 'CT', ct)

                crypto_aead.decrypt(ct, ad, npub, key)

                count += 1

                print(file=output)


if __name__ == '__main__':
    generate_test_vectors()