All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: David Laight <David.Laight@aculab.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	linux-crypto@vger.kernel.org, netdev@vger.kernel.org,
	ken@codelabs.ch, Steffen Klassert <steffen.klassert@secunet.com>,
	security@kernel.org, Eric Dumazet <eric.dumazet@gmail.com>
Subject: [PATCH 4/3] sha512: reduce stack usage even on i386
Date: Wed, 18 Jan 2012 21:02:10 +0300	[thread overview]
Message-ID: <20120118180210.GA22733@p183.telecom.by> (raw)
In-Reply-To: <CACVxJT_cZAdxNOFTpK5seUXFZU+YB3zbe6LF1nnyzo32ae14xw@mail.gmail.com>

Fix still excessive stack usage on i386.

There is too much loop unrolling going on, despite W[16] being used,
gcc screws up this for some reason. So, don't be smart, use simple code
from SHA-512 definition, this keeps code size _and_ stack usage back
under control even on i386:

	-14b:   81 ec 9c 03 00 00       sub    $0x39c,%esp
	+149:   81 ec 64 01 00 00       sub    $0x164,%esp

	$ size ../sha512_generic-i386-00*
	   text    data     bss     dec     hex filename
	  15521     712       0   16233    3f69 ../sha512_generic-i386-000.o
	   4225     712       0    4937    1349 ../sha512_generic-i386-001.o

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: stable@vger.kernel.org
---

 crypto/sha512_generic.c |   42 ++++++++++++++++++++----------------------
 1 file changed, 20 insertions(+), 22 deletions(-)

--- a/crypto/sha512_generic.c
+++ b/crypto/sha512_generic.c
@@ -95,35 +95,33 @@ sha512_transform(u64 *state, const u8 *input)
 #define SHA512_0_15(i, a, b, c, d, e, f, g, h)			\
 	t1 = h + e1(e) + Ch(e, f, g) + sha512_K[i] + W[i];	\
 	t2 = e0(a) + Maj(a, b, c);				\
-	d += t1;						\
-	h = t1 + t2
+	h = g;							\
+	g = f;							\
+	f = e;							\
+	e = d + t1;						\
+	d = c;							\
+	c = b;							\
+	b = a;							\
+	a = t1 + t2
 
 #define SHA512_16_79(i, a, b, c, d, e, f, g, h)			\
 	BLEND_OP(i, W);						\
-	t1 = h + e1(e) + Ch(e, f, g) + sha512_K[i] + W[(i)&15];	\
+	t1 = h + e1(e) + Ch(e, f, g) + sha512_K[i] + W[i & 15];	\
 	t2 = e0(a) + Maj(a, b, c);				\
