diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2014-07-29 12:14:09 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2014-08-02 03:51:46 -0400 |
commit | 1f8673d31a999ed7e20d9f66fcdad39e39f6b276 (patch) | |
tree | c25defd891657b454b80ab97d9d1728425bb6223 /arch/arm | |
parent | c6f54a9b39626090c934646f7d732e31b70ffce7 (diff) |
ARM: 8118/1: crypto: sha1/make use of common SHA-1 structures
Common SHA-1 structures are defined in <crypto/sha.h> for code sharing.
This patch changes SHA-1/ARM glue code to use these structures.
Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm')
-rw-r--r-- | arch/arm/crypto/sha1_glue.c | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/arch/arm/crypto/sha1_glue.c b/arch/arm/crypto/sha1_glue.c index 76cd976230bc..c494e579ffc3 100644 --- a/arch/arm/crypto/sha1_glue.c +++ b/arch/arm/crypto/sha1_glue.c | |||
@@ -24,31 +24,25 @@ | |||
24 | #include <crypto/sha.h> | 24 | #include <crypto/sha.h> |
25 | #include <asm/byteorder.h> | 25 | #include <asm/byteorder.h> |
26 | 26 | ||
27 | struct SHA1_CTX { | ||
28 | uint32_t h0,h1,h2,h3,h4; | ||
29 | u64 count; | ||
30 | u8 data[SHA1_BLOCK_SIZE]; | ||
31 | }; | ||
32 | 27 | ||
33 | asmlinkage void sha1_block_data_order(struct SHA1_CTX *digest, | 28 | asmlinkage void sha1_block_data_order(u32 *digest, |
34 | const unsigned char *data, unsigned int rounds); | 29 | const unsigned char *data, unsigned int rounds); |
35 | 30 | ||
36 | 31 | ||
37 | static int sha1_init(struct shash_desc *desc) | 32 | static int sha1_init(struct shash_desc *desc) |
38 | { | 33 | { |
39 | struct SHA1_CTX *sctx = shash_desc_ctx(desc); | 34 | struct sha1_state *sctx = shash_desc_ctx(desc); |
40 | memset(sctx, 0, sizeof(*sctx)); | 35 | |
41 | sctx->h0 = SHA1_H0; | 36 | *sctx = (struct sha1_state){ |
42 | sctx->h1 = SHA1_H1; | 37 | .state = { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 }, |
43 | sctx->h2 = SHA1_H2; | 38 | }; |
44 | sctx->h3 = SHA1_H3; | 39 | |
45 | sctx->h4 = SHA1_H4; | ||
46 | return 0; | 40 | return 0; |
47 | } | 41 | } |
48 | 42 | ||
49 | 43 | ||
50 | static int __sha1_update(struct SHA1_CTX *sctx, const u8 *data, | 44 | static int __sha1_update(struct sha1_state *sctx, const u8 *data, |
51 | unsigned int len, unsigned int partial) | 45 | unsigned int len, unsigned int partial) |
52 | { | 46 | { |
53 | unsigned int done = 0; | 47 | unsigned int done = 0; |
54 | 48 | ||
@@ -56,17 +50,17 @@ static int __sha1_update(struct SHA1_CTX *sctx, const u8 *data, | |||
56 | 50 | ||
57 | if (partial) { | 51 | if (partial) { |
58 | done = SHA1_BLOCK_SIZE - partial; | 52 | done = SHA1_BLOCK_SIZE - partial; |
59 | memcpy(sctx->data + partial, data, done); | 53 | memcpy(sctx->buffer + partial, data, done); |
60 | sha1_block_data_order(sctx, sctx->data, 1); | 54 | sha1_block_data_order(sctx->state, sctx->buffer, 1); |
61 | } | 55 | } |
62 | 56 | ||
63 | if (len - done >= SHA1_BLOCK_SIZE) { | 57 | if (len - done >= SHA1_BLOCK_SIZE) { |
64 | const unsigned int rounds = (len - done) / SHA1_BLOCK_SIZE; | 58 | const unsigned int rounds = (len - done) / SHA1_BLOCK_SIZE; |
65 | sha1_block_data_order(sctx, data + done, rounds); | 59 | sha1_block_data_order(sctx->state, data + done, rounds); |
66 | done += rounds * SHA1_BLOCK_SIZE; | 60 | done += rounds * SHA1_BLOCK_SIZE; |
67 | } | 61 | } |
68 | 62 | ||
69 | memcpy(sctx->data, data + done, len - done); | 63 | memcpy(sctx->buffer, data + done, len - done); |
70 | return 0; | 64 | return 0; |
71 | } | 65 | } |
72 | 66 | ||
@@ -74,14 +68,14 @@ static int __sha1_update(struct SHA1_CTX *sctx, const u8 *data, | |||
74 | static int sha1_update(struct shash_desc *desc, const u8 *data, | 68 | static int sha1_update(struct shash_desc *desc, const u8 *data, |
75 | unsigned int len) | 69 | unsigned int len) |
76 | { | 70 | { |
77 | struct SHA1_CTX *sctx = shash_desc_ctx(desc); | 71 | struct sha1_state *sctx = shash_desc_ctx(desc); |
78 | unsigned int partial = sctx->count % SHA1_BLOCK_SIZE; | 72 | unsigned int partial = sctx->count % SHA1_BLOCK_SIZE; |
79 | int res; | 73 | int res; |
80 | 74 | ||
81 | /* Handle the fast case right here */ | 75 | /* Handle the fast case right here */ |
82 | if (partial + len < SHA1_BLOCK_SIZE) { | 76 | if (partial + len < SHA1_BLOCK_SIZE) { |
83 | sctx->count += len; | 77 | sctx->count += len; |
84 | memcpy(sctx->data + partial, data, len); | 78 | memcpy(sctx->buffer + partial, data, len); |
85 | return 0; | 79 | return 0; |
86 | } | 80 | } |
87 | res = __sha1_update(sctx, data, len, partial); | 81 | res = __sha1_update(sctx, data, len, partial); |
@@ -92,7 +86,7 @@ static int sha1_update(struct shash_desc *desc, const u8 *data, | |||
92 | /* Add padding and return the message digest. */ | 86 | /* Add padding and return the message digest. */ |
93 | static int sha1_final(struct shash_desc *desc, u8 *out) | 87 | static int sha1_final(struct shash_desc *desc, u8 *out) |
94 | { | 88 | { |
95 | struct SHA1_CTX *sctx = shash_desc_ctx(desc); | 89 | struct sha1_state *sctx = shash_desc_ctx(desc); |
96 | unsigned int i, index, padlen; | 90 | unsigned int i, index, padlen; |
97 | __be32 *dst = (__be32 *)out; | 91 | __be32 *dst = (__be32 *)out; |
98 | __be64 bits; | 92 | __be64 bits; |
@@ -106,7 +100,7 @@ static int sha1_final(struct shash_desc *desc, u8 *out) | |||
106 | /* We need to fill a whole block for __sha1_update() */ | 100 | /* We need to fill a whole block for __sha1_update() */ |
107 | if (padlen <= 56) { | 101 | if (padlen <= 56) { |
108 | sctx->count += padlen; | 102 | sctx->count += padlen; |
109 | memcpy(sctx->data + index, padding, padlen); | 103 | memcpy(sctx->buffer + index, padding, padlen); |
110 | } else { | 104 | } else { |
111 | __sha1_update(sctx, padding, padlen, index); | 105 | __sha1_update(sctx, padding, padlen, index); |
112 | } | 106 | } |
@@ -114,7 +108,7 @@ static int sha1_final(struct shash_desc *desc, u8 *out) | |||
114 | 108 | ||
115 | /* Store state in digest */ | 109 | /* Store state in digest */ |
116 | for (i = 0; i < 5; i++) | 110 | for (i = 0; i < 5; i++) |
117 | dst[i] = cpu_to_be32(((u32 *)sctx)[i]); | 111 | dst[i] = cpu_to_be32(sctx->state[i]); |
118 | 112 | ||
119 | /* Wipe context */ | 113 | /* Wipe context */ |
120 | memset(sctx, 0, sizeof(*sctx)); | 114 | memset(sctx, 0, sizeof(*sctx)); |
@@ -124,7 +118,7 @@ static int sha1_final(struct shash_desc *desc, u8 *out) | |||
124 | 118 | ||
125 | static int sha1_export(struct shash_desc *desc, void *out) | 119 | static int sha1_export(struct shash_desc *desc, void *out) |
126 | { | 120 | { |
127 | struct SHA1_CTX *sctx = shash_desc_ctx(desc); | 121 | struct sha1_state *sctx = shash_desc_ctx(desc); |
128 | memcpy(out, sctx, sizeof(*sctx)); | 122 | memcpy(out, sctx, sizeof(*sctx)); |
129 | return 0; | 123 | return 0; |
130 | } | 124 | } |
@@ -132,7 +126,7 @@ static int sha1_export(struct shash_desc *desc, void *out) | |||
132 | 126 | ||
133 | static int sha1_import(struct shash_desc *desc, const void *in) | 127 | static int sha1_import(struct shash_desc *desc, const void *in) |
134 | { | 128 | { |
135 | struct SHA1_CTX *sctx = shash_desc_ctx(desc); | 129 | struct sha1_state *sctx = shash_desc_ctx(desc); |
136 | memcpy(sctx, in, sizeof(*sctx)); | 130 | memcpy(sctx, in, sizeof(*sctx)); |
137 | return 0; | 131 | return 0; |
138 | } | 132 | } |
@@ -145,8 +139,8 @@ static struct shash_alg alg = { | |||
145 | .final = sha1_final, | 139 | .final = sha1_final, |
146 | .export = sha1_export, | 140 | .export = sha1_export, |
147 | .import = sha1_import, | 141 | .import = sha1_import, |
148 | .descsize = sizeof(struct SHA1_CTX), | 142 | .descsize = sizeof(struct sha1_state), |
149 | .statesize = sizeof(struct SHA1_CTX), | 143 | .statesize = sizeof(struct sha1_state), |
150 | .base = { | 144 | .base = { |
151 | .cra_name = "sha1", | 145 | .cra_name = "sha1", |
152 | .cra_driver_name= "sha1-asm", | 146 | .cra_driver_name= "sha1-asm", |