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: ghash-generic - Use API partial block handling

Use the Crypto API partial block handling.

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

+19 -40
+17 -39
crypto/ghash-generic.c
··· 34 34 * (https://csrc.nist.gov/publications/detail/sp/800-38d/final) 35 35 */ 36 36 37 - #include <crypto/algapi.h> 38 37 #include <crypto/gf128mul.h> 39 38 #include <crypto/ghash.h> 40 39 #include <crypto/internal/hash.h> 41 - #include <linux/crypto.h> 42 - #include <linux/init.h> 40 + #include <crypto/utils.h> 41 + #include <linux/err.h> 43 42 #include <linux/kernel.h> 44 43 #include <linux/module.h> 44 + #include <linux/string.h> 45 45 46 46 static int ghash_init(struct shash_desc *desc) 47 47 { ··· 82 82 struct ghash_ctx *ctx = crypto_shash_ctx(desc->tfm); 83 83 u8 *dst = dctx->buffer; 84 84 85 - if (dctx->bytes) { 86 - int n = min(srclen, dctx->bytes); 87 - u8 *pos = dst + (GHASH_BLOCK_SIZE - dctx->bytes); 88 - 89 - dctx->bytes -= n; 90 - srclen -= n; 91 - 92 - while (n--) 93 - *pos++ ^= *src++; 94 - 95 - if (!dctx->bytes) 96 - gf128mul_4k_lle((be128 *)dst, ctx->gf128); 97 - } 98 - 99 - while (srclen >= GHASH_BLOCK_SIZE) { 85 + do { 100 86 crypto_xor(dst, src, GHASH_BLOCK_SIZE); 101 87 gf128mul_4k_lle((be128 *)dst, ctx->gf128); 102 88 src += GHASH_BLOCK_SIZE; 103 89 srclen -= GHASH_BLOCK_SIZE; 104 - } 90 + } while (srclen >= GHASH_BLOCK_SIZE); 105 91 106 - if (srclen) { 107 - dctx->bytes = GHASH_BLOCK_SIZE - srclen; 108 - while (srclen--) 109 - *dst++ ^= *src++; 110 - } 111 - 112 - return 0; 92 + return srclen; 113 93 } 114 94 115 - static void ghash_flush(struct ghash_ctx *ctx, struct ghash_desc_ctx *dctx) 95 + static void ghash_flush(struct shash_desc *desc, const u8 *src, 96 + unsigned int len) 116 97 { 98 + struct ghash_ctx *ctx = crypto_shash_ctx(desc->tfm); 99 + struct ghash_desc_ctx *dctx = shash_desc_ctx(desc); 117 100 u8 *dst = dctx->buffer; 118 101 119 - if (dctx->bytes) { 120 - u8 *tmp = dst + (GHASH_BLOCK_SIZE - dctx->bytes); 121 - 122 - while (dctx->bytes--) 123 - *tmp++ ^= 0; 124 - 102 + if (len) { 103 + crypto_xor(dst, src, len); 125 104 gf128mul_4k_lle((be128 *)dst, ctx->gf128); 126 105 } 127 - 128 - dctx->bytes = 0; 129 106 } 130 107 131 - static int ghash_final(struct shash_desc *desc, u8 *dst) 108 + static int ghash_finup(struct shash_desc *desc, const u8 *src, 109 + unsigned int len, u8 *dst) 132 110 { 133 111 struct ghash_desc_ctx *dctx = shash_desc_ctx(desc); 134 - struct ghash_ctx *ctx = crypto_shash_ctx(desc->tfm); 135 112 u8 *buf = dctx->buffer; 136 113 137 - ghash_flush(ctx, dctx); 114 + ghash_flush(desc, src, len); 138 115 memcpy(dst, buf, GHASH_BLOCK_SIZE); 139 116 140 117 return 0; ··· 128 151 .digestsize = GHASH_DIGEST_SIZE, 129 152 .init = ghash_init, 130 153 .update = ghash_update, 131 - .final = ghash_final, 154 + .finup = ghash_finup, 132 155 .setkey = ghash_setkey, 133 156 .descsize = sizeof(struct ghash_desc_ctx), 134 157 .base = { 135 158 .cra_name = "ghash", 136 159 .cra_driver_name = "ghash-generic", 137 160 .cra_priority = 100, 161 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY, 138 162 .cra_blocksize = GHASH_BLOCK_SIZE, 139 163 .cra_ctxsize = sizeof(struct ghash_ctx), 140 164 .cra_module = THIS_MODULE,
+2 -1
include/crypto/ghash.h
··· 12 12 #define GHASH_BLOCK_SIZE 16 13 13 #define GHASH_DIGEST_SIZE 16 14 14 15 + struct gf128mul_4k; 16 + 15 17 struct ghash_ctx { 16 18 struct gf128mul_4k *gf128; 17 19 }; 18 20 19 21 struct ghash_desc_ctx { 20 22 u8 buffer[GHASH_BLOCK_SIZE]; 21 - u32 bytes; 22 23 }; 23 24 24 25 #endif