[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>
This commit is contained in:
+13
-1
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user