From 322c7cb96709e222988c07ca19b19cbcb6500c9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Wed, 24 Jun 2020 18:54:36 +0300 Subject: [PATCH] Pass the 96bit nonce directly instead of in parts --- compact_chapoly.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compact_chapoly.py b/compact_chapoly.py index 42d2698..b5bbd1f 100644 --- a/compact_chapoly.py +++ b/compact_chapoly.py @@ -21,8 +21,8 @@ def poly1305(m,k): return unu(a+s,128) p16=lambda x:b'\x00'*(-len(x)%16) tag=lambda a,k,n,c:poly1305(b''.join((a,p16(a),c,p16(c),unu(len(a),64),unu(len(c),64))),ccb(k,0,n)[:32]) -def enc(a,k,i,f,p):c=bytes(chacha20(k,1,f+i,p));return c+tag(a,k,f+i,c) -def dec(a,k,i,f,e): +def enc(a,k,n,p):c=bytes(chacha20(k,1,n,p));return c+tag(a,k,n,c) +def dec(a,k,n,e): c=e[:-16] if not secrets.compare_digest(e[-16:],tag(a,k,f+i,c)):return None return bytes(chacha20(k,1,f+i,c))