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

Use the Crypto API partial block handling.

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

+17 -36
+17 -28
crypto/sha512_generic.c
··· 6 6 * Copyright (c) 2003 Kyle McMartin <kyle@debian.org> 7 7 */ 8 8 #include <crypto/internal/hash.h> 9 - #include <linux/kernel.h> 10 - #include <linux/module.h> 11 - #include <linux/mm.h> 12 - #include <linux/init.h> 13 - #include <linux/crypto.h> 14 - #include <linux/types.h> 15 9 #include <crypto/sha2.h> 16 10 #include <crypto/sha512_base.h> 17 - #include <linux/percpu.h> 18 - #include <asm/byteorder.h> 11 + #include <linux/kernel.h> 12 + #include <linux/module.h> 19 13 #include <linux/unaligned.h> 20 14 21 15 const u8 sha384_zero_message_hash[SHA384_DIGEST_SIZE] = { ··· 142 148 void sha512_generic_block_fn(struct sha512_state *sst, u8 const *src, 143 149 int blocks) 144 150 { 145 - while (blocks--) { 151 + do { 146 152 sha512_transform(sst->state, src); 147 153 src += SHA512_BLOCK_SIZE; 148 - } 154 + } while (--blocks); 149 155 } 150 156 EXPORT_SYMBOL_GPL(sha512_generic_block_fn); 151 157 152 - int crypto_sha512_update(struct shash_desc *desc, const u8 *data, 153 - unsigned int len) 158 + static int crypto_sha512_update(struct shash_desc *desc, const u8 *data, 159 + unsigned int len) 154 160 { 155 - return sha512_base_do_update(desc, data, len, sha512_generic_block_fn); 161 + return sha512_base_do_update_blocks(desc, data, len, 162 + sha512_generic_block_fn); 156 163 } 157 - EXPORT_SYMBOL(crypto_sha512_update); 158 164 159 - static int sha512_final(struct shash_desc *desc, u8 *hash) 165 + static int crypto_sha512_finup(struct shash_desc *desc, const u8 *data, 166 + unsigned int len, u8 *hash) 160 167 { 161 - sha512_base_do_finalize(desc, sha512_generic_block_fn); 168 + sha512_base_do_finup(desc, data, len, sha512_generic_block_fn); 162 169 return sha512_base_finish(desc, hash); 163 170 } 164 - 165 - int crypto_sha512_finup(struct shash_desc *desc, const u8 *data, 166 - unsigned int len, u8 *hash) 167 - { 168 - sha512_base_do_update(desc, data, len, sha512_generic_block_fn); 169 - return sha512_final(desc, hash); 170 - } 171 - EXPORT_SYMBOL(crypto_sha512_finup); 172 171 173 172 static struct shash_alg sha512_algs[2] = { { 174 173 .digestsize = SHA512_DIGEST_SIZE, 175 174 .init = sha512_base_init, 176 175 .update = crypto_sha512_update, 177 - .final = sha512_final, 178 176 .finup = crypto_sha512_finup, 179 - .descsize = sizeof(struct sha512_state), 177 + .descsize = SHA512_STATE_SIZE, 180 178 .base = { 181 179 .cra_name = "sha512", 182 180 .cra_driver_name = "sha512-generic", 183 181 .cra_priority = 100, 182 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY | 183 + CRYPTO_AHASH_ALG_FINUP_MAX, 184 184 .cra_blocksize = SHA512_BLOCK_SIZE, 185 185 .cra_module = THIS_MODULE, 186 186 } ··· 182 194 .digestsize = SHA384_DIGEST_SIZE, 183 195 .init = sha384_base_init, 184 196 .update = crypto_sha512_update, 185 - .final = sha512_final, 186 197 .finup = crypto_sha512_finup, 187 - .descsize = sizeof(struct sha512_state), 198 + .descsize = SHA512_STATE_SIZE, 188 199 .base = { 189 200 .cra_name = "sha384", 190 201 .cra_driver_name = "sha384-generic", 191 202 .cra_priority = 100, 203 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY | 204 + CRYPTO_AHASH_ALG_FINUP_MAX, 192 205 .cra_blocksize = SHA384_BLOCK_SIZE, 193 206 .cra_module = THIS_MODULE, 194 207 }
-8
include/crypto/sha2.h
··· 82 82 u8 buf[SHA512_BLOCK_SIZE]; 83 83 }; 84 84 85 - struct shash_desc; 86 - 87 - extern int crypto_sha512_update(struct shash_desc *desc, const u8 *data, 88 - unsigned int len); 89 - 90 - extern int crypto_sha512_finup(struct shash_desc *desc, const u8 *data, 91 - unsigned int len, u8 *hash); 92 - 93 85 /* 94 86 * Stand-alone implementation of the SHA256 algorithm. It is designed to 95 87 * have as little dependencies as possible so it can be used in the