crypto_aead.py (957B)
1 # Implementation of the Lilliput-AE tweakable block cipher. 2 # 3 # Authors, hereby denoted as "the implementer": 4 # Kévin Le Gouguec, 5 # 2019. 6 # 7 # For more information, feedback or questions, refer to our website: 8 # https://paclido.fr/lilliput-ae 9 # 10 # To the extent possible under law, the implementer has waived all copyright 11 # and related or neighboring rights to the source code in this file. 12 # http://creativecommons.org/publicdomain/zero/1.0/ 13 14 """Python port of the crypto_aead API for Lilliput-AE.""" 15 16 import lilliput 17 18 from lilliput.constants import ( 19 NONCE_BITS, 20 TAG_BYTES 21 ) 22 23 from parameters import ( 24 KEYBYTES, # Expose to genkat_aead. 25 MODE 26 ) 27 28 29 NPUBBYTES = NONCE_BITS//8 30 31 32 def encrypt(m, ad, npub, k): 33 c, tag = lilliput.encrypt(m, ad, k, npub, MODE) 34 return c+tag 35 36 37 def decrypt(c, ad, npub, k): 38 ctext = c[:-TAG_BYTES] 39 tag = c[-TAG_BYTES:] 40 return lilliput.decrypt(ctext, tag, ad, k, npub, MODE)