-	d += t1;						\
-	h = t1 + t2
-
-	for (i = 0; i < 16; i += 8) {
+	h = g;							\
+	g = f;							\
+	f = e;							\
+	e = d + t1;						\
+	d = c;							\
+	c = b;							\
+	b = a;							\
+	a = t1 + t2
+
+	for (i = 0; i < 16; i++) {
 		SHA512_0_15(i, a, b, c, d, e, f, g, h);
-		SHA512_0_15(i + 1, h, a, b, c, d, e, f, g);
-		SHA512_0_15(i + 2, g, h, a, b, c, d, e, f);
-		SHA512_0_15(i + 3, f, g, h, a, b, c, d, e);
-		SHA512_0_15(i + 4, e, f, g, h, a, b, c, d);
-		SHA512_0_15(i + 5, d, e, f, g, h, a, b, c);
-		SHA512_0_15(i + 6, c, d, e, f, g, h, a, b);
-		SHA512_0_15(i + 7, b, c, d, e, f, g, h, a);
 	}
-	for (i = 16; i < 80; i += 8) {
+	for (i = 16; i < 80; i++) {
 		SHA512_16_79(i, a, b, c, d, e, f, g, h);
-		SHA512_16_79(i + 1, h, a, b, c, d, e, f, g);
-		SHA512_16_79(i + 2, g, h, a, b, c, d, e, f);
-		SHA512_16_79(i + 3, f, g, h, a, b, c, d, e);
-		SHA512_16_79(i + 4, e, f, g, h, a, b, c, d);
-		SHA512_16_79(i + 5, d, e, f, g, h, a, b, c);
-		SHA512_16_79(i + 6, c, d, e, f, g, h, a, b);
-		SHA512_16_79(i + 7, b, c, d, e, f, g, h, a);
 	}
 
 	state[0] += a; state[1] += b; state[2] += c; state[3] += d;

  reply	other threads:[~2012-01-18 18:02 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-11  0:00 sha512: make it work, undo percpu message schedule Alexey Dobriyan
2012-01-11  0:12 ` Alexey Dobriyan
2012-01-11  0:36 ` Herbert Xu
2012-01-12 23:55   ` Alexey Dobriyan
2012-01-13  0:19     ` Herbert Xu
2012-01-13  7:08     ` Herbert Xu
2012-01-13 10:35       ` Eric Dumazet
2012-01-13 10:41         ` Eric Dumazet
2012-01-13 10:57           ` Eric Dumazet
2012-01-13 11:33             ` Alexey Dobriyan
2012-01-13 12:34               ` Eric Dumazet
2012-01-14 18:20                 ` Alexey Dobriyan
2012-01-14 18:27                   ` [PATCH 1/3] " Alexey Dobriyan
2012-01-14 18:40                     ` [PATCH 2/3] sha512: reduce stack usage to safe number Alexey Dobriyan
2012-01-14 18:44                       ` [PATCH 3/3] sha512: use standard ror64() Alexey Dobriyan
2012-01-14 19:08                       ` [PATCH 2/3] sha512: reduce stack usage to safe number Linus Torvalds
2012-01-14 20:41                         ` Alexey Dobriyan
2012-01-14 21:14                           ` Linus Torvalds
2012-01-16  9:56                           ` David Laight
2012-01-16 10:20                             ` Alexey Dobriyan
2012-01-16 10:23                             ` Eric Dumazet
2012-01-16 11:37                               ` David Laight
2012-01-17 12:03                               ` Alexey Dobriyan
2012-01-18 18:02                                 ` Alexey Dobriyan [this message]
2012-01-26  2:35                                   ` [PATCH 4/3] sha512: reduce stack usage even on i386 Herbert Xu
2012-01-27 17:51                                     ` Alexey Dobriyan
2012-01-27 22:32                                       ` Herbert Xu
2012-01-30 11:10                                         ` Alexey Dobriyan
2012-02-03  3:34                                           ` Herbert Xu
2012-01-14 21:46                     ` [PATCH 1/3] sha512: make it work, undo percpu message schedule Eric Dumazet
2012-01-14 21:52                       ` Linus Torvalds
2012-01-14 22:00                         ` Eric Dumazet
2012-01-15  1:43                     ` Herbert Xu
2012-01-13 11:02         ` Steffen Klassert
2012-01-15  1:43           ` Herbert Xu
2012-01-13 11:45         ` David Laight
2012-01-13 12:35           ` Eric Dumazet
2012-01-13  6:22   ` Steffen Klassert
2012-01-13  6:46     ` Herbert Xu
2012-01-13  6:48     ` Eric Dumazet
2012-01-13  6:50       ` Herbert Xu
2012-01-13  9:45       ` David Laight
2012-01-11  1:12 ` Adrian-Ken Rueegsegger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120118180210.GA22733@p183.telecom.by \
    --to=adobriyan@gmail.com \
    --cc=David.Laight@aculab.com \
    --cc=eric.dumazet@gmail.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=ken@codelabs.ch \
    --cc=linux-crypto@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=security@kernel.org \
    --cc=steffen.klassert@secunet.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.