header file for SHA definitions
Subsystems (3)
RFC PATCH 1/1 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.
The Patch should apply to cryptodev-2.6.
Signed-off-by Jan Glauber <[email protected]>
--- arch/s390/crypto/sha1_s390.c | 14 +++------ arch/s390/crypto/sha256_s390.c | 20 +++++-------- crypto/sha1_generic.c | 8 +---- crypto/sha256_generic.c | 31 ++++++-------------- crypto/sha512.c | 63 ++++++++++++----------------------------- drivers/crypto/padlock-sha.c | 36 ++++++++++------------- include/crypto/sha.h | 53 ++++++++++++++++++++++++++++++++++ 7 files changed, 116 insertions(+), 109 deletions(-)
arch/s390/crypto/sha1_s390.c +6 -8
@@ -26,12 +26,10 @@#include <linux/init.h> #include <linux/module.h> #include <linux/crypto.h> +#include <crypto/sha.h> #include "crypt_s390.h" -#define SHA1_DIGEST_SIZE 20 -#define SHA1_BLOCK_SIZE 64 -struct s390_sha1_ctx {u64 count;/* message length */ u32 state[5 ];
@@ -42,11 +40,11 @@ static void sha1_init(struct crypto_tfm {struct s390_sha1_ctx *sctx =crypto_tfm_ctx (tfm); - sctx->state[0 ] =0x67452301 ; - sctx->state[1 ] =0xEFCDAB89 ; - sctx->state[2 ] =0x98BADCFE ; - sctx->state[3 ] =0x10325476 ; - sctx->state[4 ] =0xC3D2E1F0 ; + sctx->state[0 ] =SHA1_H0 ; + sctx->state[1 ] =SHA1_H1 ; + sctx->state[2 ] =SHA1_H2 ; + sctx->state[3 ] =SHA1_H3 ; + sctx->state[4 ] =SHA1_H4 ; sctx->count =0 ; }
arch/s390/crypto/sha256_s390.c +9 -11
@@ -19,12 +19,10 @@#include <linux/init.h> #include <linux/module.h> #include <linux/crypto.h> +#include <crypto/sha.h> #include "crypt_s390.h" -#define SHA256_DIGEST_SIZE 32 -#define SHA256_BLOCK_SIZE 64 -struct s390_sha256_ctx {u64 count;/* message length */ u32 state[8 ];
@@ -35,14 +33,14 @@ static void sha256_init(struct crypto_tf {struct s390_sha256_ctx *sctx =crypto_tfm_ctx (tfm); - sctx->state[0 ] =0x6a09e667 ; - sctx->state[1 ] =0xbb67ae85 ; - sctx->state[2 ] =0x3c6ef372 ; - sctx->state[3 ] =0xa54ff53a ; - sctx->state[4 ] =0x510e527f ; - sctx->state[5 ] =0x9b05688c ; - sctx->state[6 ] =0x1f83d9ab ; - sctx->state[7 ] =0x5be0cd19 ; + sctx->state[0 ] =SHA256_H0 ; + sctx->state[1 ] =SHA256_H1 ; + sctx->state[2 ] =SHA256_H2 ; + sctx->state[3 ] =SHA256_H3 ; + sctx->state[4 ] =SHA256_H4 ; + sctx->state[5 ] =SHA256_H5 ; + sctx->state[6 ] =SHA256_H6 ; + sctx->state[7 ] =SHA256_H7 ; sctx->count =0 ; }
crypto/sha1_generic.c +3 -5
@@ -22,12 +22,10 @@#include <linux/crypto.h> #include <linux/cryptohash.h> #include <linux/types.h> +#include <crypto/sha.h> #include <asm/scatterlist.h> #include <asm/byteorder.h> -#define SHA1_DIGEST_SIZE 20 -#define SHA1_HMAC_BLOCK_SIZE 64 -struct sha1_ctx {u64 count;u32 state[5 ];
@@ -39,7 +37,7 @@ static void sha1_init(struct crypto_tfmstruct sha1_ctx *sctx =crypto_tfm_ctx (tfm);static const struct sha1_ctx initstate = {0 , - {0x67452301 ,0xEFCDAB89 ,0x98BADCFE ,0x10325476 ,0xC3D2E1F0 }, + {SHA1_H0 ,SHA1_H1 ,SHA1_H2 ,SHA1_H3 ,SHA1_H4 }, {0 , } };
@@ -111,7 +109,7 @@ static struct crypto_alg alg = { .cra_name = "sha1", .cra_driver_name= "sha1-generic", .cra_flags = CRYPTO_ALG_TYPE_DIGEST, - .cra_blocksize = SHA1_HMAC_BLOCK_SIZE, + .cra_blocksize = SHA1_BLOCK_SIZE, .cra_ctxsize = sizeof(struct sha1_ctx), .cra_module = THIS_MODULE, .cra_alignmask = 3,
crypto/sha256_generic.c +10 -21
@@ -21,12 +21,10 @@#include <linux/mm.h> #include <linux/crypto.h> #include <linux/types.h> +#include <crypto/sha.h> #include <asm/scatterlist.h> #include <asm/byteorder.h> -#define SHA256_DIGEST_SIZE 32 -#define SHA256_HMAC_BLOCK_SIZE 64 -struct sha256_ctx {u32 count[2 ];u32 state[8 ];
@@ -48,15 +46,6 @@ static inline u32 Maj(u32 x, u32 y, u32#define s0 (x) (ror32(x, 7) ^ ror32(x,18) ^ (x >> 3))#define s1 (x) (ror32(x,17) ^ ror32(x,19) ^ (x >> 10)) -#define H0 0x6a09e667 -#define H1 0xbb67ae85 -#define H2 0x3c6ef372 -#define H3 0xa54ff53a -#define H4 0x510e527f -#define H5 0x9b05688c -#define H6 0x1f83d9ab -#define H7 0x5be0cd19 -static inline void LOAD_OP (int I ,u32 *W ,const u8 *input) {W [I ] =__be32_to_cpu ( ((__be32 *)(input))[I ] );
@@ -233,14 +222,14 @@ static void sha256_transform(u32 *state,static void sha256_init (struct crypto_tfm *tfm) {struct sha256_ctx *sctx =crypto_tfm_ctx (tfm); - sctx->state[0 ] =H0 ; - sctx->state[1 ] =H1 ; - sctx->state[2 ] =H2 ; - sctx->state[3 ] =H3 ; - sctx->state[4 ] =H4 ; - sctx->state[5 ] =H5 ; - sctx->state[6 ] =H6 ; - sctx->state[7 ] =H7 ; + sctx->state[0 ] =SHA256_H0 ; + sctx->state[1 ] =SHA256_H1 ; + sctx->state[2 ] =SHA256_H2 ; + sctx->state[3 ] =SHA256_H3 ; + sctx->state[4 ] =SHA256_H4 ; + sctx->state[5 ] =SHA256_H5 ; + sctx->state[6 ] =SHA256_H6 ; + sctx->state[7 ] =SHA256_H7 ; sctx->count[0 ] = sctx->count[1 ] =0 ; }
@@ -311,7 +300,7 @@ static struct crypto_alg alg = { .cra_name = "sha256", .cra_driver_name= "sha256-generic", .cra_flags = CRYPTO_ALG_TYPE_DIGEST, - .cra_blocksize = SHA256_HMAC_BLOCK_SIZE, + .cra_blocksize = SHA256_BLOCK_SIZE, .cra_ctxsize = sizeof(struct sha256_ctx), .cra_module = THIS_MODULE, .cra_alignmask = 3,
crypto/sha512.c +19 -44
107 lines not on this page · raw message
drivers/crypto/padlock-sha.c +16 -20
@@ -13,6 +13,7 @@*/ #include <crypto/algapi.h> +#include <crypto/sha.h> #include <linux/err.h> #include <linux/module.h> #include <linux/init.h>
@@ -24,12 +25,7 @@#include "padlock.h" #define SHA1_DEFAULT_FALLBACK "sha1-generic" -#define SHA1_DIGEST_SIZE 20 -#define SHA1_HMAC_BLOCK_SIZE 64 -#define SHA256_DEFAULT_FALLBACK "sha256-generic" -#define SHA256_DIGEST_SIZE 32 -#define SHA256_HMAC_BLOCK_SIZE 64struct padlock_sha_ctx {char *data;
@@ -107,11 +103,11 @@ static void padlock_do_sha1(const char *char buf[128 +16 ];char *result =NEAREST_ALIGNED (buf); - ((uint32_t *)result)[0 ] =0x67452301 ; - ((uint32_t *)result)[1 ] =0xEFCDAB89 ; - ((uint32_t *)result)[2 ] =0x98BADCFE ; - ((uint32_t *)result)[3 ] =0x10325476 ; - ((uint32_t *)result)[4 ] =0xC3D2E1F0 ; + ((uint32_t *)result)[0 ] =SHA1_H0 ; + ((uint32_t *)result)[1 ] =SHA1_H1 ; + ((uint32_t *)result)[2 ] =SHA1_H2 ; + ((uint32_t *)result)[3 ] =SHA1_H3 ; + ((uint32_t *)result)[4 ] =SHA1_H4 ; asmvolatile (".byte 0xf3,0x0f,0xa6,0xc8" /* rep xsha1 */ : "+S"(in), "+D"(result)
@@ -128,14 +124,14 @@ static void padlock_do_sha256(const charchar buf[128 +16 ];char *result =NEAREST_ALIGNED (buf); - ((uint32_t *)result)[0 ] =0x6A09E667 ; - ((uint32_t *)result)[1 ] =0xBB67AE85 ; - ((uint32_t *)result)[2 ] =0x3C6EF372 ; - ((uint32_t *)result)[3 ] =0xA54FF53A ; - ((uint32_t *)result)[4 ] =0x510E527F ; - ((uint32_t *)result)[5 ] =0x9B05688C ; - ((uint32_t *)result)[6 ] =0x1F83D9AB ; - ((uint32_t *)result)[7 ] =0x5BE0CD19 ; + ((uint32_t *)result)[0 ] =SHA256_H0 ; + ((uint32_t *)result)[1 ] =SHA256_H1 ; + ((uint32_t *)result)[2 ] =SHA256_H2 ; + ((uint32_t *)result)[3 ] =SHA256_H3 ; + ((uint32_t *)result)[4 ] =SHA256_H4 ; + ((uint32_t *)result)[5 ] =SHA256_H5 ; + ((uint32_t *)result)[6 ] =SHA256_H6 ; + ((uint32_t *)result)[7 ] =SHA256_H7 ; asmvolatile (".byte 0xf3,0x0f,0xa6,0xd0" /* rep xsha256 */ : "+S"(in), "+D"(result)
@@ -215,7 +211,7 @@ static struct crypto_alg sha1_alg = { .cra_priority = PADLOCK_CRA_PRIORITY, .cra_flags =CRYPTO_ALG_TYPE_DIGEST | CRYPTO_ALG_NEED_FALLBACK, - .cra_blocksize = SHA1_HMAC_BLOCK_SIZE, + .cra_blocksize = SHA1_BLOCK_SIZE, .cra_ctxsize = sizeof(struct padlock_sha_ctx), .cra_module = THIS_MODULE, .cra_list = LIST_HEAD_INIT(sha1_alg.cra_list),
@@ -237,7 +233,7 @@ static struct crypto_alg sha256_alg = { .cra_priority = PADLOCK_CRA_PRIORITY, .cra_flags =CRYPTO_ALG_TYPE_DIGEST | CRYPTO_ALG_NEED_FALLBACK, - .cra_blocksize = SHA256_HMAC_BLOCK_SIZE, + .cra_blocksize = SHA256_BLOCK_SIZE, .cra_ctxsize = sizeof(struct padlock_sha_ctx), .cra_module = THIS_MODULE, .cra_list = LIST_HEAD_INIT(sha256_alg.cra_list),
include/crypto/sha.h +53 -0
53 lines not on this page · raw message
Herbert Xu
maintainerQuoted 7 lines · Jan Glauber
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.The Patch should apply to cryptodev-2.6.
Signed-off-by Jan Glauber <[email protected]>
Looks good. Patch applied. Thanks Jan!
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt