ref: 66a3ffe2489727e85462e60e6dcec5dad1f5b20d
parent: f079c719663d15cb91e0657d9a2c2ed75cd8acb7
author: cinap_lenrek <[email protected]>
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){