Skip to content

Commit 6e8c43b

Browse files
committed
Add nonce length validation to ChaCha.set_iv
1 parent 3ca2548 commit 6e8c43b

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

wolfcrypt/ciphers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,13 @@ def _decrypt(self, destination, source):
530530
return _lib.wc_Chacha_Process(self._dec,
531531
destination, source, len(source))
532532

533+
_NONCE_SIZE = 12
534+
533535
def set_iv(self, nonce, counter = 0):
534536
self._IV_nonce = t2b(nonce)
537+
if len(self._IV_nonce) != self._NONCE_SIZE:
538+
raise ValueError("nonce must be %d bytes, got %d" %
539+
(self._NONCE_SIZE, len(self._IV_nonce)))
535540
self._IV_counter = counter
536541
self._set_key(0)
537542

0 commit comments

Comments
 (0)