Skip to contentSkip to conversation

Switch remaining algorithms to shash

PATCH Superseded Adrian-Ken Rueegsegger 3 participants 23 messages Dec 4, 2008 – Dec 17, 2008 1 message not in the archive Crypto API

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

v2 cover Switch remaining algorithms to shash

This series contains the fixed up patches to convert the remaining hash algorithms to use the new shash interface.

The first patch is left unchanged and removes the message schedule W from struct sha512_ctx.

The last three patches now contain the needed Kconfig dependencies.

Adrian

#2 lore raw

PATCH v2 1/4 crypto: sha512 - Remove W (message schedule) from struct sha512_ctx

The message schedule W[80] is calculated anew when sha512_transform is executed. Therefore it is local to that function and does not need to be defined in struct sha512_ctx.
Note: the sha256 algorithm already does it this way.

---
 crypto/sha512_generic.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
crypto/sha512_generic.c +5 -5
index bc36861..e0b0303 100644
@@ -25,7 +25,6 @@ struct sha512_ctx {
 	u64 state[8];
 	u32 count[4];
 	u8 buf[128];
-	u64 W[80];
 };
 
 static inline u64 Ch(u64 x, u64 y, u64 z)
@@ -89,10 +88,10 @@ static inline void BLEND_OP(int I, u64 *W)
 }
 
 static void
-sha512_transform(u64 *state, u64 *W, const u8 *input)
+sha512_transform(u64 *state, const u8 *input)
 {
 	u64 a, b, c, d, e, f, g, h, t1, t2;
-
+	u64 W[80];
 	int i;
 
 	/* load the input */
@@ -132,6 +131,7 @@ sha512_transform(u64 *state, u64 *W, const u8 *input)
 
 	/* erase our data */
 	a = b = c = d = e = f = g = h = t1 = t2 = 0;
+	memset(W, 0, 80 * sizeof(u64));
 }
 
 static void
