lib/crypto/tests/aes_cbc_macs_kunit.c
Source file repositories/reference/linux-study-clean/lib/crypto/tests/aes_cbc_macs_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
lib/crypto/tests/aes_cbc_macs_kunit.c- Extension
.c- Size
- 6863 bytes
- Lines
- 229
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/aes-cbc-macs.haes-cmac-testvecs.hhash-test-template.h
Detected Declarations
function aes_cmac_init_withtestkeyfunction aes_cmac_withtestkeyfunction aes_cbc_macs_suite_initfunction aes_cbc_macs_suite_exitfunction test_aes_cmac_rfc4493function test_aes_xcbcmac_rfc3566function test_aes_cbcmac_rfc3610
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright 2026 Google LLC
*/
#include <crypto/aes-cbc-macs.h>
#include "aes-cmac-testvecs.h"
/*
* A fixed key used when presenting AES-CMAC as an unkeyed hash function in
* order to reuse hash-test-template.h. At the beginning of the test suite,
* this is initialized to a key prepared from bytes generated from a fixed seed.
*/
static struct aes_cmac_key test_key;
static void aes_cmac_init_withtestkey(struct aes_cmac_ctx *ctx)
{
aes_cmac_init(ctx, &test_key);
}
static void aes_cmac_withtestkey(const u8 *data, size_t data_len,
u8 out[AES_BLOCK_SIZE])
{
aes_cmac(&test_key, data, data_len, out);
}
#define HASH aes_cmac_withtestkey
#define HASH_CTX aes_cmac_ctx
#define HASH_SIZE AES_BLOCK_SIZE
#define HASH_INIT aes_cmac_init_withtestkey
#define HASH_UPDATE aes_cmac_update
#define HASH_FINAL aes_cmac_final
#include "hash-test-template.h"
static int aes_cbc_macs_suite_init(struct kunit_suite *suite)
{
u8 raw_key[AES_KEYSIZE_256];
int err;
rand_bytes_seeded_from_len(raw_key, sizeof(raw_key));
err = aes_cmac_preparekey(&test_key, raw_key, sizeof(raw_key));
if (err)
return err;
return hash_suite_init(suite);
}
static void aes_cbc_macs_suite_exit(struct kunit_suite *suite)
{
hash_suite_exit(suite);
}
/* Verify compatibility of the AES-CMAC implementation with RFC 4493. */
static void test_aes_cmac_rfc4493(struct kunit *test)
{
static const u8 raw_key[AES_KEYSIZE_128] = {
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
};
static const struct {
size_t data_len;
const u8 data[40];
const u8 mac[AES_BLOCK_SIZE];
} testvecs[] = {
{
/* Example 1 from RFC 4493 */
.data_len = 0,
.mac = {
0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46,
},
},
{
/* Example 2 from RFC 4493 */
.data = {
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
},
.data_len = 16,
.mac = {
0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c,
},
},
{
/* Example 3 from RFC 4493 */
.data = {
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
Annotation
- Immediate include surface: `crypto/aes-cbc-macs.h`, `aes-cmac-testvecs.h`, `hash-test-template.h`.
- Detected declarations: `function aes_cmac_init_withtestkey`, `function aes_cmac_withtestkey`, `function aes_cbc_macs_suite_init`, `function aes_cbc_macs_suite_exit`, `function test_aes_cmac_rfc4493`, `function test_aes_xcbcmac_rfc3566`, `function test_aes_cbcmac_rfc3610`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.