aboutsummaryrefslogtreecommitdiff
path: root/src/include/ipxe/cbc.h
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2022-10-24 16:52:24 +0100
committerMichael Brown <mcb30@ipxe.org>2022-10-25 13:21:28 +0100
commit8e478e648fb68ac6f07e4e5cd80a5c1fefcb1cf5 (patch)
tree59d27d4c71ed6c92b24d7fd6e007ed16e6379399 /src/include/ipxe/cbc.h
parent52f72d298abd81a6102ddddf2fff4918e4b077ce (diff)
downloadipxe-8e478e648fb68ac6f07e4e5cd80a5c1fefcb1cf5.zip
ipxe-8e478e648fb68ac6f07e4e5cd80a5c1fefcb1cf5.tar.gz
ipxe-8e478e648fb68ac6f07e4e5cd80a5c1fefcb1cf5.tar.bz2
[crypto] Allow initialisation vector length to vary from cipher blocksize
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/cbc.h')
-rw-r--r--src/include/ipxe/cbc.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/include/ipxe/cbc.h b/src/include/ipxe/cbc.h
index 18a94e1..5c87403 100644
--- a/src/include/ipxe/cbc.h
+++ b/src/include/ipxe/cbc.h
@@ -33,12 +33,15 @@ static inline int cbc_setkey ( void *ctx, const void *key, size_t keylen,
*
* @v ctx Context
* @v iv Initialisation vector
+ * @v ivlen Initialisation vector length
* @v raw_cipher Underlying cipher algorithm
* @v cbc_ctx CBC context
*/
-static inline void cbc_setiv ( void *ctx __unused, const void *iv,
+static inline void cbc_setiv ( void *ctx __unused,
+ const void *iv, size_t ivlen,
struct cipher_algorithm *raw_cipher,
void *cbc_ctx ) {
+ assert ( ivlen == raw_cipher->blocksize );
memcpy ( cbc_ctx, iv, raw_cipher->blocksize );
}
@@ -70,9 +73,10 @@ static int _cbc_name ## _setkey ( void *ctx, const void *key, \
return cbc_setkey ( &_cbc_name ## _ctx->raw_ctx, key, keylen, \
&_raw_cipher, &_cbc_name ## _ctx->cbc_ctx );\
} \
-static void _cbc_name ## _setiv ( void *ctx, const void *iv ) { \
+static void _cbc_name ## _setiv ( void *ctx, const void *iv, \
+ size_t ivlen ) { \
struct _cbc_name ## _context * _cbc_name ## _ctx = ctx; \
- cbc_setiv ( &_cbc_name ## _ctx->raw_ctx, iv, \
+ cbc_setiv ( &_cbc_name ## _ctx->raw_ctx, iv, ivlen, \
&_raw_cipher, &aes_cbc_ctx->cbc_ctx ); \
} \
static void _cbc_name ## _encrypt ( void *ctx, const void *src, \