@@ -187,10 +187,10 @@ sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
 	/* Transform as many times as possible. */
 	if (len >= part_len) {
 		memcpy(&sctx->buf[index], data, part_len);
-		sha512_transform(sctx->state, sctx->W, sctx->buf);
+		sha512_transform(sctx->state, sctx->buf);
 
 		for (i = part_len; i + 127 < len; i+=128)
-			sha512_transform(sctx->state, sctx->W, &data[i]);
+			sha512_transform(sctx->state, &data[i]);
 
 		index = 0;
 	} else {
@@ -199,9 +199,6 @@ sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
 
 	/* Buffer remaining input */
 	memcpy(&sctx->buf[index], &data[i], len - i);
#3 lore raw

PATCH v2 2/4 crypto: sha512 - Switch to shash

This patch changes sha512 and sha384 to the new shash interface.

---
 crypto/Kconfig          |    2 +-
 crypto/sha512_generic.c |  107 ++++++++++++++++++++++++----------------------
 2 files changed, 57 insertions(+), 52 deletions(-)
crypto/Kconfig +1 -1
index eb0b3db..372805c 100644
@@ -340,7 +340,7 @@ config CRYPTO_SHA256
 
 config CRYPTO_SHA512
 	tristate "SHA384 and SHA512 digest algorithms"
-	select CRYPTO_ALGAPI
+	select CRYPTO_HASH
 	help
 	  SHA512 secure hash standard (DFIPS 180-2).
 
crypto/sha512_generic.c +56 -51

190 lines not on this page · raw message

Signature · 1 line
1.5.2.5
#4 lore raw

PATCH v2 3/4 crypto: wp512 - Switch to shash

This patch changes wp512, wp384 and wp256 to the new shash interface.

---
 crypto/Kconfig |    2 +-
 crypto/wp512.c |  121 ++++++++++++++++++++++++++++++--------------------------
 2 files changed, 66 insertions(+), 57 deletions(-)
crypto/Kconfig +1 -1
index 372805c..e2b903d 100644
@@ -365,7 +365,7 @@ config CRYPTO_TGR192
 
 config CRYPTO_WP512
 	tristate "Whirlpool digest algorithms"
-	select CRYPTO_ALGAPI
+	select CRYPTO_HASH
 	help
 	  Whirlpool hash algorithm 512, 384 and 256-bit hashes
 
crypto/wp512.c +65 -56

205 lines not on this page · raw message

Signature · 1 line
1.5.2.5
#5 lore raw

PATCH v2 4/4 crypto: michael_mic - Switch to shash

This patch changes michael_mic to the new shash interface.

---
 crypto/Kconfig       |    2 +-
 crypto/michael_mic.c |   72 ++++++++++++++++++++++++++++---------------------
 2 files changed, 42 insertions(+), 32 deletions(-)
crypto/Kconfig +1 -1
index e2b903d..9003f11 100644
@@ -259,7 +259,7 @@ config CRYPTO_MD5
 
 config CRYPTO_MICHAEL_MIC
 	tristate "Michael MIC keyed digest algorithm"
-	select CRYPTO_ALGAPI
+	select CRYPTO_HASH
 	help
 	  Michael MIC is used for message integrity protection in TKIP
 	  (IEEE 802.11i). This algorithm is required for TKIP, but it
crypto/michael_mic.c +39 -28

135 lines not on this page · raw message

maintainer
#6 lore raw

Re: [PATCH 1/4 v2] crypto: sha512 - Remove W (message schedule) from struct sha512_ctx

In reply to Adrian-Ken Rueegsegger

crypto/sha512_generic.c static inline void BLEND_OP(int I, u64 *W) · line 94

Quoted 8 lines · Adrian-Ken Rueegsegger

static void

crypto/sha512_generic.c +2 -2
-sha512_transform(u64 *state, u64 *W, const u8 *input)
+sha512_transform(u64 *state, const u8 *input)
 {
 	u64 a, b, c, d, e, f, g, h, t1, t2;
-
+	u64 W[80];

This is too big for the stack. So we need to put it somewhere else. A static per-cpu area is one choice.

Cheers,

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
#7 lore raw

Re: [PATCH 1/4 v2] crypto: sha512 - Remove W (message schedule) from struct sha512_ctx

Quoted 11 lines · Herbert Xu

crypto/sha512_generic.c static inline void BLEND_OP(int I, u64 *W) · line 94

Quoted 7 lines · Adrian-Ken Rueegsegger

static void

crypto/sha512_generic.c +2 -2
-sha512_transform(u64 *state, u64 *W, const u8 *input)
+sha512_transform(u64 *state, const u8 *input)
 {
 	u64 a, b, c, d, e, f, g, h, t1, t2;
-
+	u64 W[80];

This is too big for the stack. So we need to put it somewhere else. A static per-cpu area is one choice.

Yes, sorry about that. I didn't properly read your previous mail. I will redo the sha512 patches.

Thanks for the review,
Adrian

#8 lore raw

v3 cover Switch remaining algorithms to shash

In reply to Herbert Xu

This series contains the fixed up patches to convert the remaining hash algorithms to use shash.

The first patch now moves the message schedule W from struct sha512_ctx to a static percpu area.

The sha512 patch is adjusted to accomodate the changes from patch 1 while the last two patches remain unchanged since v2.

Adrian

#9 lore raw

PATCH v3 1/4 crypto: sha512 - Move message schedule W[80] to static percpu area

The message schedule W (u64[80]) is too big for the stack. In order for this algorithm to be used with shash it is moved to a static percpu area.

---
 crypto/sha512_generic.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
crypto/sha512_generic.c +9 -5
index bc36861..660c5c3 100644
@@ -18,16 +18,17 @@
 #include <linux/crypto.h>
 #include <linux/types.h>
 #include <crypto/sha.h>
-
+#include <linux/percpu.h>
 #include <asm/byteorder.h>
 
 struct sha512_ctx {
 	u64 state[8];
 	u32 count[4];
 	u8 buf[128];
-	u64 W[80];
 };
 
+static DEFINE_PER_CPU(u64[80], msg_schedule);
+
 static inline u64 Ch(u64 x, u64 y, u64 z)
 {
         return z ^ (x & (y ^ z));
@@ -89,11 +90,12 @@ static inline void BLEND_OP(int I, u64 *W)
 }
 
 static void
-sha512_transform(u64 *state, u64 *W, const u8 *input)
+sha512_transform(u64 *state, const u8 *input)
 {
 	u64 a, b, c, d, e, f, g, h, t1, t2;
 
 	int i;
+	u64 *W = __get_cpu_var(msg_schedule);
 
 	/* load the input */
         for (i = 0; i < 16; i++)
@@ -132,6 +134,8 @@ sha512_transform(u64 *state, u64 *W, const u8 *input)
 
 	/* erase our data */
 	a = b = c = d = e = f = g = h = t1 = t2 = 0;
+	memset(W, 0, sizeof(__get_cpu_var(msg_schedule)));
+	put_cpu_var(msg_schedule);
 }
 
 static void
@@ -187,10 +191,10 @@ sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
 	/* Transform as many times as possible. */
 	if (len >= part_len) {
 		memcpy(&sctx->buf[index], data, part_len);
-		sha512_transform(sctx->state, sctx->W, sctx->buf);
+		sha512_transform(sctx->state, sctx->buf);
 
 		for (i = part_len; i + 127 < len; i+=128)
-			sha512_transform(sctx->state, sctx->W, &data[i]);
+			sha512_transform(sctx->state, &data[i]);
 
 		index = 0;
 	} else {
@@ -199,9 +203,6 @@ sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
 
 	/* Buffer remaining input */
 	memcpy(&sctx->buf[index], &data[i], len - i);
#10 lore raw

PATCH v3 2/4 crypto: sha512 - Switch to shash

This patch changes sha512 and sha384 to the new shash interface.

---
 crypto/sha512_generic.c |  112 +++++++++++++++++++++++++----------------------
 1 files changed, 59 insertions(+), 53 deletions(-)
crypto/sha512_generic.c +59 -53
index 660c5c3..ec9cef3 100644
@@ -10,7 +10,7 @@
  * later version.
  *
  */
-
+#include <crypto/internal/hash.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/mm.h>
@@ -138,10 +138,10 @@ sha512_transform(u64 *state, const u8 *input)
 	put_cpu_var(msg_schedule);
 }
 
-static void
-sha512_init(struct crypto_tfm *tfm)
+static int
+sha512_init(struct shash_desc *desc)
 {
-	struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
+	struct sha512_ctx *sctx = shash_desc_ctx(desc);
 	sctx->state[0] = SHA512_H0;
 	sctx->state[1] = SHA512_H1;
 	sctx->state[2] = SHA512_H2;
@@ -151,12 +151,14 @@ sha512_init(struct crypto_tfm *tfm)
 	sctx->state[6] = SHA512_H6;
 	sctx->state[7] = SHA512_H7;
 	sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0;
+
+	return 0;
 }
 
-static void
-sha384_init(struct crypto_tfm *tfm)
+static int
+sha384_init(struct shash_desc *desc)
 {
-	struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
+	struct sha512_ctx *sctx = shash_desc_ctx(desc);
 	sctx->state[0] = SHA384_H0;
 	sctx->state[1] = SHA384_H1;
 	sctx->state[2] = SHA384_H2;
@@ -166,12 +168,14 @@ sha384_init(struct crypto_tfm *tfm)
 	sctx->state[6] = SHA384_H6;
 	sctx->state[7] = SHA384_H7;
         sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0;
+
+	return 0;
 }
 
-static void
-sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
+static int
+sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len)
 {
-	struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
+	struct sha512_ctx *sctx = shash_desc_ctx(desc);
 
 	unsigned int i, index, part_len;
 
@@ -203,12 +207,14 @@ sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
 
 	/* Buffer remaining input */
 	memcpy(&sctx->buf[index], &data[i], len - i);
+
+	return 0;
 }
 
-static void
-sha512_final(struct crypto_tfm *tfm, u8 *hash)
+static int
+sha512_final(struct shash_desc *desc, u8 *hash)
 {
-	struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
+	struct sha512_ctx *sctx = shash_desc_ctx(desc);
         static u8 padding[128] = { 0x80, };
 	__be64 *dst = (__be64 *)hash;
 	__be32 bits[4];
@@ -224,10 +230,10 @@ sha512_final(struct crypto_tfm *tfm, u8 *hash)
 	/* Pad out to 112 mod 128. */
 	index = (sctx->count[0] >> 3) & 0x7f;
 	pad_len = (index < 112) ? (112 - index) : ((128+112) - index);
-	sha512_update(tfm, padding, pad_len);
+	sha512_update(desc, padding, pad_len);
 
 	/* Append length (before padding) */
-	sha512_update(tfm, (const u8 *)bits, sizeof(bits));
+	sha512_update(desc, (const u8 *)bits, sizeof(bits));
 
 	/* Store state in digest */
 	for (i = 0; i < 8; i++)
@@ -235,66 +241,66 @@ sha512_final(struct crypto_tfm *tfm, u8 *hash)
 
 	/* Zeroize sensitive information. */
 	memset(sctx, 0, sizeof(struct sha512_ctx));
+
+	return 0;
 }
 
-static void sha384_final(struct crypto_tfm *tfm, u8 *hash)
+static int sha384_final(struct shash_desc *desc, u8 *hash)
 {
-        u8 D[64];
+	u8 D[64];
 
-	sha512_final(tfm, D);
+	sha512_final(desc, D);
 
-        memcpy(hash, D, 48);
-        memset(D, 0, 64);
+	memcpy(hash, D, 48);
+	memset(D, 0, 64);
+
+	return 0;
 }
 
-static struct crypto_alg sha512 = {
-        .cra_name       = "sha512",
-        .cra_flags      = CRYPTO_ALG_TYPE_DIGEST,
-	.cra_blocksize  = SHA512_BLOCK_SIZE,
-        .cra_ctxsize    = sizeof(struct sha512_ctx),
-        .cra_module     = THIS_MODULE,
-	.cra_alignmask	= 3,
-        .cra_list       = LIST_HEAD_INIT(sha512.cra_list),
-        .cra_u          = { .digest = {
-                                .dia_digestsize = SHA512_DIGEST_SIZE,
-                                .dia_init       = sha512_init,
-                                .dia_update     = sha512_update,
-                                .dia_final      = sha512_final }
-        }
+static struct shash_alg sha512 = {
+	.digestsize	=	SHA512_DIGEST_SIZE,
+	.init		=	sha512_init,
+	.update		=	sha512_update,
+	.final		=	sha512_final,
+	.descsize	=	sizeof(struct sha512_ctx),
+	.base		=	{
+		.cra_name	=	"sha512",
+		.cra_flags	=	CRYPTO_ALG_TYPE_SHASH,
+		.cra_blocksize	=	SHA512_BLOCK_SIZE,
+		.cra_module	=	THIS_MODULE,
+	}
 };
 
-static struct crypto_alg sha384 = {
-        .cra_name       = "sha384",
-        .cra_flags      = CRYPTO_ALG_TYPE_DIGEST,
-	.cra_blocksize  = SHA384_BLOCK_SIZE,
-        .cra_ctxsize    = sizeof(struct sha512_ctx),
-	.cra_alignmask	= 3,
-        .cra_module     = THIS_MODULE,
-        .cra_list       = LIST_HEAD_INIT(sha384.cra_list),
-        .cra_u          = { .digest = {
-                                .dia_digestsize = SHA384_DIGEST_SIZE,
-                                .dia_init       = sha384_init,
-                                .dia_update     = sha512_update,
-                                .dia_final      = sha384_final }
-        }
+static struct shash_alg sha384 = {
+	.digestsize	=	SHA384_DIGEST_SIZE,
+	.init		=	sha384_init,
+	.update		=	sha512_update,
+	.final		=	sha384_final,
+	.descsize	=	sizeof(struct sha512_ctx),
+	.base		=	{
+		.cra_name	=	"sha384",
+		.cra_flags	=	CRYPTO_ALG_TYPE_SHASH,
+		.cra_blocksize	=	SHA384_BLOCK_SIZE,
+		.cra_module	=	THIS_MODULE,
+	}
 };
 
 static int __init sha512_generic_mod_init(void)
 {
         int ret = 0;
 
-        if ((ret = crypto_register_alg(&sha384)) < 0)
+        if ((ret = crypto_register_shash(&sha384)) < 0)
                 goto out;
-        if ((ret = crypto_register_alg(&sha512)) < 0)
-                crypto_unregister_alg(&sha384);
+        if ((ret = crypto_register_shash(&sha512)) < 0)
+                crypto_unregister_shash(&sha384);
 out:
         return ret;
 }
 
 static void __exit sha512_generic_mod_fini(void)
 {
-        crypto_unregister_alg(&sha384);
-        crypto_unregister_alg(&sha512);
+        crypto_unregister_shash(&sha384);
+        crypto_unregister_shash(&sha512);
 }
 
 module_init(sha512_generic_mod_init);
Signature · 1 line
1.5.2.5
#11 lore raw

PATCH v3 3/4 crypto: wp512 - Switch to shash

This patch changes wp512, wp384 and wp256 to the new shash interface.

---
 crypto/Kconfig |    2 +-
 crypto/wp512.c |  121 ++++++++++++++++++++++++++++++--------------------------
 2 files changed, 66 insertions(+), 57 deletions(-)
crypto/Kconfig +1 -1
index c8fb468..0583a26 100644
@@ -366,7 +366,7 @@ config CRYPTO_TGR192
 
 config CRYPTO_WP512
 	tristate "Whirlpool digest algorithms"
-	select CRYPTO_ALGAPI
+	select CRYPTO_HASH
 	help
 	  Whirlpool hash algorithm 512, 384 and 256-bit hashes
 
crypto/wp512.c +65 -56

205 lines not on this page · raw message

Signature · 1 line
1.5.2.5
#12 lore raw

PATCH v3 4/4 crypto: michael_mic - Switch to shash

This patch changes michael_mic to the new shash interface.

---
 crypto/Kconfig       |    2 +-
 crypto/michael_mic.c |   72 ++++++++++++++++++++++++++++---------------------
 2 files changed, 42 insertions(+), 32 deletions(-)
crypto/Kconfig +1 -1
index 0583a26..6593b5a 100644
@@ -260,7 +260,7 @@ config CRYPTO_MD5
 
 config CRYPTO_MICHAEL_MIC
 	tristate "Michael MIC keyed digest algorithm"
-	select CRYPTO_ALGAPI
+	select CRYPTO_HASH
 	help
 	  Michael MIC is used for message integrity protection in TKIP
 	  (IEEE 802.11i). This algorithm is required for TKIP, but it
crypto/michael_mic.c +39 -28

135 lines not on this page · raw message

#14 lore raw

PATCH 1/1 crypto: sha512 - Switch to shash

This patch changes sha512 and sha384 to the new shash interface.

---
 crypto/Kconfig          |    2 +-
 crypto/sha512_generic.c |  112 +++++++++++++++++++++++++----------------------
 2 files changed, 60 insertions(+), 54 deletions(-)
crypto/Kconfig +1 -1
index c8fb468..6d2c5bf 100644
@@ -341,7 +341,7 @@ config CRYPTO_SHA256
 
 config CRYPTO_SHA512
 	tristate "SHA384 and SHA512 digest algorithms"
-	select CRYPTO_ALGAPI
+	select CRYPTO_HASH
 	help
 	  SHA512 secure hash standard (DFIPS 180-2).
 
crypto/sha512_generic.c +59 -53

188 lines not on this page · raw message

Signature · 1 line
1.5.2.5
maintainer
#15 lore raw

Re: [PATCH 1/4 v3] crypto: sha512 - Move message schedule W[80] to static percpu area

In reply to Adrian-Ken Rueegsegger

crypto/sha512_generic.c static inline void BLEND_OP(int I, u64 *W) · line 98

Quoted 3 lines · Adrian-Ken Rueegsegger
crypto/sha512_generic.c +1 -0
 	int i;
+	u64 *W = __get_cpu_var(msg_schedule);

That should be get_cpu_var unless you've already disabled preemption somewhere.

Thanks,

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
#16 lore raw

v4 cover Switch remaining algorithms to shash

This resend contains the fixed up sha512 patches to switch the last remaining algorithm to shash.

The first patch is now correct also in the case of preemption. The second patch remains unchanged.

Adrian

#17 lore raw

PATCH v4 1/2 crypto: sha512 - Move message schedule W[80] to static percpu area

The message schedule W (u64[80]) is too big for the stack. In order for this algorithm to be used with shash it is moved to a static percpu area.

---
 crypto/sha512_generic.c |   17 +++++++++--------
 1 files changed, 9 insertions(+), 8 deletions(-)
crypto/sha512_generic.c +9 -5
index bc36861..cb85516 100644
@@ -18,16 +18,17 @@
 #include <linux/crypto.h>
 #include <linux/types.h>
 #include <crypto/sha.h>
-
+#include <linux/percpu.h>
 #include <asm/byteorder.h>
 
 struct sha512_ctx {
 	u64 state[8];
 	u32 count[4];
 	u8 buf[128];
-	u64 W[80];
 };
 
+static DEFINE_PER_CPU(u64[80], msg_schedule);
+
 static inline u64 Ch(u64 x, u64 y, u64 z)
 {
         return z ^ (x & (y ^ z));
@@ -89,11 +90,12 @@ static inline void BLEND_OP(int I, u64 *W)
 }
 
 static void
-sha512_transform(u64 *state, u64 *W, const u8 *input)
+sha512_transform(u64 *state, const u8 *input)
 {
 	u64 a, b, c, d, e, f, g, h, t1, t2;
 
 	int i;
+	u64 *W = get_cpu_var(msg_schedule);
 
 	/* load the input */
         for (i = 0; i < 16; i++)
@@ -132,6 +134,8 @@ sha512_transform(u64 *state, u64 *W, const u8 *input)
 
 	/* erase our data */
 	a = b = c = d = e = f = g = h = t1 = t2 = 0;
+	memset(W, 0, sizeof(__get_cpu_var(msg_schedule)));
+	put_cpu_var(msg_schedule);
 }
 
 static void
@@ -187,10 +191,10 @@ sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
 	/* Transform as many times as possible. */
 	if (len >= part_len) {
 		memcpy(&sctx->buf[index], data, part_len);
-		sha512_transform(sctx->state, sctx->W, sctx->buf);
+		sha512_transform(sctx->state, sctx->buf);
 
 		for (i = part_len; i + 127 < len; i+=128)
-			sha512_transform(sctx->state, sctx->W, &data[i]);
+			sha512_transform(sctx->state, &data[i]);
 
 		index = 0;
 	} else {
@@ -199,9 +203,6 @@ sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
 
 	/* Buffer remaining input */
 	memcpy(&sctx->buf[index], &data[i], len - i);
#18 lore raw

PATCH v4 2/2 crypto: sha512 - Switch to shash

This patch changes sha512 and sha384 to the new shash interface.

---
 crypto/Kconfig          |    2 +-
 crypto/sha512_generic.c |  112 +++++++++++++++++++++++++----------------------
 2 files changed, 60 insertions(+), 54 deletions(-)
crypto/Kconfig +1 -1
index 6593b5a..017a044 100644
@@ -341,7 +341,7 @@ config CRYPTO_SHA256
 
 config CRYPTO_SHA512
 	tristate "SHA384 and SHA512 digest algorithms"
-	select CRYPTO_ALGAPI
+	select CRYPTO_HASH
 	help
 	  SHA512 secure hash standard (DFIPS 180-2).
 
crypto/sha512_generic.c +59 -53

188 lines not on this page · raw message

Signature · 1 line
1.5.2.5
#19 lore raw

Re: [PATCH 1/2 v4] crypto: sha512 - Move message schedule W[80] to static percpu area

In reply to Adrian-Ken Rueegsegger

Hi.

Quoted 14 lines · Adrian-Ken Rueegsegger

The message schedule W (u64[80]) is too big for the stack. In order for this algorithm to be used with shash it is moved to a static percpu area.

crypto/sha512_generic.c +2 -0
+static DEFINE_PER_CPU(u64[80], msg_schedule);
+
 static inline u64 Ch(u64 x, u64 y, u64 z)
 {
         return z ^ (x & (y ^ z));

crypto/sha512_generic.c static inline void BLEND_OP(int I, u64 *W) · line 98

Quoted 10 lines
crypto/sha512_generic.c +2 -1
@@ -89,11 +90,12 @@ static inline void BLEND_OP(int I, u64 *W)
 }
 
 static void
-sha512_transform(u64 *state, u64 *W, const u8 *input)
+sha512_transform(u64 *state, const u8 *input)
 {
 	u64 a, b, c, d, e, f, g, h, t1, t2;
 
 	int i;
+	u64 *W = get_cpu_var(msg_schedule);

This should be protected by preempt_disable(), shouldn't it?

Signature · 1 line
	Evgeniy Polyakov
maintainer
#20 lore raw

Re: [PATCH 1/2 v4] crypto: sha512 - Move message schedule W[80] to static percpu area

Quoted 11 lines · Evgeniy Polyakov

crypto/sha512_generic.c static inline void BLEND_OP(int I, u64 *W) · line 98

Quoted 9 lines

static void

crypto/sha512_generic.c +2 -1
-sha512_transform(u64 *state, u64 *W, const u8 *input)
+sha512_transform(u64 *state, const u8 *input)
 {
 	u64 a, b, c, d, e, f, g, h, t1, t2;
 
 	int i;
+	u64 *W = get_cpu_var(msg_schedule);

This should be protected by preempt_disable(), shouldn't it?

get_cpu_var does it implicitly.

Thanks,

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
#21 lore raw

Re: [PATCH 1/2 v4] crypto: sha512 - Move message schedule W[80] to static percpu area

Quoted 5 lines · Herbert Xu
Quoted 3 lines

crypto/sha512_generic.c static inline void BLEND_OP(int I, u64 *W) · line 98

Quoted 1 line
crypto/sha512_generic.c +1 -0
+	u64 *W = get_cpu_var(msg_schedule);

This should be protected by preempt_disable(), shouldn't it?

get_cpu_var does it implicitly.

Yeah, that simple!

Signature · 1 line
	Evgeniy Polyakov
maintainer
#22 lore raw
In reply to Adrian-Ken Rueegsegger
Quoted 5 lines · Adrian-Ken Rueegsegger

This resend contains the fixed up sha512 patches to switch the last remaining algorithm to shash.

The first patch is now correct also in the case of preemption. The second patch remains unchanged.

Both applied. Thanks a lot Adrian!

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
maintainer
#23 lore raw
In reply to Adrian-Ken Rueegsegger
Quoted 2 lines · Adrian-Ken Rueegsegger

This series contains the fixed up patches to convert the remaining hash algorithms to use shash.

I've applied patches 3-4.

Thanks,

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