Unroll two loops of SHA1Update(). 60 bytes of static memory is not a price.

This commit is contained in:
Alexander Motin 2008-12-16 19:15:31 +00:00
parent ce8be7b8b0
commit b3d298b9b9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=186189

View File

@ -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);
}