git: 9front

Download patch

ref: 3273c3eb7853c90d9afc42c1a81d897cc27ad4a5
parent: c420e05a969200ed0720e570b2282a637c81914c
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Sat Mar 23 16:52:54 EDT 2013

unrolling loops in aesCCMencrypt() and aesCCMdecrypt()

do the xoring word wise for 16-byte block instead
of doing it bytewise in a loop.

--- a/sys/src/9/pc/wifi.c
+++ b/sys/src/9/pc/wifi.c
@@ -1161,11 +1161,18 @@
 
 	xblock(L, M, N, a, la, lm, t, s);
 
-	for(i = 1; lm >= 16; i++, lm -= 16){
-		for(p = sblock(L, N, i, b, s), x = t; p < &b[16]; x++, m++, p++){
-			*x ^= *m;
-			*m ^= *p;
-		}
+	for(i = 1; lm >= 16; i++, m += 16, lm -= 16){
+		sblock(L, N, i, b, s);
+
+		*((u32int*)&t[0]) ^= *((u32int*)&m[0]);
+		*((u32int*)&m[0]) ^= *((u32int*)&b[0]);
+		*((u32int*)&t[4]) ^= *((u32int*)&m[4]);
+		*((u32int*)&m[4]) ^= *((u32int*)&b[4]);
+		*((u32int*)&t[8]) ^= *((u32int*)&m[8]);
+		*((u32int*)&m[8]) ^= *((u32int*)&b[8]);
+		*((u32int*)&t[12]) ^= *((u32int*)&m[12]);
+		*((u32int*)&m[12]) ^= *((u32int*)&b[12]);
+
 		aes_encrypt(s->ekey, s->rounds, t, t);
 	}
 	if(lm > 0){
@@ -1193,11 +1200,18 @@
 
 	xblock(L, M, N, a, la, lm, t, s);
 
-	for(i = 1; lm >= 16; i++, lm -= 16){
-		for(p = sblock(L, N, i, b, s), x = t; p < &b[16]; x++, m++, p++){
-			*m ^= *p;
-			*x ^= *m;
-		}
+	for(i = 1; lm >= 16; i++, m += 16, lm -= 16){
+		sblock(L, N, i, b, s);
+
+		*((u32int*)&m[0]) ^= *((u32int*)&b[0]);
+		*((u32int*)&t[0]) ^= *((u32int*)&m[0]);
+		*((u32int*)&m[4]) ^= *((u32int*)&b[4]);
+		*((u32int*)&t[4]) ^= *((u32int*)&m[4]);
+		*((u32int*)&m[8]) ^= *((u32int*)&b[8]);
+		*((u32int*)&t[8]) ^= *((u32int*)&m[8]);
+		*((u32int*)&m[12]) ^= *((u32int*)&b[12]);
+		*((u32int*)&t[12]) ^= *((u32int*)&m[12]);
+
 		aes_encrypt(s->ekey, s->rounds, t, t);
 	}
 	if(lm > 0){
--