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: lib/sm3 - Remove partial block helpers

Now that all sm3_base users have been converted to use the API
partial block handling, remove the partial block helpers as well
as the lib/crypto functions.

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

+6 -128
-2
include/crypto/sm3.h
··· 60 60 } 61 61 62 62 void sm3_block_generic(struct sm3_state *sctx, u8 const *data, int blocks); 63 - void sm3_update(struct sm3_state *sctx, const u8 *data, unsigned int len); 64 - void sm3_final(struct sm3_state *sctx, u8 *out); 65 63 66 64 #endif
+2 -62
include/crypto/sm3_base.h
··· 11 11 12 12 #include <crypto/internal/hash.h> 13 13 #include <crypto/sm3.h> 14 - #include <linux/crypto.h> 14 + #include <linux/math.h> 15 15 #include <linux/module.h> 16 16 #include <linux/string.h> 17 + #include <linux/types.h> 17 18 #include <linux/unaligned.h> 18 19 19 20 typedef void (sm3_block_fn)(struct sm3_state *sst, u8 const *src, int blocks); ··· 22 21 static inline int sm3_base_init(struct shash_desc *desc) 23 22 { 24 23 sm3_init(shash_desc_ctx(desc)); 25 - return 0; 26 - } 27 - 28 - static inline int sm3_base_do_update(struct shash_desc *desc, 29 - const u8 *data, 30 - unsigned int len, 31 - sm3_block_fn *block_fn) 32 - { 33 - struct sm3_state *sctx = shash_desc_ctx(desc); 34 - unsigned int partial = sctx->count % SM3_BLOCK_SIZE; 35 - 36 - sctx->count += len; 37 - 38 - if (unlikely((partial + len) >= SM3_BLOCK_SIZE)) { 39 - int blocks; 40 - 41 - if (partial) { 42 - int p = SM3_BLOCK_SIZE - partial; 43 - 44 - memcpy(sctx->buffer + partial, data, p); 45 - data += p; 46 - len -= p; 47 - 48 - block_fn(sctx, sctx->buffer, 1); 49 - } 50 - 51 - blocks = len / SM3_BLOCK_SIZE; 52 - len %= SM3_BLOCK_SIZE; 53 - 54 - if (blocks) { 55 - block_fn(sctx, data, blocks); 56 - data += blocks * SM3_BLOCK_SIZE; 57 - } 58 - partial = 0; 59 - } 60 - if (len) 61 - memcpy(sctx->buffer + partial, data, len); 62 - 63 24 return 0; 64 25 } 65 26 ··· 64 101 block.b64[bit_offset] = cpu_to_be64(sctx->count << 3); 65 102 block_fn(sctx, block.u8, (bit_offset + 1) * 8 / SM3_BLOCK_SIZE); 66 103 memzero_explicit(&block, sizeof(block)); 67 - 68 - return 0; 69 - } 70 - 71 - static inline int sm3_base_do_finalize(struct shash_desc *desc, 72 - sm3_block_fn *block_fn) 73 - { 74 - const int bit_offset = SM3_BLOCK_SIZE - sizeof(__be64); 75 - struct sm3_state *sctx = shash_desc_ctx(desc); 76 - __be64 *bits = (__be64 *)(sctx->buffer + bit_offset); 77 - unsigned int partial = sctx->count % SM3_BLOCK_SIZE; 78 - 79 - sctx->buffer[partial++] = 0x80; 80 - if (partial > bit_offset) { 81 - memset(sctx->buffer + partial, 0x0, SM3_BLOCK_SIZE - partial); 82 - partial = 0; 83 - 84 - block_fn(sctx, sctx->buffer, 1); 85 - } 86 - 87 - memset(sctx->buffer + partial, 0x0, bit_offset - partial); 88 - *bits = cpu_to_be64(sctx->count << 3); 89 - block_fn(sctx, sctx->buffer, 1); 90 104 91 105 return 0; 92 106 }
+4 -64
lib/crypto/sm3.c
··· 8 8 * Copyright (C) 2021 Tianjia Zhang <tianjia.zhang@linux.alibaba.com> 9 9 */ 10 10 11 - #include <linux/module.h> 12 - #include <linux/unaligned.h> 13 11 #include <crypto/sm3.h> 12 + #include <linux/kernel.h> 13 + #include <linux/module.h> 14 + #include <linux/string.h> 15 + #include <linux/unaligned.h> 14 16 15 17 static const u32 ____cacheline_aligned K[64] = { 16 18 0x79cc4519, 0xf3988a32, 0xe7311465, 0xce6228cb, ··· 180 178 memzero_explicit(W, sizeof(W)); 181 179 } 182 180 EXPORT_SYMBOL_GPL(sm3_block_generic); 183 - 184 - void sm3_update(struct sm3_state *sctx, const u8 *data, unsigned int len) 185 - { 186 - unsigned int partial = sctx->count % SM3_BLOCK_SIZE; 187 - 188 - sctx->count += len; 189 - 190 - if ((partial + len) >= SM3_BLOCK_SIZE) { 191 - int blocks; 192 - 193 - if (partial) { 194 - int p = SM3_BLOCK_SIZE - partial; 195 - 196 - memcpy(sctx->buffer + partial, data, p); 197 - data += p; 198 - len -= p; 199 - 200 - sm3_block_generic(sctx, sctx->buffer, 1); 201 - } 202 - 203 - blocks = len / SM3_BLOCK_SIZE; 204 - len %= SM3_BLOCK_SIZE; 205 - 206 - if (blocks) { 207 - sm3_block_generic(sctx, data, blocks); 208 - data += blocks * SM3_BLOCK_SIZE; 209 - } 210 - 211 - partial = 0; 212 - } 213 - if (len) 214 - memcpy(sctx->buffer + partial, data, len); 215 - } 216 - EXPORT_SYMBOL_GPL(sm3_update); 217 - 218 - void sm3_final(struct sm3_state *sctx, u8 *out) 219 - { 220 - const int bit_offset = SM3_BLOCK_SIZE - sizeof(u64); 221 - __be64 *bits = (__be64 *)(sctx->buffer + bit_offset); 222 - __be32 *digest = (__be32 *)out; 223 - unsigned int partial = sctx->count % SM3_BLOCK_SIZE; 224 - int i; 225 - 226 - sctx->buffer[partial++] = 0x80; 227 - if (partial > bit_offset) { 228 - memset(sctx->buffer + partial, 0, SM3_BLOCK_SIZE - partial); 229 - partial = 0; 230 - 231 - sm3_block_generic(sctx, sctx->buffer, 1); 232 - } 233 - 234 - memset(sctx->buffer + partial, 0, bit_offset - partial); 235 - *bits = cpu_to_be64(sctx->count << 3); 236 - sm3_block_generic(sctx, sctx->buffer, 1); 237 - 238 - for (i = 0; i < 8; i++) 239 - put_unaligned_be32(sctx->state[i], digest++); 240 - 241 - /* Zeroize sensitive information. */ 242 - memzero_explicit(sctx, sizeof(*sctx)); 243 - } 244 - EXPORT_SYMBOL_GPL(sm3_final); 245 181 246 182 MODULE_DESCRIPTION("Generic SM3 library"); 247 183 MODULE_LICENSE("GPL v2");