fix bug in python aes-gcm-siv reference implementation

This commit is contained in:
bunnie 2021-11-23 02:56:54 +08:00
parent eda60a5d9c
commit 77d3f8a646

View file

@ -121,13 +121,15 @@ def b2i(s):
def i2b(i): def i2b(i):
if i == 0: return i.to_bytes(16, 'little')
return b'\x00'*16 # original implementation below -- if the leading bytes are '00', it will truncate and return a 15-long array, instead of 16-long, which is incorrect.
s = b'' #if i == 0:
while i: # return b'\x00'*16
s += chr(i & 0xff) if six.PY2 else bytes([i & 0xff]) #s = b''
i >>= 8 #while i:
return bytes(s) # s += chr(i & 0xff) if six.PY2 else bytes([i & 0xff])
# i >>= 8
#return bytes(s)
def s2i(s): def s2i(s):