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

Use the Crypto API partial block handling.

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

+15 -87
+15 -87
arch/sparc/crypto/sha512_glue.c
··· 10 10 11 11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 12 12 13 + #include <asm/elf.h> 14 + #include <asm/pstate.h> 13 15 #include <crypto/internal/hash.h> 14 - #include <linux/init.h> 15 - #include <linux/module.h> 16 - #include <linux/mm.h> 17 - #include <linux/types.h> 18 16 #include <crypto/sha2.h> 19 17 #include <crypto/sha512_base.h> 20 - 21 - #include <asm/pstate.h> 22 - #include <asm/elf.h> 18 + #include <linux/kernel.h> 19 + #include <linux/module.h> 23 20 24 21 #include "opcodes.h" 25 22 26 23 asmlinkage void sha512_sparc64_transform(u64 *digest, const char *data, 27 24 unsigned int rounds); 28 25 29 - static void __sha512_sparc64_update(struct sha512_state *sctx, const u8 *data, 30 - unsigned int len, unsigned int partial) 26 + static void sha512_block(struct sha512_state *sctx, const u8 *src, int blocks) 31 27 { 32 - unsigned int done = 0; 33 - 34 - if ((sctx->count[0] += len) < len) 35 - sctx->count[1]++; 36 - if (partial) { 37 - done = SHA512_BLOCK_SIZE - partial; 38 - memcpy(sctx->buf + partial, data, done); 39 - sha512_sparc64_transform(sctx->state, sctx->buf, 1); 40 - } 41 - if (len - done >= SHA512_BLOCK_SIZE) { 42 - const unsigned int rounds = (len - done) / SHA512_BLOCK_SIZE; 43 - 44 - sha512_sparc64_transform(sctx->state, data + done, rounds); 45 - done += rounds * SHA512_BLOCK_SIZE; 46 - } 47 - 48 - memcpy(sctx->buf, data + done, len - done); 28 + sha512_sparc64_transform(sctx->state, src, blocks); 49 29 } 50 30 51 31 static int sha512_sparc64_update(struct shash_desc *desc, const u8 *data, 52 32 unsigned int len) 53 33 { 54 - struct sha512_state *sctx = shash_desc_ctx(desc); 55 - unsigned int partial = sctx->count[0] % SHA512_BLOCK_SIZE; 56 - 57 - /* Handle the fast case right here */ 58 - if (partial + len < SHA512_BLOCK_SIZE) { 59 - if ((sctx->count[0] += len) < len) 60 - sctx->count[1]++; 61 - memcpy(sctx->buf + partial, data, len); 62 - } else 63 - __sha512_sparc64_update(sctx, data, len, partial); 64 - 65 - return 0; 34 + return sha512_base_do_update_blocks(desc, data, len, sha512_block); 66 35 } 67 36 68 - static int sha512_sparc64_final(struct shash_desc *desc, u8 *out) 37 + static int sha512_sparc64_finup(struct shash_desc *desc, const u8 *src, 38 + unsigned int len, u8 *out) 69 39 { 70 - struct sha512_state *sctx = shash_desc_ctx(desc); 71 - unsigned int i, index, padlen; 72 - __be64 *dst = (__be64 *)out; 73 - __be64 bits[2]; 74 - static const u8 padding[SHA512_BLOCK_SIZE] = { 0x80, }; 75 - 76 - /* Save number of bits */ 77 - bits[1] = cpu_to_be64(sctx->count[0] << 3); 78 - bits[0] = cpu_to_be64(sctx->count[1] << 3 | sctx->count[0] >> 61); 79 - 80 - /* Pad out to 112 mod 128 and append length */ 81 - index = sctx->count[0] % SHA512_BLOCK_SIZE; 82 - padlen = (index < 112) ? (112 - index) : ((SHA512_BLOCK_SIZE+112) - index); 83 - 84 - /* We need to fill a whole block for __sha512_sparc64_update() */ 85 - if (padlen <= 112) { 86 - if ((sctx->count[0] += padlen) < padlen) 87 - sctx->count[1]++; 88 - memcpy(sctx->buf + index, padding, padlen); 89 - } else { 90 - __sha512_sparc64_update(sctx, padding, padlen, index); 91 - } 92 - __sha512_sparc64_update(sctx, (const u8 *)&bits, sizeof(bits), 112); 93 - 94 - /* Store state in digest */ 95 - for (i = 0; i < 8; i++) 96 - dst[i] = cpu_to_be64(sctx->state[i]); 97 - 98 - /* Wipe context */ 99 - memset(sctx, 0, sizeof(*sctx)); 100 - 101 - return 0; 102 - } 103 - 104 - static int sha384_sparc64_final(struct shash_desc *desc, u8 *hash) 105 - { 106 - u8 D[64]; 107 - 108 - sha512_sparc64_final(desc, D); 109 - 110 - memcpy(hash, D, 48); 111 - memzero_explicit(D, 64); 112 - 113 - return 0; 40 + sha512_base_do_finup(desc, src, len, sha512_block); 41 + return sha512_base_finish(desc, out); 114 42 } 115 43 116 44 static struct shash_alg sha512 = { 117 45 .digestsize = SHA512_DIGEST_SIZE, 118 46 .init = sha512_base_init, 119 47 .update = sha512_sparc64_update, 120 - .final = sha512_sparc64_final, 121 - .descsize = sizeof(struct sha512_state), 48 + .finup = sha512_sparc64_finup, 49 + .descsize = SHA512_STATE_SIZE, 122 50 .base = { 123 51 .cra_name = "sha512", 124 52 .cra_driver_name= "sha512-sparc64", ··· 60 132 .digestsize = SHA384_DIGEST_SIZE, 61 133 .init = sha384_base_init, 62 134 .update = sha512_sparc64_update, 63 - .final = sha384_sparc64_final, 64 - .descsize = sizeof(struct sha512_state), 135 + .finup = sha512_sparc64_finup, 136 + .descsize = SHA512_STATE_SIZE, 65 137 .base = { 66 138 .cra_name = "sha384", 67 139 .cra_driver_name= "sha384-sparc64",