From 1290464fbc7b41e44c7d1bde1b834fc4559ad746 Mon Sep 17 00:00:00 2001 From: mav Date: Tue, 16 Dec 2008 19:15:31 +0000 Subject: Unroll two loops of SHA1Update(). 60 bytes of static memory is not a price. --- sys/netgraph/ng_mppc.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'sys/netgraph') diff --git a/sys/netgraph/ng_mppc.c b/sys/netgraph/ng_mppc.c index 472968f..5a6c302 100644 --- a/sys/netgraph/ng_mppc.c +++ b/sys/netgraph/ng_mppc.c @@ -824,21 +824,24 @@ ng_mppc_reset_req(node_p node) static void ng_mppc_getkey(const u_char *h, u_char *h2, int len) { - static const u_char pad1[10] = - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; - static const u_char pad2[10] = - { 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, }; + static const u_char pad1[40] = + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + static const u_char pad2[40] = + { 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, + 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, + 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, + 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2 }; u_char hash[20]; SHA1_CTX c; - int k; SHA1Init(&c); SHA1Update(&c, h, len); - for (k = 0; k < 4; k++) - SHA1Update(&c, pad1, sizeof(pad1)); + SHA1Update(&c, pad1, sizeof(pad1)); SHA1Update(&c, h2, len); - for (k = 0; k < 4; k++) - SHA1Update(&c, pad2, sizeof(pad2)); + SHA1Update(&c, pad2, sizeof(pad2)); SHA1Final(hash, &c); bcopy(hash, h2, len); } -- cgit v1.1