mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-04-04 11:36:06 +02:00
Add tests covering skipped update() or update_ad()
for empty plaintext/ciphertext and empty auth data.
Test vector for P=0, A=0 generated using python's
cryptography.hazmat library.
Python script used for test vector generation:
```
import os
from cryptography.hazmat.primitives.ciphers.aead import AESCCM
def encrypt(key, iv, plaintext, associated_data):
key = bytes.fromhex(key)
iv = bytes.fromhex(iv)
plaintext = bytes.fromhex(plaintext)
associated_data = bytes.fromhex(associated_data)
aesccm = AESCCM(key)
ct = aesccm.encrypt(iv, plaintext, associated_data)
return ct.hex()
def decrypt(key, associated_data, iv, ciphertext):
key = bytes.fromhex(key)
associated_data = bytes.fromhex(associated_data)
iv = bytes.fromhex(iv)
ciphertext = bytes.fromhex(ciphertext)
aesccm = AESCCM(key)
pt = aesccm.decrypt(iv, ciphertext, associated_data)
return pt.hex()
key = "54caf96ef6d448734700aadab50faf7a"
plaintext = ""
iv = "a3803e752ae849c910d8da36af"
aad = ""
encrypted = encrypt(key, iv, plaintext, aad)
print(f"key: {key}")
print(f"iv: {iv}")
print(f"encrypted: {encrypted}")
print("--------------------------------------")
decrypted = decrypt(
key,
aad,
iv,
encrypted
)
print(f"decrypted: {decrypted}")
```
Results:
```
key: 54caf96ef6d448734700aadab50faf7a
iv: a3803e752ae849c910d8da36af
encrypted: eba8347baa6d61f87b67c2dd7c6d2053
--------------------------------------
decrypted:
```
Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>