X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=hmac.c;h=8b6d2f6234caa8e612d2710e35daaacc16bd40bb;hp=de44162796b6339164e4c41dd88009bae76c3c43;hb=e3c655432c0a5054156e457f53cdae1efc9600b9;hpb=a737a50df4004443459e818e1e463141ef246280 diff --git a/hmac.c b/hmac.c index de441627..8b6d2f62 100644 --- a/hmac.c +++ b/hmac.c @@ -1,29 +1,27 @@ -#include "quakedef.h" +#include "darkplaces.h" #include "hmac.h" -void hmac( +qbool 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) - Host_Error("Invalid hash function used for HMAC - too long hash length"); + return false; if(sizeof(k_xor_ipad) < (size_t) hblock) - Host_Error("Invalid hash function used for HMAC - too long hash block length"); + return false; if(sizeof(k_xor_ipad) < (size_t) hlen) - Host_Error("Invalid hash function used for HMAC - too long hash length"); - if(sizeof(catbuf) < (size_t) hblock + (size_t) hlen) - Host_Error("Invalid hash function used for HMAC - too long hash block length"); - if(sizeof(catbuf) < (size_t) hblock + (size_t) n) - Host_Error("Invalid hash function used for HMAC - too long message length"); + return false; + + catbuf = (unsigned char *)Mem_Alloc(tempmempool, (size_t) hblock + max((size_t) hlen, (size_t) n)); if(k > hblock) { @@ -56,4 +54,8 @@ void hmac( memcpy(catbuf, k_xor_opad, hblock); memcpy(catbuf + hblock, hashbuf, hlen); hfunc(out, catbuf, hblock + hlen); + + Mem_Free(catbuf); + + return true; }