X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=hmac.c;h=e740632df4884cd0789cbfbc80e04962eff00a5e;hp=bd97ba43fd2c7321d6d5229e80c98c4c0a27b01e;hb=ce130c7da8ce2c1cdf5e19d1823276c5ca5e83b5;hpb=01b29650876b1f991ac2e8fe0c0a54b73c43204e diff --git a/hmac.c b/hmac.c index bd97ba43..e740632d 100644 --- a/hmac.c +++ b/hmac.c @@ -4,14 +4,14 @@ qboolean hmac( hashfunc_t hfunc, int hlen, int hblock, unsigned char *out, - unsigned char *in, int n, - unsigned char *key, int k + const unsigned char *in, int n, + 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[4096]; + 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 = (unsigned char *)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; }