[crypto] Add concept of cipher alignment size

The GCM cipher mode of operation (in common with other counter-based
modes of operation) has a notion of blocksize that does not neatly
fall into our current abstraction: it does operate in 16-byte blocks
but allows for an arbitrary overall data length (i.e. the final block
may be incomplete).

Model this by adding a concept of alignment size.  Each call to
encrypt() or decrypt() must begin at a multiple of the alignment size
from the start of the data stream.  This allows us to model GCM by
using a block size of 1 byte and an alignment size of 16 bytes.

As a side benefit, this same concept allows us to neatly model the
fact that raw AES can encrypt only a single 16-byte block, by
specifying an alignment size of zero on this cipher.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2022-10-28 16:27:10 +01:00
parent d1bc872a2e
commit 30243ad739
8 changed files with 33 additions and 1 deletions

View File

@@ -131,8 +131,18 @@ void cipher_decrypt_okx ( struct cipher_test *test, const char *file,
*/
void cipher_okx ( struct cipher_test *test, const char *file,
unsigned int line ) {
struct cipher_algorithm *cipher = test->cipher;
size_t len = test->len;
/* Sanity checks */
okx ( cipher->blocksize != 0, file, line );
okx ( ( len % cipher->blocksize ) == 0, file, line );
okx ( ( cipher->alignsize % cipher->blocksize ) == 0, file, line );
/* Report encryption test result */
cipher_encrypt_okx ( test, file, line );
/* Report decryption test result */
cipher_decrypt_okx ( test, file, line );
}