crypto: cbcmac - Set block size properly
authorHerbert Xu <herbert@gondor.apana.org.au>
Sat, 12 Apr 2025 10:57:36 +0000 (18:57 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Wed, 16 Apr 2025 07:36:24 +0000 (15:36 +0800)
The block size of a hash algorithm is meant to be the number of
bytes its block function can handle.  For cbcmac that should be
the block size of the underlying block cipher instead of one.

Set the block size of all cbcmac implementations accordingly.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/arm64/crypto/aes-glue.c
arch/arm64/crypto/sm4-ce-glue.c
crypto/ccm.c
drivers/crypto/inside-secure/safexcel_hash.c

index b0150999743f68361f6ef2541ebee07bcf915173..5ca3b5661749f858701e440c10659945ce391cb3 100644 (file)
@@ -1009,7 +1009,7 @@ static struct shash_alg mac_algs[] = { {
        .base.cra_name          = "cbcmac(aes)",
        .base.cra_driver_name   = "cbcmac-aes-" MODE,
        .base.cra_priority      = PRIO,
-       .base.cra_blocksize     = 1,
+       .base.cra_blocksize     = AES_BLOCK_SIZE,
        .base.cra_ctxsize       = sizeof(struct mac_tfm_ctx),
        .base.cra_module        = THIS_MODULE,
 
index 43741bed874e275d2ad343370a539663d456e17c..f11cf26e5a206dbdeea8b631a1236452ca760fea 100644 (file)
@@ -723,7 +723,7 @@ static struct shash_alg sm4_mac_algs[] = {
                        .cra_name               = "cbcmac(sm4)",
                        .cra_driver_name        = "cbcmac-sm4-ce",
                        .cra_priority           = 400,
-                       .cra_blocksize          = 1,
+                       .cra_blocksize          = SM4_BLOCK_SIZE,
                        .cra_ctxsize            = sizeof(struct sm4_mac_tfm_ctx),
                        .cra_module             = THIS_MODULE,
                },
index 06476b53b4916338f27ea784bca2ab23d0fde342..a0610ff6ce02b55ee6c2913811bc8212acc44735 100644 (file)
@@ -883,7 +883,7 @@ static int cbcmac_create(struct crypto_template *tmpl, struct rtattr **tb)
                goto err_free_inst;
 
        inst->alg.base.cra_priority = alg->cra_priority;
-       inst->alg.base.cra_blocksize = 1;
+       inst->alg.base.cra_blocksize = alg->cra_blocksize;
 
        inst->alg.digestsize = alg->cra_blocksize;
        inst->alg.descsize = sizeof(struct cbcmac_desc_ctx) +
index f44c08f5f5ec4af129e0e69141be8fc4a6ac6f71..d2b632193bebb982fce069c3586106105548d595 100644 (file)
@@ -2043,7 +2043,7 @@ struct safexcel_alg_template safexcel_alg_cbcmac = {
                                .cra_flags = CRYPTO_ALG_ASYNC |
                                             CRYPTO_ALG_ALLOCATES_MEMORY |
                                             CRYPTO_ALG_KERN_DRIVER_ONLY,
-                               .cra_blocksize = 1,
+                               .cra_blocksize = AES_BLOCK_SIZE,
                                .cra_ctxsize = sizeof(struct safexcel_ahash_ctx),
                                .cra_init = safexcel_ahash_cra_init,
                                .cra_exit = safexcel_ahash_cra_exit,