summaryrefslogtreecommitdiff
path: root/test/python/crypto_aead.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/python/crypto_aead.py')
-rw-r--r--test/python/crypto_aead.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/python/crypto_aead.py b/test/python/crypto_aead.py
new file mode 100644
index 0000000..d2f1896
--- /dev/null
+++ b/test/python/crypto_aead.py
@@ -0,0 +1,40 @@
+# Implementation of the Lilliput-AE tweakable block cipher.
+#
+# Authors, hereby denoted as "the implementer":
+# Kévin Le Gouguec,
+# 2019.
+#
+# For more information, feedback or questions, refer to our website:
+# https://paclido.fr/lilliput-ae
+#
+# To the extent possible under law, the implementer has waived all copyright
+# and related or neighboring rights to the source code in this file.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+"""Python port of the crypto_aead API for Lilliput-AE."""
+
+import lilliput
+
+from lilliput.constants import (
+ NONCE_BITS,
+ TAG_BYTES
+)
+
+from parameters import (
+ KEYBYTES, # Expose to genkat_aead.
+ MODE
+)
+
+
+NPUBBYTES = NONCE_BITS//8
+
+
+def encrypt(m, ad, npub, k):
+ c, tag = lilliput.encrypt(m, ad, k, npub, MODE)
+ return c+tag
+
+
+def decrypt(c, ad, npub, k):
+ ctext = c[:-TAG_BYTES]
+ tag = c[-TAG_BYTES:]
+ return lilliput.decrypt(ctext, tag, ad, k, npub, MODE)