Skip to content

Commit

Permalink
fixes #10958 -- support aes-siv with empty plaintext on latest openssl
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Feb 26, 2025
1 parent 90c5b33 commit 61a961e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/rust/src/backend/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ impl AesSiv {
let data_bytes = data.as_bytes();
let aad = associated_data.map(Aad::List);

#[cfg(not(CRYPTOGRAPHY_OPENSSL_350_OR_GREATER))]
if data_bytes.is_empty() {
return Err(CryptographyError::from(
pyo3::exceptions::PyValueError::new_err("data must not be zero length"),
Expand Down
14 changes: 11 additions & 3 deletions tests/hazmat/primitives/test_aead.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,12 +735,20 @@ def test_data_too_large(self):
with pytest.raises(OverflowError):
aessiv.decrypt(b"very very irrelevant", [large_data])

def test_no_empty_encryption(self):
def test_empty(self):
key = AESSIV.generate_key(256)
aessiv = AESSIV(key)

with pytest.raises(ValueError):
aessiv.encrypt(b"", None)
if rust_openssl.CRYPTOGRAPHY_OPENSSL_350_OR_GREATER:
assert (
AESSIV(
b"+'\xe4)\xfbl\x02g\x8eX\x9c\xccD7\xc5\xad\xfbD\xb31\xabm!\xea2\x17'\xe6\xec\x03\xd3T"
).encrypt(b"", None)
== b"\xb2\xb25N7$\xdc\xda\xa8^\xcf\x02\x9bI\xa9\x0c"
)
else:
with pytest.raises(ValueError):
aessiv.encrypt(b"", None)

with pytest.raises(InvalidTag):
aessiv.decrypt(b"", None)
Expand Down

0 comments on commit 61a961e

Please sign in to comment.