-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
30 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
import unittest | ||
from random import seed, randbytes | ||
from kyber.decrypt import Decrypt | ||
from kyber.constants import k | ||
from kyber.constants import k, n, du, dv | ||
|
||
class TestDecryption(unittest.TestCase): | ||
def test_decryption_raises_with_invalid_input(self): | ||
# this private key is one byte too long | ||
def setUp(self): | ||
seed(42) | ||
|
||
def test_decryption_outputs_valid_shared_secret(self): | ||
private_key = randbytes(32*12*k) | ||
ciphertext = randbytes(du*k*n//8 + dv*n//8) | ||
shared_secret = Decrypt(private_key, ciphertext).decrypt() | ||
self.assertEqual(type(shared_secret), bytes) | ||
self.assertEqual(len(shared_secret), 32) | ||
|
||
def test_decryption_raises_with_invalid_private_key(self): | ||
# this private key is one byte too long | ||
invalid_private_key = randbytes(32*12*k + 1) | ||
ciphertext_placeholder = () | ||
valid_ciphertext = randbytes(du*k*n//8 + dv*n//8) | ||
with self.assertRaises(ValueError): | ||
Decrypt(invalid_private_key, valid_ciphertext) | ||
|
||
def test_decryption_raises_with_invalid_ciphertext(self): | ||
# this ciphertext is one byte too short | ||
valid_private_key = randbytes(32*12*k) | ||
invalid_ciphertext = randbytes(du*k*n//8 + dv*n//8 - 1) | ||
with self.assertRaises(ValueError): | ||
Decrypt(invalid_private_key, ciphertext_placeholder) | ||
Decrypt(valid_private_key, invalid_ciphertext) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters