Skip to contentSkip to conversation

crypto: aes - Add import_core/export_core to cmac/xcbc/cbcmac

PATCH In review Herbert Xu 4 participants 5 messages Oct 9 – Oct 15 Crypto API

lore
Share & tools
lore

Herbert Xu

author maintainer
#0 lore raw

PATCH 1/1 crypto: aes - Add import_core/export_core to cmac/xcbc/cbcmac

The export format for cmac-aes-lib, xcbc-aes-lib and cbcmac-aes-lib did not match that of the generic templates. Add custom export and import functions to align with the generic tempaltes.

For cmac and xcbc, perform an extra encryption on the withheld block for export_core so that the information isn't lost.

crypto/aes.c +126 -0
index 94791f481e98..a1af4d5a7608 100644
@@ -18,7 +18,10 @@
 #include <crypto/internal/hash.h>
 #include <crypto/internal/skcipher.h>
 #include <crypto/scatterwalk.h>
+#include <crypto/utils.h>
+#include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/string.h>
 
 static_assert(__alignof__(struct aes_key) <= CRYPTO_MINALIGN);
 static_assert(__alignof__(struct aes_enckey) <= CRYPTO_MINALIGN);
@@ -95,6 +98,71 @@ static int __maybe_unused crypto_aes_cmac_digest(struct shash_desc *desc,
 	return 0;
 }
 
+static int crypto_cmac_export_core(struct shash_desc *desc, void *out)
+{
+	struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+	struct aes_cmac_ctx ctx1;
+	u8 *h = ctx->h;
+
+	if (!ctx->partial_len)
+		;
+	else if (ctx->partial_len != AES_BLOCK_SIZE)
+		return -EINVAL;
+	else {
+		union {
+			long l;
+			char c;
+		} u = {};
+
+		BUILD_BUG_ON(sizeof(u) >= AES_BLOCK_SIZE);
+		ctx1 = *ctx;
+		aes_cmac_update(&ctx1, &u.c, sizeof(u));
+		h = ctx1.h;
+	}
+
+	memcpy(out, h, AES_BLOCK_SIZE);
+	memzero_explicit(&ctx1, sizeof(ctx1));
+	return 0;
+}
+
+static int crypto_cmac_import_core(struct shash_desc *desc, const void *in)
+{
+	struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+
+	ctx->key = AES_CMAC_KEY(desc->tfm);
+	memcpy(ctx->h, in, AES_BLOCK_SIZE);
+	ctx->partial_len = 0;
+	return 0;
+}
+
+static int crypto_cmac_export(struct shash_desc *desc, void *out)
+{
+	struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+	unsigned int partial = ctx->partial_len;
+	u8 *p = out;
+
+	memcpy(p, ctx->h, AES_BLOCK_SIZE);
+	memset(p + AES_BLOCK_SIZE, 0, AES_BLOCK_SIZE);
+	p[AES_BLOCK_SIZE * 2] = partial;
+	return 0;
+}
+
+static int crypto_cmac_import(struct shash_desc *desc, const void *in)
+{
+	struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+	unsigned int partial;
+	const u8 *p = in;
+
+	crypto_cmac_import_core(desc, p);
+	p += AES_BLOCK_SIZE;
+	partial = p[AES_BLOCK_SIZE];
+	if (partial > AES_BLOCK_SIZE)
+		return -EOVERFLOW;
+	crypto_xor(ctx->h, p, partial);
+	ctx->partial_len = partial;
+	return 0;
+}
+
 #define AES_CBCMAC_KEY(tfm) ((struct aes_enckey *)crypto_shash_ctx(tfm))
 #define AES_CBCMAC_CTX(desc) ((struct aes_cbcmac_ctx *)shash_desc_ctx(desc))
 
@@ -136,6 +204,49 @@ static int __maybe_unused crypto_aes_cbcmac_digest(struct shash_desc *desc,
 	return 0;
 }
 
