* [PATCH] crypto: aes - Add import_core/export_core to cmac/xcbc/cbcmac
@ 2026-10-09 11:45 Herbert Xu
2026-10-10 0:11 ` kernel test robot
2026-10-12 10:41 ` Pavitrakumar Managutte
0 siblings, 2 replies; 5+ messages in thread
From: Herbert Xu @ 2026-10-09 11:45 UTC (permalink / raw)
To: Linux Crypto Mailing List, Pavitrakumar Managutte
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.
Reported-by: Pavitrakumar Managutte <pavitrakumarm@vayavyalabs.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff --git a/crypto/aes.c b/crypto/aes.c
index 94791f481e98..a1af4d5a7608 100644
--- a/crypto/aes.c
+++ b/crypto/aes.c
@@ -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 <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] crypto: aes - Add import_core/export_core to cmac/xcbc/cbcmac
2026-10-09 11:45 [PATCH] crypto: aes - Add import_core/export_core to cmac/xcbc/cbcmac Herbert Xu
@ 2026-10-10 0:11 ` kernel test robot
2026-10-12 10:41 ` Pavitrakumar Managutte
1 sibling, 0 replies; 5+ messages in thread
From: kernel test robot @ 2026-10-10 0:11 UTC (permalink / raw)
To: Herbert Xu, Linux Crypto Mailing List, Pavitrakumar Managutte
Cc: oe-kbuild-all
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/202610100824.r4C5Hjk0-lkp@intel.com/config)
compiler: sparc-linux-gcc (GCC) 16.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261010/202610100824.r4C5Hjk0-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202610100824.r4C5Hjk0-lkp@intel.com/
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] crypto: aes - Add import_core/export_core to cmac/xcbc/cbcmac
2026-10-09 11:45 [PATCH] crypto: aes - Add import_core/export_core to cmac/xcbc/cbcmac Herbert Xu
2026-10-10 0:11 ` kernel test robot
@ 2026-10-12 10:41 ` Pavitrakumar Managutte
2026-10-15 17:42 ` Pavitrakumar Managutte
1 sibling, 1 reply; 5+ messages in thread
From: Pavitrakumar Managutte @ 2026-10-12 10:41 UTC (permalink / raw)
To: Herbert Xu; +Cc: Linux Crypto Mailing List
Hi Herbert,
I tested your patch with the SPAcc driver, all cmac(aes)/xcbc(aes)
tests pass.
Warm regards,
PK
Vayavya Labs Pvt. Ltd.
On Fri, Oct 9, 2026 at 5:16 PM Herbert Xu <herbert@gondor.apana.org.au> wrote:
>
> 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.
>
> Reported-by: Pavitrakumar Managutte <pavitrakumarm@vayavyalabs.com>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
>
> diff --git a/crypto/aes.c b/crypto/aes.c
> index 94791f481e98..a1af4d5a7608 100644
> --- a/crypto/aes.c
> +++ b/crypto/aes.c
> @@ -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 <herbert@gondor.apana.org.au>
> Home Page: http://gondor.apana.org.au/~herbert/
> PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] crypto: aes - Add import_core/export_core to cmac/xcbc/cbcmac
2026-10-12 10:41 ` Pavitrakumar Managutte
@ 2026-10-15 17:42 ` Pavitrakumar Managutte
2026-10-15 18:34 ` Eric Biggers
0 siblings, 1 reply; 5+ messages in thread
From: Pavitrakumar Managutte @ 2026-10-15 17:42 UTC (permalink / raw)
To: Herbert Xu; +Cc: Linux Crypto Mailing List
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.
Tested-by: Pavitrakumar Managutte <pavitrakumarm@vayavyalabs.com>
Warm Regards,
PK
Vayavya Labs Pvt. Ltd.
On Mon, Oct 12, 2026 at 4:11 PM Pavitrakumar Managutte
<pavitrakumarm@vayavyalabs.com> wrote:
>
> Hi Herbert,
> I tested your patch with the SPAcc driver, all cmac(aes)/xcbc(aes)
> tests pass.
>
> Warm regards,
> PK
> Vayavya Labs Pvt. Ltd.
>
> On Fri, Oct 9, 2026 at 5:16 PM Herbert Xu <herbert@gondor.apana.org.au> wrote:
> >
> > 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.
> >
> > Reported-by: Pavitrakumar Managutte <pavitrakumarm@vayavyalabs.com>
> > Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> >
> > diff --git a/crypto/aes.c b/crypto/aes.c
> > index 94791f481e98..a1af4d5a7608 100644
> > --- a/crypto/aes.c
> > +++ b/crypto/aes.c
> > @@ -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 <herbert@gondor.apana.org.au>
> > Home Page: http://gondor.apana.org.au/~herbert/
> > PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] crypto: aes - Add import_core/export_core to cmac/xcbc/cbcmac
2026-10-15 17:42 ` Pavitrakumar Managutte
@ 2026-10-15 18:34 ` Eric Biggers
0 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2026-10-15 18:34 UTC (permalink / raw)
To: Pavitrakumar Managutte; +Cc: Herbert Xu, Linux Crypto Mailing List
On Thu, Oct 15, 2026 at 11:12:58PM +0530, Pavitrakumar Managutte wrote:
> 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.
>
> Tested-by: Pavitrakumar Managutte <pavitrakumarm@vayavyalabs.com>
>
> Warm Regards,
> PK
> Vayavya Labs Pvt. Ltd.
Refer to my feedback at
https://lore.kernel.org/linux-crypto/20261007102457.GA1695@quark/
- Eric
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-10-15 18:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-09 11:45 [PATCH] crypto: aes - Add import_core/export_core to cmac/xcbc/cbcmac Herbert Xu
2026-10-10 0:11 ` kernel test robot
2026-10-12 10:41 ` Pavitrakumar Managutte
2026-10-15 17:42 ` Pavitrakumar Managutte
2026-10-15 18:34 ` Eric Biggers
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.