aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/sha512.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/sha512.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/sha512.c')
-rw-r--r--crypto/sha512.c63
1 files changed, 19 insertions, 44 deletions
diff --git a/crypto/sha512.c b/crypto/sha512.c
index 15eab9db9be4..e736596ca574 100644
--- a/crypto/sha512.c
+++ b/crypto/sha512.c
@@ -13,20 +13,15 @@
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h> 15#include <linux/module.h>
16
17#include <linux/mm.h> 16#include <linux/mm.h>
18#include <linux/init.h> 17#include <linux/init.h>
19#include <linux/crypto.h> 18#include <linux/crypto.h>
20#include <linux/types.h> 19#include <linux/types.h>
20#include <crypto/sha.h>
21 21
22#include <asm/scatterlist.h> 22#include <asm/scatterlist.h>
23#include <asm/byteorder.h> 23#include <asm/byteorder.h>
24 24
25#define SHA384_DIGEST_SIZE 48
26#define SHA512_DIGEST_SIZE 64
27#define SHA384_HMAC_BLOCK_SIZE 128
28#define SHA512_HMAC_BLOCK_SIZE 128
29
30struct sha512_ctx { 25struct sha512_ctx {
31 u64 state[8]; 26 u64 state[8];
32 u32 count[4]; 27 u32 count[4];
@@ -84,26 +79,6 @@ static const u64 sha512_K[80] = {
84#define s0(x) (RORu64(x, 1) ^ RORu64(x, 8) ^ (x >> 7)) 79#define s0(x) (RORu64(x, 1) ^ RORu64(x, 8) ^ (x >> 7))
85#define s1(x) (RORu64(x,19) ^ RORu64(x,61) ^ (x >> 6)) 80#define s1(x) (RORu64(x,19) ^ RORu64(x,61) ^ (x >> 6))
86 81
87/* H* initial state for SHA-512 */
88#define H0 0x6a09e667f3bcc908ULL
89#define H1 0xbb67ae8584caa73bULL
90#define H2 0x3c6ef372fe94f82bULL
91#define H3 0xa54ff53a5f1d36f1ULL
92#define H4 0x510e527fade682d1ULL
93#define H5 0x9b05688c2b3e6c1fULL
94#define H6 0x1f83d9abfb41bd6bULL
95#define H7 0x5be0cd19137e2179ULL
96
97/* H'* initial state for SHA-384 */
98#define HP0 0xcbbb9d5dc1059ed8ULL
99#define HP1 0x629a292a367cd507ULL
100#define HP2 0x9159015a3070dd17ULL
101#define HP3 0x152fecd8f70e5939ULL
102#define HP4 0x67332667ffc00b31ULL
103#define HP5 0x8eb44a8768581511ULL
104#define HP6 0xdb0c2e0d64f98fa7ULL
105#define HP7 0x47b5481dbefa4fa4ULL
106
107static inline void LOAD_OP(int I, u64 *W, const u8 *input) 82static inline void LOAD_OP(int I, u64 *W, const u8 *input)
108{ 83{
109 W[I] = __be64_to_cpu( ((__be64*)(input))[I] ); 84 W[I] = __be64_to_cpu( ((__be64*)(input))[I] );
@@ -164,14 +139,14 @@ static void
164sha512_init(struct crypto_tfm *tfm) 139sha512_init(struct crypto_tfm *tfm)
165{ 140{
166 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm); 141 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
167 sctx->state[0] = H0; 142 sctx->state[0] = SHA512_H0;
168 sctx->state[1] = H1; 143 sctx->state[1] = SHA512_H1;
169 sctx->state[2] = H2; 144 sctx->state[2] = SHA512_H2;
170 sctx->state[3] = H3; 145 sctx->state[3] = SHA512_H3;
171 sctx->state[4] = H4; 146 sctx->state[4] = SHA512_H4;
172 sctx->state[5] = H5; 147 sctx->state[5] = SHA512_H5;
173 sctx->state[6] = H6; 148 sctx->state[6] = SHA512_H6;
174 sctx->state[7] = H7; 149 sctx->state[7] = SHA512_H7;
175 sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; 150 sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0;
176} 151}
177 152
@@ -179,14 +154,14 @@ static void
179sha384_init(struct crypto_tfm *tfm) 154sha384_init(struct crypto_tfm *tfm)
180{ 155{
181 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm); 156 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
182 sctx->state[0] = HP0; 157 sctx->state[0] = SHA384_H0;
183 sctx->state[1] = HP1; 158 sctx->state[1] = SHA384_H1;
184 sctx->state[2] = HP2; 159 sctx->state[2] = SHA384_H2;
185 sctx->state[3] = HP3; 160 sctx->state[3] = SHA384_H3;
186 sctx->state[4] = HP4; 161 sctx->state[4] = SHA384_H4;
187 sctx->state[5] = HP5; 162 sctx->state[5] = SHA384_H5;
188 sctx->state[6] = HP6; 163 sctx->state[6] = SHA384_H6;
189 sctx->state[7] = HP7; 164 sctx->state[7] = SHA384_H7;
190 sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; 165 sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0;
191} 166}
192 167
@@ -275,7 +250,7 @@ static void sha384_final(struct crypto_tfm *tfm, u8 *hash)
275static struct crypto_alg sha512 = { 250static struct crypto_alg sha512 = {
276 .cra_name = "sha512", 251 .cra_name = "sha512",
277 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 252 .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
278 .cra_blocksize = SHA512_HMAC_BLOCK_SIZE, 253 .cra_blocksize = SHA512_BLOCK_SIZE,
279 .cra_ctxsize = sizeof(struct sha512_ctx), 254 .cra_ctxsize = sizeof(struct sha512_ctx),
280 .cra_module = THIS_MODULE, 255 .cra_module = THIS_MODULE,
281 .cra_alignmask = 3, 256 .cra_alignmask = 3,
@@ -291,7 +266,7 @@ static struct crypto_alg sha512 = {
291static struct crypto_alg sha384 = { 266static struct crypto_alg sha384 = {
292 .cra_name = "sha384", 267 .cra_name = "sha384",
293 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 268 .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
294 .cra_blocksize = SHA384_HMAC_BLOCK_SIZE, 269 .cra_blocksize = SHA384_BLOCK_SIZE,
295 .cra_ctxsize = sizeof(struct sha512_ctx), 270 .cra_ctxsize = sizeof(struct sha512_ctx),
296 .cra_alignmask = 3, 271 .cra_alignmask = 3,
297 .cra_module = THIS_MODULE, 272 .cra_module = THIS_MODULE,