Added NIST CMAC to the CryptoAPI library
Subsystems (4)
PATCH 1/1 Added NIST CMAC to the CryptoAPI library
This patch adds NIST CMAC cipher based MAC as described in FIPS 800-38B to the CryptoAPI stack. It also wires up the MAC to the IPsec stack as per RFC 4494.
This patch was tested against 3.7.0-rc6 with third party hardware IPsec.
Signed-off-by Tom St Denis <[email protected]>
--- crypto/Kconfig | 8 ++ crypto/Makefile | 1 + crypto/cmac.c | 313 ++++++++++++++++++++++++++++++++++++++++++ crypto/testmgr.c | 9 ++ crypto/testmgr.h | 40 ++++++ include/uapi/linux/pfkeyv2.h | 1 + net/xfrm/xfrm_algo.c | 17 +++ 7 files changed, 389 insertions(+) create mode 100644 crypto/cmac.c
crypto/Kconfig +8 -0
@@ -301,6 +301,14 @@ config CRYPTO_XCBC http://csrc.nist.gov/encryption/modes/proposedmodes/ xcbc-mac/xcbc-mac-spec.pdf +config CRYPTO_CMAC + tristate "CMAC support" + depends on EXPERIMENTAL + select CRYPTO_HASH + select CRYPTO_MANAGER + help + NIST CMAC cipher based MAC + config CRYPTO_VMAC tristate "VMAC support" depends on EXPERIMENTAL
crypto/Makefile +1 -0
@@ -35,6 +35,7 @@ obj-$(CONFIG_CRYPTO_USER) += crypto_user.o obj-$(CONFIG_CRYPTO_HMAC) += hmac.o obj-$(CONFIG_CRYPTO_VMAC) += vmac.o obj-$(CONFIG_CRYPTO_XCBC) += xcbc.o +obj-$(CONFIG_CRYPTO_CMAC) += cmac.o obj-$(CONFIG_CRYPTO_NULL) += crypto_null.o obj-$(CONFIG_CRYPTO_MD4) += md4.o obj-$(CONFIG_CRYPTO_MD5) += md5.o
crypto/cmac.c new file +313 -0
313 lines not on this page · raw message
crypto/testmgr.c +9 -0
@@ -3139,6 +3139,15 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { + .alg = "cmac(aes)", + .test = alg_test_hash, + .suite = { + .hash = { + .vecs = aes_cmac128_tv_template, + .count = CMAC_AES_TEST_VECTORS + } + } + }, { .alg = "xcbc(aes)", .test = alg_test_hash, .suite = {
crypto/testmgr.h +40 -0
@@ -1639,6 +1639,46 @@ static struct hash_testvec hmac_sha256_tv_template[] = { }, }; +#define CMAC_AES_TEST_VECTORS 4 + +static struct hash_testvec aes_cmac128_tv_template[] = { + { + .key ="\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c" , + .plaintext = zeroed_string, + .digest ="\xbb\x1d\x69\x29\xe9\x59\x37\x28\x7f\xa3\x7d\x12\x9b\x75\x67\x46" , + .psize =0 , + .ksize =16 , + }, + + { + .key ="\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c" , + .plaintext ="\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a" , + .digest ="\x07\x0a\x16\xb4\x6b\x4d\x41\x44\xf7\x9b\xdd\x9d\xd0\x4a\x28\x7c" + .psize =16 , + .ksize =16 , + }, + { + .key ="\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c" , + .plaintext ="\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17" +"\x2a\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf" +"\x8e\x51\x30\xc8\x1c\x46\xa3\x5c\xe4\x11" , + .digest ="\xdf\xa6\x67\x47de\x9a\xe6\x30\x30\xca\x32\x61\x14\x97\xc8\x27" , + .psize =40 , + .ksize =16 , + }, + { + .key ="\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c" , + .plaintext ="\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17" +"\x2a\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf" +"\x8e\x51\x30\xc8\x1c\x46\xa3\x5c\xe4\x11\xe5\xfb\xc1\x19\x1a" +"\x0a\x52\xef\xf6\x9f\x24\x45\xdf\x4f\x9b\x17\xad\x2b\x41\x7b" +"\xe6\x6c\x37\x10" , + .digest ="\x51\xf0\xbe\xbf\x7e\x3b\x9d\x92\xfc\x49\x74\x17\x79\x36\x3c\xfe" , + .psize =64 , + .ksize =16 , + }, +} +#define XCBC_AES_TEST_VECTORS 6static struct hash_testvec aes_xcbc128_tv_template[] = {
include/uapi/linux/pfkeyv2.h +1 -0
@@ -296,6 +296,7 @@ struct sadb_x_kmaddress {#define SADB_X_AALG_SHA2_512HMAC 7#define SADB_X_AALG_RIPEMD160HMAC 8#define SADB_X_AALG_AES_XCBC_MAC 9 +#define SADB_X_AALG_AES_CMAC_MAC 10#define SADB_X_AALG_NULL 251/* kame */ #define SADB_AALG_MAX 251
net/xfrm/xfrm_algo.c +17 -0
@@ -265,6 +265,23 @@ static struct xfrm_algo_desc aalg_list[] = { } }, { + .name = "cmac(aes)", + + .uinfo = { + .auth = { + .icv_truncbits = 96, + .icv_fullbits = 128, + } + }, + + .desc = { + .sadb_alg_id = SADB_X_AALG_AES_CMAC_MAC, + .sadb_alg_ivlen = 0, + .sadb_alg_minbits = 128, + .sadb_alg_maxbits = 128 + } +}, +{ .name = "xcbc(aes)", .uinfo = {
Signature · 1 line
1.7.10.4