+static int crypto_cbcmac_export_core(struct shash_desc *desc, void *out)
+{
+	memcpy(out, AES_CBCMAC_CTX(desc)->h, AES_BLOCK_SIZE);
+	return 0;
+}
+
+static int crypto_cbcmac_import_core(struct shash_desc *desc, const void *in)
+{
+	struct aes_cbcmac_ctx *ctx = AES_CBCMAC_CTX(desc);
+
+	ctx->key = AES_CBCMAC_KEY(desc->tfm);
+	memcpy(ctx->h, in, AES_BLOCK_SIZE);
+	ctx->partial_len = 0;
+	return 0;
+}
+
+static int crypto_cbcmac_export(struct shash_desc *desc, void *out)
+{
+	struct aes_cbcmac_ctx *ctx = AES_CBCMAC_CTX(desc);
+	unsigned int partial = ctx->partial_len;
+	u8 *p = out;
+
+	memset(p + AES_BLOCK_SIZE, 0, AES_BLOCK_SIZE);
+	p[AES_BLOCK_SIZE * 2] = partial;
+	return crypto_cbcmac_export_core(desc, p);
+}
+
+static int crypto_cbcmac_import(struct shash_desc *desc, const void *in)
+{
+	struct aes_cbcmac_ctx *ctx = AES_CBCMAC_CTX(desc);
+	unsigned int partial;
+	const u8 *p = in;
+
+	crypto_cbcmac_import_core(desc, p);
+	p += AES_BLOCK_SIZE;
+	partial = p[AES_BLOCK_SIZE];
+	if (partial > AES_BLOCK_SIZE)
+		return -EOVERFLOW;
+	crypto_xor(ctx->h, p, partial);
+	ctx->partial_len = partial;
+	return 0;
+}
+
 static struct crypto_alg alg = {
 	.cra_name = "aes",
 	.cra_driver_name = "aes-lib",
@@ -166,7 +277,12 @@ static struct shash_alg mac_algs[] = {
 		.update = crypto_aes_cmac_update,
 		.final = crypto_aes_cmac_final,
 		.digest = crypto_aes_cmac_digest,
+		.export	= crypto_cmac_export,
+		.import = crypto_cmac_import,
+		.export_core = crypto_cmac_export_core,
+		.import_core = crypto_cmac_import_core,
 		.descsize = sizeof(struct aes_cmac_ctx),
+		.statesize = AES_BLOCK_SIZE * 2 + 1,
 	},
 #endif
 #if IS_ENABLED(CONFIG_CRYPTO_XCBC)
@@ -187,7 +303,12 @@ static struct shash_alg mac_algs[] = {
 		.update = crypto_aes_cmac_update,
 		.final = crypto_aes_cmac_final,
 		.digest = crypto_aes_cmac_digest,
+		.export	= crypto_cmac_export,
+		.import = crypto_cmac_import,
+		.export_core = crypto_cmac_export_core,
+		.import_core = crypto_cmac_import_core,
 		.descsize = sizeof(struct aes_cmac_ctx),
+		.statesize = AES_BLOCK_SIZE * 2 + 1,
 	},
 #endif
 #if IS_ENABLED(CONFIG_CRYPTO_CCM)
@@ -204,7 +325,12 @@ static struct shash_alg mac_algs[] = {
 		.update = crypto_aes_cbcmac_update,
 		.final = crypto_aes_cbcmac_final,
 		.digest = crypto_aes_cbcmac_digest,
+		.export	= crypto_cbcmac_export,
+		.import = crypto_cbcmac_import,
+		.export_core = crypto_cbcmac_export_core,
+		.import_core = crypto_cbcmac_import_core,
 		.descsize = sizeof(struct aes_cbcmac_ctx),
+		.statesize = AES_BLOCK_SIZE * 2 + 1,
 	},
 #endif
 };
Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#1 lore raw
kernel test robot noticed the following build warnings:

Hi Herbert,

kernel test robot noticed the following build warnings:

