diff options
| author | Michael Brown | 2022-10-28 17:27:10 +0200 |
|---|---|---|
| committer | Michael Brown | 2022-11-07 12:19:48 +0100 |
| commit | 30243ad73957a2e1cc4aedc3f23be66cdf399f00 (patch) | |
| tree | c0b476b76fed7f2a9c5a3b9ec1ea03f01017a693 /src/include/ipxe/crypto.h | |
| parent | [tls] Formalise notions of fixed and record initialisation vectors (diff) | |
| download | ipxe-30243ad73957a2e1cc4aedc3f23be66cdf399f00.tar.gz ipxe-30243ad73957a2e1cc4aedc3f23be66cdf399f00.tar.xz ipxe-30243ad73957a2e1cc4aedc3f23be66cdf399f00.zip | |
[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>
Diffstat (limited to 'src/include/ipxe/crypto.h')
| -rw-r--r-- | src/include/ipxe/crypto.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/include/ipxe/crypto.h b/src/include/ipxe/crypto.h index 842f2f633..ba09c9468 100644 --- a/src/include/ipxe/crypto.h +++ b/src/include/ipxe/crypto.h @@ -51,8 +51,24 @@ struct cipher_algorithm { const char *name; /** Context size */ size_t ctxsize; - /** Block size */ + /** Block size + * + * Every call to encrypt() or decrypt() must be for a multiple + * of this size. + */ size_t blocksize; + /** Alignment size + * + * Every call to encrypt() or decrypt() must begin at a + * multiple of this offset from the start of the stream. + * (Equivalently: all but the last call to encrypt() or + * decrypt() must be for a multiple of this size.) + * + * For ciphers supporting additional data, the main data + * stream and additional data stream are both considered to + * begin at offset zero. + */ + size_t alignsize; /** Authentication tag size */ size_t authsize; /** Set key |
