[PATCH 17/33] lib/crypto: aes: Remove aes_cbcmac_* functions

From: Eric Biggers

Date: Tue Jul 07 2026 - 01:40:24 EST


The aes_cbcmac_* functions are no longer used, except by their KUnit
test, since their functionality was folded directly into the AES-CCM
library code. Remove them.

Note that the aes_cmac_* and aes_xcbcmac_* functions remain unchanged.

Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
---
include/crypto/aes-cbc-macs.h | 22 +--------
lib/crypto/aes.c | 43 -----------------
lib/crypto/tests/aes_cbc_macs_kunit.c | 68 +--------------------------
3 files changed, 2 insertions(+), 131 deletions(-)

diff --git a/include/crypto/aes-cbc-macs.h b/include/crypto/aes-cbc-macs.h
index e61df108b926..95bbb8603420 100644
--- a/include/crypto/aes-cbc-macs.h
+++ b/include/crypto/aes-cbc-macs.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
- * Support for AES-CMAC, AES-XCBC-MAC, and AES-CBC-MAC
+ * Support for AES-CMAC and AES-XCBC-MAC
*
* Copyright 2026 Google LLC
*/
@@ -131,24 +131,4 @@ static inline void aes_cmac(const struct aes_cmac_key *key, const u8 *data,
aes_cmac_final(&ctx, out);
}

-/*
- * AES-CBC-MAC support. This is provided only for use by the implementation of
- * AES-CCM. It should have no other users. Warning: unlike AES-CMAC and
- * AES-XCBC-MAC, AES-CBC-MAC isn't a secure MAC for variable-length messages.
- */
-struct aes_cbcmac_ctx {
- const struct aes_enckey *key;
- size_t partial_len;
- u8 h[AES_BLOCK_SIZE];
-};
-static inline void aes_cbcmac_init(struct aes_cbcmac_ctx *ctx,
- const struct aes_enckey *key)
-{
- *ctx = (struct aes_cbcmac_ctx){ .key = key };
-}
-void aes_cbcmac_update(struct aes_cbcmac_ctx *ctx, const u8 *data,
- size_t data_len);
-void aes_cbcmac_final(struct aes_cbcmac_ctx *ctx,
- u8 out[at_least AES_BLOCK_SIZE]);
-
#endif /* _CRYPTO_AES_CBC_MACS_H */
diff --git a/lib/crypto/aes.c b/lib/crypto/aes.c
index 1a1b32e41ac1..aeefd55eacaa 100644
--- a/lib/crypto/aes.c
+++ b/lib/crypto/aes.c
@@ -674,49 +674,6 @@ void aes_cmac_final(struct aes_cmac_ctx *ctx, u8 out[AES_BLOCK_SIZE])
}
EXPORT_SYMBOL_GPL(aes_cmac_final);

