aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/sha256_generic.c
diff options
context:
space:
mode:
authorJan Glauber <jang@de.ibm.com>2007-10-09 10:43:13 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:55:50 -0400
commit5265eeb2b036835021591173ac64e624baaff55c (patch)
tree0263f8e8db4ead27b6e02f3200e3a1305bbf2080 /crypto/sha256_generic.c
parentad5d27899fdbe7a66e57fdf1af883dbd7ff88dac (diff)
[CRYPTO] sha: Add header file for SHA definitions
There are currently several SHA implementations that all define their own initialization vectors and size values. Since this values are idential move them to a header file under include/crypto. Signed-off-by: Jan Glauber <jang@de.ibm.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/sha256_generic.c')
-rw-r--r--crypto/sha256_generic.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
index 74bf2f95f4e5..5f4332edcf6b 100644
--- a/crypto/sha256_generic.c
+++ b/crypto/sha256_generic.c
@@ -21,12 +21,10 @@
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/crypto.h> 22#include <linux/crypto.h>
23#include <linux/types.h> 23#include <linux/types.h>
24#include <crypto/sha.h>
24#include <asm/scatterlist.h> 25#include <asm/scatterlist.h>
25#include <asm/byteorder.h> 26#include <asm/byteorder.h>
26 27
27#define SHA256_DIGEST_SIZE 32
28#define SHA256_HMAC_BLOCK_SIZE 64
29
30struct sha256_ctx { 28struct sha256_ctx {
31 u32 count[2]; 29 u32 count[2];
32 u32 state[8]; 30 u32 state[8];
@@ -48,15 +46,6 @@ static inline u32 Maj(u32 x, u32 y, u32 z)
48#define s0(x) (ror32(x, 7) ^ ror32(x,18) ^ (x >> 3)) 46#define s0(x) (ror32(x, 7) ^ ror32(x,18) ^ (x >> 3))
49#define s1(x) (ror32(x,17) ^ ror32(x,19) ^ (x >> 10)) 47#define s1(x) (ror32(x,17) ^ ror32(x,19) ^ (x >> 10))
50 48
51#define H0 0x6a09e667
52#define H1 0xbb67ae85
53#define H2 0x3c6ef372
54#define H3 0xa54ff53a
55#define H4 0x510e527f
56#define H5 0x9b05688c
57#define H6 0x1f83d9ab
58#define H7 0x5be0cd19
59
60static inline void LOAD_OP(int I, u32 *W, const u8 *input) 49static inline void LOAD_OP(int I, u32 *W, const u8 *input)
61{ 50{
62 W[I] = __be32_to_cpu( ((__be32*)(input))[I] ); 51 W[I] = __be32_to_cpu( ((__be32*)(input))[I] );
@@ -233,14 +222,14 @@ static void sha256_transform(u32 *state, const u8 *input)
233static void sha256_init(struct crypto_tfm *tfm) 222static void sha256_init(struct crypto_tfm *tfm)
234{ 223{
235 struct sha256_ctx *sctx = crypto_tfm_ctx(tfm); 224 struct sha256_ctx *sctx = crypto_tfm_ctx(tfm);
236 sctx->state[0] = H0; 225 sctx->state[0] = SHA256_H0;
237 sctx->state[1] = H1; 226 sctx->state[1] = SHA256_H1;
238 sctx->state[2] = H2; 227 sctx->state[2] = SHA256_H2;
239 sctx->state[3] = H3; 228 sctx->state[3] = SHA256_H3;
240 sctx->state[4] = H4; 229 sctx->state[4] = SHA256_H4;
241 sctx->state[5] = H5; 230 sctx->state[5] = SHA256_H5;
242 sctx->state[6] = H6; 231 sctx->state[6] = SHA256_H6;
243 sctx->state[7] = H7; 232 sctx->state[7] = SHA256_H7;
244 sctx->count[0] = sctx->count[1] = 0; 233 sctx->count[0] = sctx->count[1] = 0;
245} 234}
246 235
@@ -311,7 +300,7 @@ static struct crypto_alg alg = {
311 .cra_name = "sha256", 300 .cra_name = "sha256",
312 .cra_driver_name= "sha256-generic", 301 .cra_driver_name= "sha256-generic",
313 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 302 .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
314 .cra_blocksize = SHA256_HMAC_BLOCK_SIZE, 303 .cra_blocksize = SHA256_BLOCK_SIZE,
315 .cra_ctxsize = sizeof(struct sha256_ctx), 304 .cra_ctxsize = sizeof(struct sha256_ctx),
316 .cra_module = THIS_MODULE, 305 .cra_module = THIS_MODULE,
317 .cra_alignmask = 3, 306 .cra_alignmask = 3,