mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
merge bitcoin#29390: speedup bip324_cipher.py unit test
This commit is contained in:
parent
062aaf11e4
commit
2455862c9f
@ -25,6 +25,8 @@ def pad16(x):
|
|||||||
|
|
||||||
def aead_chacha20_poly1305_encrypt(key, nonce, aad, plaintext):
|
def aead_chacha20_poly1305_encrypt(key, nonce, aad, plaintext):
|
||||||
"""Encrypt a plaintext using ChaCha20Poly1305."""
|
"""Encrypt a plaintext using ChaCha20Poly1305."""
|
||||||
|
if plaintext is None:
|
||||||
|
return None
|
||||||
ret = bytearray()
|
ret = bytearray()
|
||||||
msg_len = len(plaintext)
|
msg_len = len(plaintext)
|
||||||
for i in range((msg_len + 63) // 64):
|
for i in range((msg_len + 63) // 64):
|
||||||
@ -42,7 +44,7 @@ def aead_chacha20_poly1305_encrypt(key, nonce, aad, plaintext):
|
|||||||
|
|
||||||
def aead_chacha20_poly1305_decrypt(key, nonce, aad, ciphertext):
|
def aead_chacha20_poly1305_decrypt(key, nonce, aad, ciphertext):
|
||||||
"""Decrypt a ChaCha20Poly1305 ciphertext."""
|
"""Decrypt a ChaCha20Poly1305 ciphertext."""
|
||||||
if len(ciphertext) < 16:
|
if ciphertext is None or len(ciphertext) < 16:
|
||||||
return None
|
return None
|
||||||
msg_len = len(ciphertext) - 16
|
msg_len = len(ciphertext) - 16
|
||||||
poly1305 = Poly1305(chacha20_block(key, nonce, 0)[:32])
|
poly1305 = Poly1305(chacha20_block(key, nonce, 0)[:32])
|
||||||
@ -191,11 +193,11 @@ class TestFrameworkAEAD(unittest.TestCase):
|
|||||||
dec_aead = FSChaCha20Poly1305(key)
|
dec_aead = FSChaCha20Poly1305(key)
|
||||||
|
|
||||||
for _ in range(msg_idx):
|
for _ in range(msg_idx):
|
||||||
enc_aead.encrypt(b"", b"")
|
enc_aead.encrypt(b"", None)
|
||||||
ciphertext = enc_aead.encrypt(aad, plain)
|
ciphertext = enc_aead.encrypt(aad, plain)
|
||||||
self.assertEqual(hex_cipher, ciphertext.hex())
|
self.assertEqual(hex_cipher, ciphertext.hex())
|
||||||
|
|
||||||
for _ in range(msg_idx):
|
for _ in range(msg_idx):
|
||||||
dec_aead.decrypt(b"", bytes(16))
|
dec_aead.decrypt(b"", None)
|
||||||
plaintext = dec_aead.decrypt(aad, ciphertext)
|
plaintext = dec_aead.decrypt(aad, ciphertext)
|
||||||
self.assertEqual(plain, plaintext)
|
self.assertEqual(plain, plaintext)
|
||||||
|
Loading…
Reference in New Issue
Block a user