Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: riscv/ghash - Use API partial block handling

Use the Crypto API partial block handling.

As this was the last user relying on crypto/ghash.h for gf128mul.h,
remove the unnecessary inclusion of gf128mul.h from crypto/ghash.h.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+18 -41
+18 -40
arch/riscv/crypto/ghash-riscv64-glue.c
··· 11 11 12 12 #include <asm/simd.h> 13 13 #include <asm/vector.h> 14 + #include <crypto/b128ops.h> 15 + #include <crypto/gf128mul.h> 14 16 #include <crypto/ghash.h> 15 17 #include <crypto/internal/hash.h> 16 18 #include <crypto/internal/simd.h> 17 - #include <linux/linkage.h> 19 + #include <crypto/utils.h> 20 + #include <linux/errno.h> 21 + #include <linux/kernel.h> 18 22 #include <linux/module.h> 23 + #include <linux/string.h> 19 24 20 25 asmlinkage void ghash_zvkg(be128 *accumulator, const be128 *key, const u8 *data, 21 26 size_t len); ··· 31 26 32 27 struct riscv64_ghash_desc_ctx { 33 28 be128 accumulator; 34 - u8 buffer[GHASH_BLOCK_SIZE]; 35 - u32 bytes; 36 29 }; 37 30 38 31 static int riscv64_ghash_setkey(struct crypto_shash *tfm, const u8 *key, ··· 81 78 { 82 79 const struct riscv64_ghash_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); 83 80 struct riscv64_ghash_desc_ctx *dctx = shash_desc_ctx(desc); 84 - unsigned int len; 85 81 86 - if (dctx->bytes) { 87 - if (dctx->bytes + srclen < GHASH_BLOCK_SIZE) { 88 - memcpy(dctx->buffer + dctx->bytes, src, srclen); 89 - dctx->bytes += srclen; 90 - return 0; 91 - } 92 - memcpy(dctx->buffer + dctx->bytes, src, 93 - GHASH_BLOCK_SIZE - dctx->bytes); 94 - riscv64_ghash_blocks(tctx, dctx, dctx->buffer, 95 - GHASH_BLOCK_SIZE); 96 - src += GHASH_BLOCK_SIZE - dctx->bytes; 97 - srclen -= GHASH_BLOCK_SIZE - dctx->bytes; 98 - dctx->bytes = 0; 99 - } 100 - 101 - len = round_down(srclen, GHASH_BLOCK_SIZE); 102 - if (len) { 103 - riscv64_ghash_blocks(tctx, dctx, src, len); 104 - src += len; 105 - srclen -= len; 106 - } 107 - 108 - if (srclen) { 109 - memcpy(dctx->buffer, src, srclen); 110 - dctx->bytes = srclen; 111 - } 112 - 113 - return 0; 82 + riscv64_ghash_blocks(tctx, dctx, src, 83 + round_down(srclen, GHASH_BLOCK_SIZE)); 84 + return srclen - round_down(srclen, GHASH_BLOCK_SIZE); 114 85 } 115 86 116 - static int riscv64_ghash_final(struct shash_desc *desc, u8 *out) 87 + static int riscv64_ghash_finup(struct shash_desc *desc, const u8 *src, 88 + unsigned int len, u8 *out) 117 89 { 118 90 const struct riscv64_ghash_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); 119 91 struct riscv64_ghash_desc_ctx *dctx = shash_desc_ctx(desc); 120 - int i; 121 92 122 - if (dctx->bytes) { 123 - for (i = dctx->bytes; i < GHASH_BLOCK_SIZE; i++) 124 - dctx->buffer[i] = 0; 93 + if (len) { 94 + u8 buf[GHASH_BLOCK_SIZE] = {}; 125 95 126 - riscv64_ghash_blocks(tctx, dctx, dctx->buffer, 127 - GHASH_BLOCK_SIZE); 96 + memcpy(buf, src, len); 97 + riscv64_ghash_blocks(tctx, dctx, buf, GHASH_BLOCK_SIZE); 98 + memzero_explicit(buf, sizeof(buf)); 128 99 } 129 100 130 101 memcpy(out, &dctx->accumulator, GHASH_DIGEST_SIZE); ··· 108 131 static struct shash_alg riscv64_ghash_alg = { 109 132 .init = riscv64_ghash_init, 110 133 .update = riscv64_ghash_update, 111 - .final = riscv64_ghash_final, 134 + .finup = riscv64_ghash_finup, 112 135 .setkey = riscv64_ghash_setkey, 113 136 .descsize = sizeof(struct riscv64_ghash_desc_ctx), 114 137 .digestsize = GHASH_DIGEST_SIZE, ··· 116 139 .cra_blocksize = GHASH_BLOCK_SIZE, 117 140 .cra_ctxsize = sizeof(struct riscv64_ghash_tfm_ctx), 118 141 .cra_priority = 300, 142 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY, 119 143 .cra_name = "ghash", 120 144 .cra_driver_name = "ghash-riscv64-zvkg", 121 145 .cra_module = THIS_MODULE,
-1
include/crypto/ghash.h
··· 7 7 #define __CRYPTO_GHASH_H__ 8 8 9 9 #include <linux/types.h> 10 - #include <crypto/gf128mul.h> 11 10 12 11 #define GHASH_BLOCK_SIZE 16 13 12 #define GHASH_DIGEST_SIZE 16