mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: musl 0.9.5 release and new website
Date: Sun, 16 Sep 2012 23:42:08 +0200	[thread overview]
Message-ID: <20120916214208.GL9428@port70.net> (raw)
In-Reply-To: <20120916032931.GB254@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 630 bytes --]

* Rich Felker <dalias@aerifal.cx> [2012-09-15 23:29:31 -0400]:
> On Sat, Sep 15, 2012 at 03:53:41PM +0200, Szabolcs Nagy wrote:
> > 	while (i < 16) {
> > 		FF(a,b,c,d, W[i],  7, tab[i]); i++;
> > 		FF(d,a,b,c, W[i], 12, tab[i]); i++;
> > 		FF(c,d,a,b, W[i], 17, tab[i]); i++;
> > 		FF(b,c,d,a, W[i], 22, tab[i]); i++;
> > 	}
> 
> This is more of the same old ugly manual unrolling. The file is small
> as-is, but I think it could be a lot smaller with -Os (and same speed
> as now with -O3) if the manual unrolling were removed.
> 

ok i removed the unrolling, the difference is about 200 bytes

is the 30K key limit reasonable?


[-- Attachment #2: md5.diff --]
[-- Type: text/x-diff, Size: 3121 bytes --]

diff --git a/src/crypt/crypt_md5.c b/src/crypt/crypt_md5.c
index 02f2244..684a9fe 100644
--- a/src/crypt/crypt_md5.c
+++ b/src/crypt/crypt_md5.c
@@ -22,11 +22,23 @@ static uint32_t rol(uint32_t n, int k) { return (n << k) | (n >> (32-k)); }
 #define G(x,y,z) (y ^ (z & (y ^ x)))
 #define H(x,y,z) (x ^ y ^ z)
 #define I(x,y,z) (y ^ (x | ~z))
-#define FF(a,b,c,d,w,s,t) a += F(b,c,d) + w + t; a = rol(a,s) + b
-#define GG(a,b,c,d,w,s,t) a += G(b,c,d) + w + t; a = rol(a,s) + b
-#define HH(a,b,c,d,w,s,t) a += H(b,c,d) + w + t; a = rol(a,s) + b
-#define II(a,b,c,d,w,s,t) a += I(b,c,d) + w + t; a = rol(a,s) + b
+#define FF(a,b,c,d,w,r,t) a += F(b,c,d) + w + t; a = rol(a,r) + b
+#define GG(a,b,c,d,w,r,t) a += G(b,c,d) + w + t; a = rol(a,r) + b
+#define HH(a,b,c,d,w,r,t) a += H(b,c,d) + w + t; a = rol(a,r) + b
+#define II(a,b,c,d,w,r,t) a += I(b,c,d) + w + t; a = rol(a,r) + b
 
+static const uint8_t idx[64] = {
+0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
+1,6,11,0,5,10,15,4,9,14,3,8,13,2,7,12,
+5,8,11,14,1,4,7,10,13,0,3,6,9,12,15,2,
+0,7,14,5,12,3,10,1,8,15,6,13,4,11,2,9
+};
+static const uint8_t rot[64] = {
+7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22,
+5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20,
+4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23,
+6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21
+};
 static const uint32_t tab[64] = {
 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
@@ -40,7 +52,7 @@ static const uint32_t tab[64] = {
 
 static void processblock(struct md5 *s, const uint8_t *buf)
 {
-	uint32_t i, W[16], a, b, c, d;
+	uint32_t i, W[16], a, b, c, d, x;
 
 	for (i = 0; i < 16; i++) {
 		W[i] = buf[4*i];
@@ -54,30 +66,21 @@ static void processblock(struct md5 *s, const uint8_t *buf)
 	c = s->h[2];
 	d = s->h[3];
 
-	i = 0;
-	while (i < 16) {
-		FF(a,b,c,d, W[i],  7, tab[i]); i++;
-		FF(d,a,b,c, W[i], 12, tab[i]); i++;
-		FF(c,d,a,b, W[i], 17, tab[i]); i++;
-		FF(b,c,d,a, W[i], 22, tab[i]); i++;
+	for (i = 0; i < 16; i++) {
+		FF(a,b,c,d,W[idx[i]],rot[i],tab[i]);
+		x = d; d = c; c = b; b = a; a = x;
 	}
-	while (i < 32) {
-		GG(a,b,c,d, W[(5*i+1)%16],  5, tab[i]); i++;
-		GG(d,a,b,c, W[(5*i+1)%16],  9, tab[i]); i++;
-		GG(c,d,a,b, W[(5*i+1)%16], 14, tab[i]); i++;
-		GG(b,c,d,a, W[(5*i+1)%16], 20, tab[i]); i++;
+	for (; i < 32; i++) {
+		GG(a,b,c,d,W[idx[i]],rot[i],tab[i]);
+		x = d; d = c; c = b; b = a; a = x;
 	}
-	while (i < 48) {
-		HH(a,b,c,d, W[(3*i+5)%16],  4, tab[i]); i++;
-		HH(d,a,b,c, W[(3*i+5)%16], 11, tab[i]); i++;
-		HH(c,d,a,b, W[(3*i+5)%16], 16, tab[i]); i++;
-		HH(b,c,d,a, W[(3*i+5)%16], 23, tab[i]); i++;
+	for (; i < 48; i++) {
+		HH(a,b,c,d,W[idx[i]],rot[i],tab[i]);
+		x = d; d = c; c = b; b = a; a = x;
 	}
-	while (i < 64) {
-		II(a,b,c,d, W[7*i%16],  6, tab[i]); i++;
-		II(d,a,b,c, W[7*i%16], 10, tab[i]); i++;
-		II(c,d,a,b, W[7*i%16], 15, tab[i]); i++;
-		II(b,c,d,a, W[7*i%16], 21, tab[i]); i++;
+	for (; i < 64; i++) {
+		II(a,b,c,d,W[idx[i]],rot[i],tab[i]);
+		x = d; d = c; c = b; b = a; a = x;
 	}
 
 	s->h[0] += a;

  reply	other threads:[~2012-09-16 21:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-15  8:12 Rich Felker
2012-09-15 13:53 ` Szabolcs Nagy
2012-09-15 14:05   ` Luca Barbato
2012-09-16  3:35     ` Rich Felker
2012-09-16  3:48       ` Conrad Pankoff
2012-09-16  4:03         ` Gregor Richards
2012-09-16 11:04       ` Luca Barbato
2012-09-16  3:26   ` Rich Felker
2012-09-16 10:31     ` Szabolcs Nagy
2012-09-16 12:39       ` Rich Felker
2012-09-16  3:29   ` Rich Felker
2012-09-16 21:42     ` Szabolcs Nagy [this message]
2012-09-17  3:02       ` Rich Felker
2012-09-17  7:35         ` Szabolcs Nagy
2012-09-18 13:56           ` Rich Felker
2012-09-15 23:09 ` Isaac Dunham
2012-09-16  3:41 ` Rich Felker

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=20120916214208.GL9428@port70.net \
    --to=nsz@port70.net \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).