aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
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
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')
-rw-r--r--crypto/sha1_generic.c8
-rw-r--r--crypto/sha256_generic.c31
-rw-r--r--crypto/sha512.c63
3 files changed, 32 insertions, 70 deletions
diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c
index 70364dd5c45a..48a3c3e0bf5f 100644
--- a/crypto/sha1_generic.c
+++ b/crypto/sha1_generic.c
@@ -22,12 +22,10 @@
22#include <linux/crypto.h> 22#include <linux/crypto.h>
23#include <linux/cryptohash.h> 23#include <linux/cryptohash.h>
24#include <linux/types.h> 24#include <linux/types.h>
25#include <crypto/sha.h>
25#include <asm/scatterlist.h> 26#include <asm/scatterlist.h>
26#include <asm/byteorder.h> 27#include <asm/byteorder.h>
27 28
28#define SHA1_DIGEST_SIZE 20
29#define SHA1_HMAC_BLOCK_SIZE 64
30
31struct sha1_ctx { 29struct sha1_ctx {
32 u64 count; 30 u64 count;
33 u32 state[5]; 31 u32 state[5];
@@ -39,7 +37,7 @@ static void sha1_init(struct crypto_tfm *tfm)
39 struct sha1_ctx *sctx = crypto_tfm_ctx(tfm); 37 struct sha1_ctx *sctx = crypto_tfm_ctx(tfm);
40 static const struct sha1_ctx initstate = { 38 static const struct sha1_ctx initstate = {
41 0, 39 0,
42 { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }, 40 { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 },
43 { 0, } 41 { 0, }
44 }; 42 };
45 43
@@ -111,7 +109,7 @@ static struct crypto_alg alg = {
111 .cra_name = "sha1", 109 .cra_name = "sha1",
112 .cra_driver_name= "sha1-generic", 110 .cra_driver_name= "sha1-generic",
113 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 111 .cra_flags = CRYPTO_ALG_TYPE_DIGEST,
114 .cra_blocksize = SHA1_HMAC_BLOCK_SIZE, 112 .cra_blocksize = SHA1_BLOCK_SIZE,
115 .cra_ctxsize = sizeof(struct sha1_ctx), 113 .cra_ctxsize = sizeof(struct sha1_ctx),
116 .cra_module = THIS_MODULE, 114 .cra_module = THIS_MODULE,
117 .cra_alignmask = 3, 115 .cra_alignmask = 3,
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,
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,