X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=hmac.c;h=e740632df4884cd0789cbfbc80e04962eff00a5e;hp=372921d7a096a8786e3e652b9c988f574ace53c2;hb=563fb48299f453ecb3b81168079df8d30c0ac311;hpb=c7eea28ff1214ea7c198be1bda5638e1df314ab1 diff --git a/hmac.c b/hmac.c index 372921d7..e740632d 100644 --- a/hmac.c +++ b/hmac.c @@ -1,29 +1,27 @@ #include "quakedef.h" #include "hmac.h" -void hmac( +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 ) { unsigned char hashbuf[32]; unsigned char k_xor_ipad[128]; unsigned char k_xor_opad[128]; - unsigned char catbuf[256]; + 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; }