[auto build test WARNING on herbert-cryptodev-2.6/master]
[also build test WARNING on herbert-crypto-2.6/master linus/master v7.3-rc6 next-20261008] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Herbert-Xu/crypto-aes-Add-import_core-export_core-to-cmac-xcbc-cbcmac/20261009-224555
base:   https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master
patch link:    https://lore.kernel.org/r/asjT87HAZ_UUbbvm%40gondor.apana.org.au
patch subject: [PATCH] crypto: aes - Add import_core/export_core to cmac/xcbc/cbcmac
config: sparc-defconfig (https://download.01.org/0day-ci/archive/20261010/[email protected]/config)
compiler: sparc-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261010/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> crypto/aes.c:234:12: warning: 'crypto_cbcmac_import' defined but not used [-Wunused-function]
     234 | static int crypto_cbcmac_import(struct shash_desc *desc, const void *in)
         |            ^~~~~~~~~~~~~~~~~~~~
>> crypto/aes.c:223:12: warning: 'crypto_cbcmac_export' defined but not used [-Wunused-function]

223 | static int crypto_cbcmac_export(struct shash_desc *desc, void *out)
| ^~~~~~~~~~~~~~~~~~~~

vim +/crypto_cbcmac_import +234 crypto/aes.c

222

 > 223	static int crypto_cbcmac_export(struct shash_desc *desc, void *out)
   224	{
   225		struct aes_cbcmac_ctx *ctx = AES_CBCMAC_CTX(desc);
   226		unsigned int partial = ctx->partial_len;
   227		u8 *p = out;
   228	
   229		memset(p + AES_BLOCK_SIZE, 0, AES_BLOCK_SIZE);
   230		p[AES_BLOCK_SIZE * 2] = partial;
   231		return crypto_cbcmac_export_core(desc, p);
   232	}
   233	
 > 234	static int crypto_cbcmac_import(struct shash_desc *desc, const void *in)

235 {
236 struct aes_cbcmac_ctx *ctx = AES_CBCMAC_CTX(desc);
237 unsigned int partial;
238 const u8 *p = in;
239
240 crypto_cbcmac_import_core(desc, p);
241 p += AES_BLOCK_SIZE;
242 partial = p[AES_BLOCK_SIZE];
243 if (partial > AES_BLOCK_SIZE)
244 return -EOVERFLOW;
245 crypto_xor(ctx->h, p, partial);
246 ctx->partial_len = partial;
247 return 0;
248 }
249

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#2 lore raw
In reply to Herbert Xu

Hi Herbert,
I tested your patch with the SPAcc driver, all cmac(aes)/xcbc(aes)
tests pass.

Warm regards,
PK
Vayavya Labs Pvt. Ltd.

Quoted 191 lines · Herbert Xu

The export format for cmac-aes-lib, xcbc-aes-lib and cbcmac-aes-lib did not match that of the generic templates. Add custom export and import functions to align with the generic tempaltes.

For cmac and xcbc, perform an extra encryption on the withheld block for export_core so that the information isn't lost.

crypto/aes.c +126 -1
index 94791f481e98..a1af4d5a7608 100644
@@ -18,7 +18,10 @@
 #include <crypto/internal/hash.h>
 #include <crypto/internal/skcipher.h>
 #include <crypto/scatterwalk.h>
+#include <crypto/utils.h>
+#include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/string.h>
 
 static_assert(__alignof__(struct aes_key) <= CRYPTO_MINALIGN);
 static_assert(__alignof__(struct aes_enckey) <= CRYPTO_MINALIGN);
@@ -95,6 +98,71 @@ static int __maybe_unused crypto_aes_cmac_digest(struct shash_desc *desc,
        return 0;
 }
 
+static int crypto_cmac_export_core(struct shash_desc *desc, void *out)
+{
+       struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+       struct aes_cmac_ctx ctx1;
+       u8 *h = ctx->h;
+
+       if (!ctx->partial_len)
+               ;
+       else if (ctx->partial_len != AES_BLOCK_SIZE)
+               return -EINVAL;
+       else {
+               union {
+                       long l;
+                       char c;
+               } u = {};
+
+               BUILD_BUG_ON(sizeof(u) >= AES_BLOCK_SIZE);
+               ctx1 = *ctx;
+               aes_cmac_update(&ctx1, &u.c, sizeof(u));
+               h = ctx1.h;
+       }
+
+       memcpy(out, h, AES_BLOCK_SIZE);
+       memzero_explicit(&ctx1, sizeof(ctx1));
+       return 0;
+}
+
+static int crypto_cmac_import_core(struct shash_desc *desc, const void *in)
+{
+       struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+
+       ctx->key = AES_CMAC_KEY(desc->tfm);
+       memcpy(ctx->h, in, AES_BLOCK_SIZE);
+       ctx->partial_len = 0;
+       return 0;
+}
+
+static int crypto_cmac_export(struct shash_desc *desc, void *out)
+{
+       struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+       unsigned int partial = ctx->partial_len;
+       u8 *p = out;
+
+       memcpy(p, ctx->h, AES_BLOCK_SIZE);
+       memset(p + AES_BLOCK_SIZE, 0, AES_BLOCK_SIZE);
+       p[AES_BLOCK_SIZE * 2] = partial;
+       return 0;
+}
+
+static int crypto_cmac_import(struct shash_desc *desc, const void *in)
+{
+       struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+       unsigned int partial;
+       const u8 *p = in;
+
+       crypto_cmac_import_core(desc, p);
+       p += AES_BLOCK_SIZE;
+       partial = p[AES_BLOCK_SIZE];
+       if (partial > AES_BLOCK_SIZE)
+               return -EOVERFLOW;
+       crypto_xor(ctx->h, p, partial);
+       ctx->partial_len = partial;
+       return 0;
+}
+
 #define AES_CBCMAC_KEY(tfm) ((struct aes_enckey *)crypto_shash_ctx(tfm))
 #define AES_CBCMAC_CTX(desc) ((struct aes_cbcmac_ctx *)shash_desc_ctx(desc))
 
@@ -136,6 +204,49 @@ static int __maybe_unused crypto_aes_cbcmac_digest(struct shash_desc *desc,
        return 0;
 }
 
+static int crypto_cbcmac_export_core(struct shash_desc *desc, void *out)
+{
+       memcpy(out, AES_CBCMAC_CTX(desc)->h, AES_BLOCK_SIZE);
+       return 0;
+}
+
+static int crypto_cbcmac_import_core(struct shash_desc *desc, const void *in)
+{
+       struct aes_cbcmac_ctx *ctx = AES_CBCMAC_CTX(desc);
+
+       ctx->key = AES_CBCMAC_KEY(desc->tfm);
+       memcpy(ctx->h, in, AES_BLOCK_SIZE);
+       ctx->partial_len = 0;
+       return 0;
+}
+
+static int crypto_cbcmac_export(struct shash_desc *desc, void *out)
+{
+       struct aes_cbcmac_ctx *ctx = AES_CBCMAC_CTX(desc);
+       unsigned int partial = ctx->partial_len;
+       u8 *p = out;
+
+       memset(p + AES_BLOCK_SIZE, 0, AES_BLOCK_SIZE);
+       p[AES_BLOCK_SIZE * 2] = partial;
+       return crypto_cbcmac_export_core(desc, p);
+}
+
+static int crypto_cbcmac_import(struct shash_desc *desc, const void *in)
+{
+       struct aes_cbcmac_ctx *ctx = AES_CBCMAC_CTX(desc);
+       unsigned int partial;
+       const u8 *p = in;
+
+       crypto_cbcmac_import_core(desc, p);
+       p += AES_BLOCK_SIZE;
+       partial = p[AES_BLOCK_SIZE];
+       if (partial > AES_BLOCK_SIZE)
+               return -EOVERFLOW;
+       crypto_xor(ctx->h, p, partial);
+       ctx->partial_len = partial;
+       return 0;
+}
+
 static struct crypto_alg alg = {
        .cra_name = "aes",
        .cra_driver_name = "aes-lib",
@@ -166,7 +277,12 @@ static struct shash_alg mac_algs[] = {
                .update = crypto_aes_cmac_update,
                .final = crypto_aes_cmac_final,
                .digest = crypto_aes_cmac_digest,
+               .export = crypto_cmac_export,
+               .import = crypto_cmac_import,
+               .export_core = crypto_cmac_export_core,
+               .import_core = crypto_cmac_import_core,
                .descsize = sizeof(struct aes_cmac_ctx),
+               .statesize = AES_BLOCK_SIZE * 2 + 1,
        },
 #endif
 #if IS_ENABLED(CONFIG_CRYPTO_XCBC)
@@ -187,7 +303,12 @@ static struct shash_alg mac_algs[] = {
                .update = crypto_aes_cmac_update,
                .final = crypto_aes_cmac_final,
                .digest = crypto_aes_cmac_digest,
+               .export = crypto_cmac_export,
+               .import = crypto_cmac_import,
+               .export_core = crypto_cmac_export_core,
+               .import_core = crypto_cmac_import_core,
                .descsize = sizeof(struct aes_cmac_ctx),
+               .statesize = AES_BLOCK_SIZE * 2 + 1,
        },
 #endif
 #if IS_ENABLED(CONFIG_CRYPTO_CCM)
@@ -204,7 +325,12 @@ static struct shash_alg mac_algs[] = {
                .update = crypto_aes_cbcmac_update,
                .final = crypto_aes_cbcmac_final,
                .digest = crypto_aes_cbcmac_digest,
+               .export = crypto_cbcmac_export,
+               .import = crypto_cbcmac_import,
+               .export_core = crypto_cbcmac_export_core,
+               .import_core = crypto_cbcmac_import_core,
                .descsize = sizeof(struct aes_cbcmac_ctx),
+               .statesize = AES_BLOCK_SIZE * 2 + 1,
        },
 #endif
 };
--

Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

#3 lore raw

Hi Herbert,
I applied this patch on top of cryptodev-2.6/master and ran the
crypto self-tests (CONFIG_CRYPTO_SELFTESTS=y, CONFIG_CRYPTO_SELFTESTS_FULL=y) with the SPAcc driver. cmac(aes) and xcbc(aes) now allocate their software fallback and pass all self-tests, with no regressions on the other SPAcc hash/HMAC algorithms.
I will push the SPAcc v26 patches. Please suggest otherwise.

Warm Regards,
PK
Vayavya Labs Pvt. Ltd.

Quoted 201 lines · Pavitrakumar Managutte

Hi Herbert,
I tested your patch with the SPAcc driver, all cmac(aes)/xcbc(aes)
tests pass.

Warm regards,
PK
Vayavya Labs Pvt. Ltd.

Quoted 191 lines · Herbert Xu

The export format for cmac-aes-lib, xcbc-aes-lib and cbcmac-aes-lib did not match that of the generic templates. Add custom export and import functions to align with the generic tempaltes.

For cmac and xcbc, perform an extra encryption on the withheld block for export_core so that the information isn't lost.

crypto/aes.c +126 -1
index 94791f481e98..a1af4d5a7608 100644
@@ -18,7 +18,10 @@
 #include <crypto/internal/hash.h>
 #include <crypto/internal/skcipher.h>
 #include <crypto/scatterwalk.h>
+#include <crypto/utils.h>
+#include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/string.h>
 
 static_assert(__alignof__(struct aes_key) <= CRYPTO_MINALIGN);
 static_assert(__alignof__(struct aes_enckey) <= CRYPTO_MINALIGN);
@@ -95,6 +98,71 @@ static int __maybe_unused crypto_aes_cmac_digest(struct shash_desc *desc,
        return 0;
 }
 
+static int crypto_cmac_export_core(struct shash_desc *desc, void *out)
+{
+       struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+       struct aes_cmac_ctx ctx1;
+       u8 *h = ctx->h;
+
+       if (!ctx->partial_len)
+               ;
+       else if (ctx->partial_len != AES_BLOCK_SIZE)
+               return -EINVAL;
+       else {
+               union {
+                       long l;
+                       char c;
+               } u = {};
+
+               BUILD_BUG_ON(sizeof(u) >= AES_BLOCK_SIZE);
+               ctx1 = *ctx;
+               aes_cmac_update(&ctx1, &u.c, sizeof(u));
+               h = ctx1.h;
+       }
+
+       memcpy(out, h, AES_BLOCK_SIZE);
+       memzero_explicit(&ctx1, sizeof(ctx1));
+       return 0;
+}
+
+static int crypto_cmac_import_core(struct shash_desc *desc, const void *in)
+{
+       struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+
+       ctx->key = AES_CMAC_KEY(desc->tfm);
+       memcpy(ctx->h, in, AES_BLOCK_SIZE);
+       ctx->partial_len = 0;
+       return 0;
+}
+
+static int crypto_cmac_export(struct shash_desc *desc, void *out)
+{
+       struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+       unsigned int partial = ctx->partial_len;
+       u8 *p = out;
+
+       memcpy(p, ctx->h, AES_BLOCK_SIZE);
+       memset(p + AES_BLOCK_SIZE, 0, AES_BLOCK_SIZE);
+       p[AES_BLOCK_SIZE * 2] = partial;
+       return 0;
+}
+
+static int crypto_cmac_import(struct shash_desc *desc, const void *in)
+{
+       struct aes_cmac_ctx *ctx = AES_CMAC_CTX(desc);
+       unsigned int partial;
+       const u8 *p = in;
+
+       crypto_cmac_import_core(desc, p);
+       p += AES_BLOCK_SIZE;
+       partial = p[AES_BLOCK_SIZE];
+       if (partial > AES_BLOCK_SIZE)
+               return -EOVERFLOW;
+       crypto_xor(ctx->h, p, partial);
+       ctx->partial_len = partial;
+       return 0;
+}
+
 #define AES_CBCMAC_KEY(tfm) ((struct aes_enckey *)crypto_shash_ctx(tfm))
 #define AES_CBCMAC_CTX(desc) ((struct aes_cbcmac_ctx *)shash_desc_ctx(desc))
 
@@ -136,6 +204,49 @@ static int __maybe_unused crypto_aes_cbcmac_digest(struct shash_desc *desc,
        return 0;
 }
 
+static int crypto_cbcmac_export_core(struct shash_desc *desc, void *out)
+{
+       memcpy(out, AES_CBCMAC_CTX(desc)->h, AES_BLOCK_SIZE);
+       return 0;
+}
+
+static int crypto_cbcmac_import_core(struct shash_desc *desc, const void *in)
+{
+       struct aes_cbcmac_ctx *ctx = AES_CBCMAC_CTX(desc);
+
+       ctx->key = AES_CBCMAC_KEY(desc->tfm);
+       memcpy(ctx->h, in, AES_BLOCK_SIZE);
+       ctx->partial_len = 0;
+       return 0;
+}
+
+static int crypto_cbcmac_export(struct shash_desc *desc, void *out)
+{
+       struct aes_cbcmac_ctx *ctx = AES_CBCMAC_CTX(desc);
+       unsigned int partial = ctx->partial_len;
+       u8 *p = out;
+
+       memset(p + AES_BLOCK_SIZE, 0, AES_BLOCK_SIZE);
+       p[AES_BLOCK_SIZE * 2] = partial;
+       return crypto_cbcmac_export_core(desc, p);
+}
+
+static int crypto_cbcmac_import(struct shash_desc *desc, const void *in)
+{
+       struct aes_cbcmac_ctx *ctx = AES_CBCMAC_CTX(desc);
+       unsigned int partial;
+       const u8 *p = in;
+
+       crypto_cbcmac_import_core(desc, p);
+       p += AES_BLOCK_SIZE;
+       partial = p[AES_BLOCK_SIZE];
+       if (partial > AES_BLOCK_SIZE)
+               return -EOVERFLOW;
+       crypto_xor(ctx->h, p, partial);
+       ctx->partial_len = partial;
+       return 0;
+}
+
 static struct crypto_alg alg = {
        .cra_name = "aes",
        .cra_driver_name = "aes-lib",
@@ -166,7 +277,12 @@ static struct shash_alg mac_algs[] = {
                .update = crypto_aes_cmac_update,
                .final = crypto_aes_cmac_final,
                .digest = crypto_aes_cmac_digest,
+               .export = crypto_cmac_export,
+               .import = crypto_cmac_import,
+               .export_core = crypto_cmac_export_core,
+               .import_core = crypto_cmac_import_core,
                .descsize = sizeof(struct aes_cmac_ctx),
+               .statesize = AES_BLOCK_SIZE * 2 + 1,
        },
 #endif
 #if IS_ENABLED(CONFIG_CRYPTO_XCBC)
@@ -187,7 +303,12 @@ static struct shash_alg mac_algs[] = {
                .update = crypto_aes_cmac_update,
                .final = crypto_aes_cmac_final,
                .digest = crypto_aes_cmac_digest,
+               .export = crypto_cmac_export,
+               .import = crypto_cmac_import,
+               .export_core = crypto_cmac_export_core,
+               .import_core = crypto_cmac_import_core,
                .descsize = sizeof(struct aes_cmac_ctx),
+               .statesize = AES_BLOCK_SIZE * 2 + 1,
        },
 #endif
 #if IS_ENABLED(CONFIG_CRYPTO_CCM)
@@ -204,7 +325,12 @@ static struct shash_alg mac_algs[] = {
                .update = crypto_aes_cbcmac_update,
                .final = crypto_aes_cbcmac_final,
                .digest = crypto_aes_cbcmac_digest,
+               .export = crypto_cbcmac_export,
+               .import = crypto_cbcmac_import,
+               .export_core = crypto_cbcmac_export_core,
+               .import_core = crypto_cbcmac_import_core,
                .descsize = sizeof(struct aes_cbcmac_ctx),
+               .statesize = AES_BLOCK_SIZE * 2 + 1,
        },
 #endif
 };
--

Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

#4 lore raw
Quoted 9 lines · Pavitrakumar Managutte

Hi Herbert,
I applied this patch on top of cryptodev-2.6/master and ran the
crypto self-tests (CONFIG_CRYPTO_SELFTESTS=y, CONFIG_CRYPTO_SELFTESTS_FULL=y) with the SPAcc driver. cmac(aes) and xcbc(aes) now allocate their software fallback and pass all self-tests, with no regressions on the other SPAcc hash/HMAC algorithms.
I will push the SPAcc v26 patches. Please suggest otherwise.

Quoted 5 lines

Warm Regards,
PK
Vayavya Labs Pvt. Ltd.

Refer to my feedback at
https://lore.kernel.org/linux-crypto/20261007102457.GA1695@quark/

- Eric