diff options
author | Michael Brown <mcb30@ipxe.org> | 2022-10-24 18:49:43 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2022-10-25 13:21:30 +0100 |
commit | 0c383bf00afbef1a9cfe02829d1bc6ee46e1c16b (patch) | |
tree | ac5e0bca148bd881a6e01fdb55591d5fb8ba9447 /src/tests/cipher_test.c | |
parent | 8e478e648fb68ac6f07e4e5cd80a5c1fefcb1cf5 (diff) | |
download | ipxe-0c383bf00afbef1a9cfe02829d1bc6ee46e1c16b.tar.gz |
[crypto] Add concept of additional data to cipher algorithms
Some ciphers (such as GCM) support the concept of additional
authenticated data, which does not appear in the ciphertext but may
affect the operation of the cipher.
Allow cipher_encrypt() and cipher_decrypt() to be called with a NULL
destination buffer in order to pass additional data.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/tests/cipher_test.c')
-rw-r--r-- | src/tests/cipher_test.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/tests/cipher_test.c b/src/tests/cipher_test.c index 5361502ff..c49b4b69b 100644 --- a/src/tests/cipher_test.c +++ b/src/tests/cipher_test.c @@ -63,6 +63,12 @@ void cipher_encrypt_okx ( struct cipher_test *test, const char *file, file, line ); cipher_setiv ( cipher, ctx, test->iv, test->iv_len ); + /* Process additional data, if applicable */ + if ( test->additional_len ) { + cipher_encrypt ( cipher, ctx, test->additional, NULL, + test->additional_len ); + } + /* Perform encryption */ cipher_encrypt ( cipher, ctx, test->plaintext, ciphertext, len ); @@ -89,7 +95,13 @@ void cipher_decrypt_okx ( struct cipher_test *test, const char *file, file, line ); cipher_setiv ( cipher, ctx, test->iv, test->iv_len ); - /* Perform encryption */ + /* Process additional data, if applicable */ + if ( test->additional_len ) { + cipher_decrypt ( cipher, ctx, test->additional, NULL, + test->additional_len ); + } + + /* Perform decryption */ cipher_decrypt ( cipher, ctx, test->ciphertext, plaintext, len ); /* Compare against expected plaintext */ |