Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5265eeb2 authored by Jan Glauber's avatar Jan Glauber Committed by David S. Miller
Browse files

[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: default avatarJan Glauber <jang@de.ibm.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent ad5d2789
Loading
Loading
Loading
Loading
+6 −8
Original line number Diff line number Diff line
@@ -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 *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;
}

+9 −11
Original line number Diff line number Diff line
@@ -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_tfm *tfm)
{
	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;
}

+3 −5
Original line number Diff line number Diff line
@@ -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_tfm *tfm)
	struct 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,
+10 −21
Original line number Diff line number Diff line
@@ -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 z)
#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, const u8 *input)
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,
+19 −44
Original line number Diff line number Diff line
@@ -13,20 +13,15 @@

#include <linux/kernel.h>
#include <linux/module.h>

#include <linux/mm.h>
#include <linux/init.h>
#include <linux/crypto.h>
#include <linux/types.h>
#include <crypto/sha.h>

#include <asm/scatterlist.h>
#include <asm/byteorder.h>

#define SHA384_DIGEST_SIZE 48
#define SHA512_DIGEST_SIZE 64
#define SHA384_HMAC_BLOCK_SIZE 128
#define SHA512_HMAC_BLOCK_SIZE 128

struct sha512_ctx {
	u64 state[8];
	u32 count[4];
@@ -84,26 +79,6 @@ static const u64 sha512_K[80] = {
#define s0(x)       (RORu64(x, 1) ^ RORu64(x, 8) ^ (x >> 7))
#define s1(x)       (RORu64(x,19) ^ RORu64(x,61) ^ (x >> 6))

/* H* initial state for SHA-512 */
#define H0         0x6a09e667f3bcc908ULL
#define H1         0xbb67ae8584caa73bULL
#define H2         0x3c6ef372fe94f82bULL
#define H3         0xa54ff53a5f1d36f1ULL
#define H4         0x510e527fade682d1ULL
#define H5         0x9b05688c2b3e6c1fULL
#define H6         0x1f83d9abfb41bd6bULL
#define H7         0x5be0cd19137e2179ULL

/* H'* initial state for SHA-384 */
#define HP0 0xcbbb9d5dc1059ed8ULL
#define HP1 0x629a292a367cd507ULL
#define HP2 0x9159015a3070dd17ULL
#define HP3 0x152fecd8f70e5939ULL
#define HP4 0x67332667ffc00b31ULL
#define HP5 0x8eb44a8768581511ULL
#define HP6 0xdb0c2e0d64f98fa7ULL
#define HP7 0x47b5481dbefa4fa4ULL

static inline void LOAD_OP(int I, u64 *W, const u8 *input)
{
	W[I] = __be64_to_cpu( ((__be64*)(input))[I] );
@@ -164,14 +139,14 @@ static void
sha512_init(struct crypto_tfm *tfm)
{
	struct sha512_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] = SHA512_H0;
	sctx->state[1] = SHA512_H1;
	sctx->state[2] = SHA512_H2;
	sctx->state[3] = SHA512_H3;
	sctx->state[4] = SHA512_H4;
	sctx->state[5] = SHA512_H5;
	sctx->state[6] = SHA512_H6;
	sctx->state[7] = SHA512_H7;
	sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0;
}

@@ -179,14 +154,14 @@ static void
sha384_init(struct crypto_tfm *tfm)
{
	struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
        sctx->state[0] = HP0;
        sctx->state[1] = HP1;
        sctx->state[2] = HP2;
        sctx->state[3] = HP3;
        sctx->state[4] = HP4;
        sctx->state[5] = HP5;
        sctx->state[6] = HP6;
        sctx->state[7] = HP7;
	sctx->state[0] = SHA384_H0;
	sctx->state[1] = SHA384_H1;
	sctx->state[2] = SHA384_H2;
	sctx->state[3] = SHA384_H3;
	sctx->state[4] = SHA384_H4;
	sctx->state[5] = SHA384_H5;
	sctx->state[6] = SHA384_H6;
	sctx->state[7] = SHA384_H7;
        sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0;
}

@@ -275,7 +250,7 @@ static void sha384_final(struct crypto_tfm *tfm, u8 *hash)
static struct crypto_alg sha512 = {
        .cra_name       = "sha512",
        .cra_flags      = CRYPTO_ALG_TYPE_DIGEST,
        .cra_blocksize  = SHA512_HMAC_BLOCK_SIZE,
	.cra_blocksize  = SHA512_BLOCK_SIZE,
        .cra_ctxsize    = sizeof(struct sha512_ctx),
        .cra_module     = THIS_MODULE,
	.cra_alignmask	= 3,
@@ -291,7 +266,7 @@ static struct crypto_alg sha512 = {
static struct crypto_alg sha384 = {
        .cra_name       = "sha384",
        .cra_flags      = CRYPTO_ALG_TYPE_DIGEST,
        .cra_blocksize  = SHA384_HMAC_BLOCK_SIZE,
	.cra_blocksize  = SHA384_BLOCK_SIZE,
        .cra_ctxsize    = sizeof(struct sha512_ctx),
	.cra_alignmask	= 3,
        .cra_module     = THIS_MODULE,
Loading