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/sha256 - Use API partial block handling

Use the Crypto API partial block handling.

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

+20 -101
+20 -101
arch/sparc/crypto/sha256_glue.c
··· 11 11 12 12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 13 13 14 + #include <asm/elf.h> 15 + #include <asm/pstate.h> 14 16 #include <crypto/internal/hash.h> 15 - #include <linux/init.h> 16 - #include <linux/module.h> 17 - #include <linux/mm.h> 18 - #include <linux/types.h> 19 17 #include <crypto/sha2.h> 20 18 #include <crypto/sha256_base.h> 21 - 22 - #include <asm/pstate.h> 23 - #include <asm/elf.h> 19 + #include <linux/kernel.h> 20 + #include <linux/module.h> 24 21 25 22 #include "opcodes.h" 26 23 27 24 asmlinkage void sha256_sparc64_transform(u32 *digest, const char *data, 28 25 unsigned int rounds); 29 26 30 - static void __sha256_sparc64_update(struct sha256_state *sctx, const u8 *data, 31 - unsigned int len, unsigned int partial) 27 + static void sha256_block(struct crypto_sha256_state *sctx, const u8 *src, 28 + int blocks) 32 29 { 33 - unsigned int done = 0; 34 - 35 - sctx->count += len; 36 - if (partial) { 37 - done = SHA256_BLOCK_SIZE - partial; 38 - memcpy(sctx->buf + partial, data, done); 39 - sha256_sparc64_transform(sctx->state, sctx->buf, 1); 40 - } 41 - if (len - done >= SHA256_BLOCK_SIZE) { 42 - const unsigned int rounds = (len - done) / SHA256_BLOCK_SIZE; 43 - 44 - sha256_sparc64_transform(sctx->state, data + done, rounds); 45 - done += rounds * SHA256_BLOCK_SIZE; 46 - } 47 - 48 - memcpy(sctx->buf, data + done, len - done); 30 + sha256_sparc64_transform(sctx->state, src, blocks); 49 31 } 50 32 51 33 static int sha256_sparc64_update(struct shash_desc *desc, const u8 *data, 52 34 unsigned int len) 53 35 { 54 - struct sha256_state *sctx = shash_desc_ctx(desc); 55 - unsigned int partial = sctx->count % SHA256_BLOCK_SIZE; 56 - 57 - /* Handle the fast case right here */ 58 - if (partial + len < SHA256_BLOCK_SIZE) { 59 - sctx->count += len; 60 - memcpy(sctx->buf + partial, data, len); 61 - } else 62 - __sha256_sparc64_update(sctx, data, len, partial); 63 - 64 - return 0; 36 + return sha256_base_do_update_blocks(desc, data, len, sha256_block); 65 37 } 66 38 67 - static int sha256_sparc64_final(struct shash_desc *desc, u8 *out) 39 + static int sha256_sparc64_finup(struct shash_desc *desc, const u8 *src, 40 + unsigned int len, u8 *out) 68 41 { 69 - struct sha256_state *sctx = shash_desc_ctx(desc); 70 - unsigned int i, index, padlen; 71 - __be32 *dst = (__be32 *)out; 72 - __be64 bits; 73 - static const u8 padding[SHA256_BLOCK_SIZE] = { 0x80, }; 74 - 75 - bits = cpu_to_be64(sctx->count << 3); 76 - 77 - /* Pad out to 56 mod 64 and append length */ 78 - index = sctx->count % SHA256_BLOCK_SIZE; 79 - padlen = (index < 56) ? (56 - index) : ((SHA256_BLOCK_SIZE+56) - index); 80 - 81 - /* We need to fill a whole block for __sha256_sparc64_update() */ 82 - if (padlen <= 56) { 83 - sctx->count += padlen; 84 - memcpy(sctx->buf + index, padding, padlen); 85 - } else { 86 - __sha256_sparc64_update(sctx, padding, padlen, index); 87 - } 88 - __sha256_sparc64_update(sctx, (const u8 *)&bits, sizeof(bits), 56); 89 - 90 - /* Store state in digest */ 91 - for (i = 0; i < 8; i++) 92 - dst[i] = cpu_to_be32(sctx->state[i]); 93 - 94 - /* Wipe context */ 95 - memset(sctx, 0, sizeof(*sctx)); 96 - 97 - return 0; 98 - } 99 - 100 - static int sha224_sparc64_final(struct shash_desc *desc, u8 *hash) 101 - { 102 - u8 D[SHA256_DIGEST_SIZE]; 103 - 104 - sha256_sparc64_final(desc, D); 105 - 106 - memcpy(hash, D, SHA224_DIGEST_SIZE); 107 - memzero_explicit(D, SHA256_DIGEST_SIZE); 108 - 109 - return 0; 110 - } 111 - 112 - static int sha256_sparc64_export(struct shash_desc *desc, void *out) 113 - { 114 - struct sha256_state *sctx = shash_desc_ctx(desc); 115 - 116 - memcpy(out, sctx, sizeof(*sctx)); 117 - return 0; 118 - } 119 - 120 - static int sha256_sparc64_import(struct shash_desc *desc, const void *in) 121 - { 122 - struct sha256_state *sctx = shash_desc_ctx(desc); 123 - 124 - memcpy(sctx, in, sizeof(*sctx)); 125 - return 0; 42 + sha256_base_do_finup(desc, src, len, sha256_block); 43 + return sha256_base_finish(desc, out); 126 44 } 127 45 128 46 static struct shash_alg sha256_alg = { 129 47 .digestsize = SHA256_DIGEST_SIZE, 130 48 .init = sha256_base_init, 131 49 .update = sha256_sparc64_update, 132 - .final = sha256_sparc64_final, 133 - .export = sha256_sparc64_export, 134 - .import = sha256_sparc64_import, 135 - .descsize = sizeof(struct sha256_state), 136 - .statesize = sizeof(struct sha256_state), 50 + .finup = sha256_sparc64_finup, 51 + .descsize = sizeof(struct crypto_sha256_state), 137 52 .base = { 138 53 .cra_name = "sha256", 139 54 .cra_driver_name= "sha256-sparc64", 140 55 .cra_priority = SPARC_CR_OPCODE_PRIORITY, 56 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY | 57 + CRYPTO_AHASH_ALG_FINUP_MAX, 141 58 .cra_blocksize = SHA256_BLOCK_SIZE, 142 59 .cra_module = THIS_MODULE, 143 60 } ··· 64 147 .digestsize = SHA224_DIGEST_SIZE, 65 148 .init = sha224_base_init, 66 149 .update = sha256_sparc64_update, 67 - .final = sha224_sparc64_final, 68 - .descsize = sizeof(struct sha256_state), 150 + .finup = sha256_sparc64_finup, 151 + .descsize = sizeof(struct crypto_sha256_state), 69 152 .base = { 70 153 .cra_name = "sha224", 71 154 .cra_driver_name= "sha224-sparc64", 72 155 .cra_priority = SPARC_CR_OPCODE_PRIORITY, 156 + .cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY | 157 + CRYPTO_AHASH_ALG_FINUP_MAX, 73 158 .cra_blocksize = SHA224_BLOCK_SIZE, 74 159 .cra_module = THIS_MODULE, 75 160 }