Skip to content
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

raise ValueError on zero length GCM IV #4348

Merged
merged 1 commit into from Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/hazmat/primitives/symmetric-encryption.rst
Expand Up @@ -399,7 +399,8 @@ Modes
this is ``16``, meaning tag truncation is not allowed. Allowing tag
truncation is strongly discouraged for most applications.

:raises ValueError: This is raised if ``len(tag) < min_tag_length``.
:raises ValueError: This is raised if ``len(tag) < min_tag_length`` or the
``initialization_vector`` is too short.

:raises NotImplementedError: This is raised if the version of the OpenSSL
backend used is 1.0.1 or earlier.
Expand Down
2 changes: 2 additions & 0 deletions src/cryptography/hazmat/primitives/ciphers/modes.py
Expand Up @@ -208,6 +208,8 @@ def __init__(self, initialization_vector, tag=None, min_tag_length=16):
# for it
if not isinstance(initialization_vector, bytes):
raise TypeError("initialization_vector must be bytes")
if len(initialization_vector) == 0:
raise ValueError("initialization_vector must be at least 1 byte")
self._initialization_vector = initialization_vector
if tag is not None:
if not isinstance(tag, bytes):
Expand Down
4 changes: 4 additions & 0 deletions tests/hazmat/primitives/test_block.py
Expand Up @@ -191,6 +191,10 @@ def test_ctr(self, backend):
backend,
)

def test_gcm(self):
with pytest.raises(ValueError):
modes.GCM(b"")


class TestModesRequireBytes(object):
def test_cbc(self):
Expand Down