-void aes_cbcmac_update(struct aes_cbcmac_ctx *ctx, const u8 *data,
- size_t data_len)
-{
- bool enc_before = false;
- size_t nblocks;
-
- if (ctx->partial_len) {
- size_t l = min(data_len, AES_BLOCK_SIZE - ctx->partial_len);
-
- crypto_xor(&ctx->h[ctx->partial_len], data, l);
- data += l;
- data_len -= l;
- ctx->partial_len += l;
- if (ctx->partial_len < AES_BLOCK_SIZE)
- return;
- enc_before = true;
- }
-
- nblocks = data_len / AES_BLOCK_SIZE;
- data_len %= AES_BLOCK_SIZE;
- if (nblocks == 0) {
- if (enc_before)
- aes_encrypt(ctx->key, ctx->h, ctx->h);
- } else {
- aes_cbcmac_blocks(ctx->h, ctx->key, data, nblocks, enc_before,
- /* enc_after= */ true);
- data += nblocks * AES_BLOCK_SIZE;
- }
- crypto_xor(ctx->h, data, data_len);
- ctx->partial_len = data_len;
-}
-EXPORT_SYMBOL_NS_GPL(aes_cbcmac_update, "CRYPTO_INTERNAL");
-
-void aes_cbcmac_final(struct aes_cbcmac_ctx *ctx, u8 out[AES_BLOCK_SIZE])
-{
- if (ctx->partial_len)
- aes_encrypt(ctx->key, out, ctx->h);
- else
- memcpy(out, ctx->h, AES_BLOCK_SIZE);
- memzero_explicit(ctx, sizeof(*ctx));
-}
-EXPORT_SYMBOL_NS_GPL(aes_cbcmac_final, "CRYPTO_INTERNAL");
-
/*
* FIPS cryptographic algorithm self-test for AES-CMAC. As per the FIPS 140-3
* Implementation Guidance, a cryptographic algorithm self-test for at least one
diff --git a/lib/crypto/tests/aes_cbc_macs_kunit.c b/lib/crypto/tests/aes_cbc_macs_kunit.c
index ae3745212f03..97a4594895c2 100644
--- a/lib/crypto/tests/aes_cbc_macs_kunit.c
+++ b/lib/crypto/tests/aes_cbc_macs_kunit.c
@@ -141,75 +141,10 @@ static void test_aes_xcbcmac_rfc3566(struct kunit *test)
KUNIT_ASSERT_MEMEQ(test, actual_mac, expected_mac, AES_BLOCK_SIZE);
}

-static void test_aes_cbcmac_rfc3610(struct kunit *test)
-{
- /*
- * The following AES-CBC-MAC test vector is extracted from RFC 3610
- * Packet Vector #11. It required some rearrangement to get the actual
- * input to AES-CBC-MAC from the values given.
- */
- static const u8 raw_key[AES_KEYSIZE_128] = {
- 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
- 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
- };
- const size_t unpadded_data_len = 52;
- static const u8 data[64] = {
- /* clang-format off */
- /* CCM header */
- 0x61, 0x00, 0x00, 0x00, 0x0d, 0x0c, 0x0b, 0x0a,
- 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0x00, 0x14,
- /* CCM additional authentication blocks */
- 0x00, 0x0c, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
- 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x00, 0x00,
- /* CCM message blocks */
- 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
- 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
- 0x1c, 0x1d, 0x1e, 0x1f, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- /* clang-format on */
- };
- static const u8 expected_mac[AES_BLOCK_SIZE] = {
- 0x6b, 0x5e, 0x24, 0x34, 0x12, 0xcc, 0xc2, 0xad,
- 0x6f, 0x1b, 0x11, 0xc3, 0xa1, 0xa9, 0xd8, 0xbc,
- };
- struct aes_enckey key;
- struct aes_cbcmac_ctx ctx;
- u8 actual_mac[AES_BLOCK_SIZE];
- int err;
-
- err = aes_prepareenckey(&key, raw_key, sizeof(raw_key));
- KUNIT_ASSERT_EQ(test, err, 0);
-
- /*
- * Trailing zeroes should not affect the CBC-MAC value, up to the next
- * AES block boundary.
- */
- for (size_t data_len = unpadded_data_len; data_len <= sizeof(data);
- data_len++) {
- aes_cbcmac_init(&ctx, &key);
- aes_cbcmac_update(&ctx, data, data_len);
- aes_cbcmac_final(&ctx, actual_mac);
- KUNIT_ASSERT_MEMEQ(test, actual_mac, expected_mac,
- AES_BLOCK_SIZE);
-
- /* Incremental computations should produce the same result. */
- for (size_t part1_len = 0; part1_len <= data_len; part1_len++) {
- aes_cbcmac_init(&ctx, &key);
- aes_cbcmac_update(&ctx, data, part1_len);
- aes_cbcmac_update(&ctx, &data[part1_len],
- data_len - part1_len);
- aes_cbcmac_final(&ctx, actual_mac);
- KUNIT_ASSERT_MEMEQ(test, actual_mac, expected_mac,
- AES_BLOCK_SIZE);
- }
- }
-}
-
static struct kunit_case aes_cbc_macs_test_cases[] = {
HASH_KUNIT_CASES,
KUNIT_CASE(test_aes_cmac_rfc4493),
KUNIT_CASE(test_aes_xcbcmac_rfc3566),
- KUNIT_CASE(test_aes_cbcmac_rfc3610),
KUNIT_CASE(benchmark_hash),
{},
};
@@ -222,7 +157,6 @@ static struct kunit_suite aes_cbc_macs_test_suite = {
};
kunit_test_suite(aes_cbc_macs_test_suite);

-MODULE_DESCRIPTION(
- "KUnit tests and benchmark for AES-CMAC, AES-XCBC-MAC, and AES-CBC-MAC");
+MODULE_DESCRIPTION("KUnit tests and benchmark for AES-CMAC and AES-XCBC-MAC");
MODULE_IMPORT_NS("CRYPTO_INTERNAL");
MODULE_LICENSE("GPL");
--
2.54.0