-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attempt to increase coverage #73
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import unittest | ||
import os | ||
from kyber_py.drbg.aes256_ctr_drbg import AES256_CTR_DRBG | ||
|
||
|
||
class TestDRBG(unittest.TestCase): | ||
""" | ||
Some small tests, as the general check for the DRBG is that | ||
the KAT vectors match with the assets within the mlkem and | ||
kyber tests. | ||
""" | ||
|
||
def test_no_seed(self): | ||
# If seed is none, os.urandom is used instead | ||
seed = None | ||
drbg = AES256_CTR_DRBG(seed) | ||
self.assertNotEqual(drbg.entropy_input, None) | ||
|
||
def test_bad_seed(self): | ||
# if the seed length is not 48, the code fails | ||
seed = b"1" | ||
self.assertRaises(ValueError, lambda: AES256_CTR_DRBG(seed)) | ||
seed = b"1" * 49 | ||
self.assertRaises(ValueError, lambda: AES256_CTR_DRBG(seed)) | ||
|
||
def test_personalization(self): | ||
# if the personalization is longer than 48 bytes, fail | ||
seed = os.urandom(48) | ||
personalization = os.urandom(24) | ||
drbg = AES256_CTR_DRBG(seed, personalization) | ||
self.assertEqual(AES256_CTR_DRBG, type(drbg)) | ||
|
||
def test_bad_personalization(self): | ||
# if the personalization is longer than 48 bytes, fail | ||
seed = os.urandom(48) | ||
personalization = os.urandom(49) | ||
self.assertRaises( | ||
ValueError, lambda: AES256_CTR_DRBG(seed, personalization) | ||
) | ||
|
||
def test_additional(self): | ||
drbg = AES256_CTR_DRBG() | ||
additional = os.urandom(24) | ||
b = drbg.random_bytes(32, additional) | ||
self.assertEqual(len(b), 32) | ||
self.assertEqual(type(b), bytes) | ||
|
||
def test_bad_additional(self): | ||
drbg = AES256_CTR_DRBG() | ||
additional = os.urandom(49) | ||
self.assertRaises( | ||
ValueError, lambda: drbg.random_bytes(32, additional) | ||
) |
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 |
---|---|---|
|
@@ -60,14 +60,16 @@ def test_equality(self): | |
f1 = self.R.random_element() | ||
f2 = -f1 | ||
self.assertEqual(f1, f1) | ||
# We don't cover the case of f1 being zero, as it's incredibly unlikely to happen | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's something that |
||
if f1.is_zero(): | ||
self.assertTrue(f1 == f2) | ||
self.assertTrue(f1 == f2) # pragma: no cover | ||
else: | ||
self.assertFalse(f1 == f2) | ||
|
||
self.assertTrue(self.R(0) == 0) | ||
self.assertTrue(self.R(1) == self.R.q + 1) | ||
self.assertTrue(self.R(self.R.q - 1) == -1) | ||
self.assertTrue(self.R(0) != 1) | ||
self.assertFalse(self.R(self.R.q - 1) == "a") | ||
|
||
def test_add_failure(self): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we couldn't test it through mocking...