]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
HMAC: remove static vars
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 25 Oct 2011 11:14:32 +0000 (11:14 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 25 Oct 2011 11:14:32 +0000 (11:14 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11473 d7cf8633-e32d-0410-b094-e92efae38249

hmac.c

diff --git a/hmac.c b/hmac.c
index af0d11968e64bca065d1212d05118a0621453792..a422c699843356fd0cddb1fb3d3e832b3453c588 100644 (file)
--- a/hmac.c
+++ b/hmac.c
@@ -8,10 +8,10 @@ qboolean hmac(
        const unsigned char *key, int k
 )
 {
-       static unsigned char hashbuf[32];
-       static unsigned char k_xor_ipad[128];
-       static unsigned char k_xor_opad[128];
-       static unsigned char catbuf[65600]; // 65535 bytes max quake packet size + 64 for the hash
+       unsigned char hashbuf[32];
+       unsigned char k_xor_ipad[128];
+       unsigned char k_xor_opad[128];
+       unsigned char *catbuf;
        int i;
 
        if(sizeof(hashbuf) < (size_t) hlen)
@@ -20,10 +20,8 @@ qboolean hmac(
                return false;
        if(sizeof(k_xor_ipad) < (size_t) hlen)
                return false;
-       if(sizeof(catbuf) < (size_t) hblock + (size_t) hlen)
-               return false;
-       if(sizeof(catbuf) < (size_t) hblock + (size_t) n)
-               return false;
+
+       catbuf = Mem_Alloc(tempmempool, (size_t) hblock + max((size_t) hlen, (size_t) n));
 
        if(k > hblock)
        {
@@ -56,5 +54,8 @@ qboolean hmac(
        memcpy(catbuf, k_xor_opad, hblock);
        memcpy(catbuf + hblock, hashbuf, hlen);
        hfunc(out, catbuf, hblock + hlen);
+
+       Mem_Free(catbuf);
+
        return true;
 }