aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto/sha256_generic.c37
-rw-r--r--include/crypto/sha.h6
2 files changed, 31 insertions, 12 deletions
diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
index e58c71bdf333..c48459ebf05b 100644
--- a/crypto/sha256_generic.c
+++ b/crypto/sha256_generic.c
@@ -25,12 +25,6 @@
25#include <crypto/sha.h> 25#include <crypto/sha.h>
26#include <asm/byteorder.h> 26#include <asm/byteorder.h>
27 27
28struct sha256_ctx {
29 u64 count;
30 u32 state[8];
31 u8 buf[128];
32};
33
34static inline u32 Ch(u32 x, u32 y, u32 z) 28static inline u32 Ch(u32 x, u32 y, u32 z)
35{ 29{
36 return z ^ (x & (y ^ z)); 30 return z ^ (x & (y ^ z));
@@ -222,7 +216,7 @@ static void sha256_transform(u32 *state, const u8 *input)
222 216
223static int sha224_init(struct shash_desc *desc) 217static int sha224_init(struct shash_desc *desc)
224{ 218{
225 struct sha256_ctx *sctx = shash_desc_ctx(desc); 219 struct sha256_state *sctx = shash_desc_ctx(desc);
226 sctx->state[0] = SHA224_H0; 220 sctx->state[0] = SHA224_H0;
227 sctx->state[1] = SHA224_H1; 221 sctx->state[1] = SHA224_H1;
228 sctx->state[2] = SHA224_H2; 222 sctx->state[2] = SHA224_H2;
@@ -238,7 +232,7 @@ static int sha224_init(struct shash_desc *desc)
238 232
239static int sha256_init(struct shash_desc *desc) 233static int sha256_init(struct shash_desc *desc)
240{ 234{
241 struct sha256_ctx *sctx = shash_desc_ctx(desc); 235 struct sha256_state *sctx = shash_desc_ctx(desc);
242 sctx->state[0] = SHA256_H0; 236 sctx->state[0] = SHA256_H0;
243 sctx->state[1] = SHA256_H1; 237 sctx->state[1] = SHA256_H1;
244 sctx->state[2] = SHA256_H2; 238 sctx->state[2] = SHA256_H2;
@@ -255,7 +249,7 @@ static int sha256_init(struct shash_desc *desc)
255static int sha256_update(struct shash_desc *desc, const u8 *data, 249static int sha256_update(struct shash_desc *desc, const u8 *data,
256 unsigned int len) 250 unsigned int len)
257{ 251{
258 struct sha256_ctx *sctx = shash_desc_ctx(desc); 252 struct sha256_state *sctx = shash_desc_ctx(desc);
259 unsigned int partial, done; 253 unsigned int partial, done;
260 const u8 *src; 254 const u8 *src;
261 255
@@ -286,7 +280,7 @@ static int sha256_update(struct shash_desc *desc, const u8 *data,
286 280
287static int sha256_final(struct shash_desc *desc, u8 *out) 281static int sha256_final(struct shash_desc *desc, u8 *out)
288{ 282{
289 struct sha256_ctx *sctx = shash_desc_ctx(desc); 283 struct sha256_state *sctx = shash_desc_ctx(desc);
290 __be32 *dst = (__be32 *)out; 284 __be32 *dst = (__be32 *)out;
291 __be64 bits; 285 __be64 bits;
292 unsigned int index, pad_len; 286 unsigned int index, pad_len;
@@ -326,12 +320,31 @@ static int sha224_final(struct shash_desc *desc, u8 *hash)
326 return 0; 320 return 0;
327} 321}
328 322
323static int sha256_export(struct shash_desc *desc, void *out)
324{
325 struct sha256_state *sctx = shash_desc_ctx(desc);
326
327 memcpy(out, sctx, sizeof(*sctx));
328 return 0;
329}
330
331static int sha256_import(struct shash_desc *desc, const void *in)
332{
333 struct sha256_state *sctx = shash_desc_ctx(desc);
334
335 memcpy(sctx, in, sizeof(*sctx));
336 return 0;
337}
338
329static struct shash_alg sha256 = { 339static struct shash_alg sha256 = {
330 .digestsize = SHA256_DIGEST_SIZE, 340 .digestsize = SHA256_DIGEST_SIZE,
331 .init = sha256_init, 341 .init = sha256_init,
332 .update = sha256_update, 342 .update = sha256_update,
333 .final = sha256_final, 343 .final = sha256_final,
334 .descsize = sizeof(struct sha256_ctx), 344 .export = sha256_export,
345 .import = sha256_import,
346 .descsize = sizeof(struct sha256_state),
347 .statesize = sizeof(struct sha256_state),
335 .base = { 348 .base = {
336 .cra_name = "sha256", 349 .cra_name = "sha256",
337 .cra_driver_name= "sha256-generic", 350 .cra_driver_name= "sha256-generic",
@@ -346,7 +359,7 @@ static struct shash_alg sha224 = {
346 .init = sha224_init, 359 .init = sha224_init,
347 .update = sha256_update, 360 .update = sha256_update,
348 .final = sha224_final, 361 .final = sha224_final,
349 .descsize = sizeof(struct sha256_ctx), 362 .descsize = sizeof(struct sha256_state),
350 .base = { 363 .base = {
351 .cra_name = "sha224", 364 .cra_name = "sha224",
352 .cra_driver_name= "sha224-generic", 365 .cra_driver_name= "sha224-generic",
diff --git a/include/crypto/sha.h b/include/crypto/sha.h
index 922a248bd04d..88ef5eb9514d 100644
--- a/include/crypto/sha.h
+++ b/include/crypto/sha.h
@@ -70,4 +70,10 @@ struct sha1_state {
70 u8 buffer[SHA1_BLOCK_SIZE]; 70 u8 buffer[SHA1_BLOCK_SIZE];
71}; 71};
72 72
73struct sha256_state {
74 u64 count;
75 u32 state[SHA256_DIGEST_SIZE / 4];
76 u8 buf[SHA256_BLOCK_SIZE];
77};
78
73#endif 79#endif