Fixes from review
parent
01219a4659
commit
6e9f2ba1dc
|
|
@ -50,6 +50,24 @@ if _lib.CHACHA20_POLY1305_ENABLED:
|
|||
with pytest.raises(ValueError):
|
||||
ChaCha20Poly1305(b"tooshort")
|
||||
|
||||
def test_encrypt_invalid_iv_length():
|
||||
key = h2b("808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f")
|
||||
chacha = ChaCha20Poly1305(key)
|
||||
with pytest.raises(ValueError):
|
||||
chacha.encrypt(b"aad", b"short", b"plaintext")
|
||||
|
||||
def test_decrypt_invalid_iv_length():
|
||||
key = h2b("808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f")
|
||||
chacha = ChaCha20Poly1305(key)
|
||||
with pytest.raises(ValueError):
|
||||
chacha.decrypt(b"aad", b"short", b"\x00" * 16, b"ciphertext")
|
||||
|
||||
def test_decrypt_invalid_tag_length():
|
||||
key = h2b("808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f")
|
||||
chacha = ChaCha20Poly1305(key)
|
||||
with pytest.raises(ValueError):
|
||||
chacha.decrypt(b"aad", b"\x00" * 12, b"short", b"ciphertext")
|
||||
|
||||
def test_decrypt_bad_tag():
|
||||
key = h2b("808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f")
|
||||
iv = h2b("07000000404142434445464748")
|
||||
|
|
|
|||
|
|
@ -561,6 +561,8 @@ if _lib.CHACHA20_POLY1305_ENABLED:
|
|||
"""
|
||||
aad = t2b(aad)
|
||||
iv = t2b(iv)
|
||||
if len(iv) != 12:
|
||||
raise ValueError("iv must be 12 bytes, got %d" % len(iv))
|
||||
plaintext = t2b(plaintext)
|
||||
ciphertext = _ffi.new("byte[%d]" % len(plaintext))
|
||||
authTag = _ffi.new("byte[%d]" % self._tag_bytes)
|
||||
|
|
@ -587,7 +589,12 @@ if _lib.CHACHA20_POLY1305_ENABLED:
|
|||
"""
|
||||
aad = t2b(aad)
|
||||
iv = t2b(iv)
|
||||
if len(iv) != 12:
|
||||
raise ValueError("iv must be 12 bytes, got %d" % len(iv))
|
||||
authTag = t2b(authTag)
|
||||
if len(authTag) != self._tag_bytes:
|
||||
raise ValueError("authTag must be %d bytes, got %d" %
|
||||
(self._tag_bytes, len(authTag)))
|
||||
ciphertext = t2b(ciphertext)
|
||||
plaintext = _ffi.new("byte[%d]" % len(ciphertext))
|
||||
ret = _lib.wc_ChaCha20Poly1305_Decrypt(
|
||||
|
|
|
|||
Loading…
Reference in New Issue