From: divverent Date: Thu, 9 Apr 2009 06:29:30 +0000 (+0000) Subject: tiny fix regarding too long keys X-Git-Tag: xonotic-v0.1.0preview~1725 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c7eea28ff1214ea7c198be1bda5638e1df314ab1;p=xonotic%2Fdarkplaces.git tiny fix regarding too long keys git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8885 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/hmac.c b/hmac.c index eb254e21..372921d7 100644 --- a/hmac.c +++ b/hmac.c @@ -18,6 +18,8 @@ void hmac( Host_Error("Invalid hash function used for HMAC - too long hash length"); if(sizeof(k_xor_ipad) < (size_t) hblock) Host_Error("Invalid hash function used for HMAC - too long hash block length"); + 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) @@ -26,16 +28,16 @@ void hmac( if(k > hblock) { // hash the key if it is too long - // NO! that makes it too short if hblock != hlen - // just shorten it, then - // hfunc(hashbuf, key, k); - // key = hashbuf; - k = hblock; + hfunc(k_xor_opad, key, k); + key = k_xor_opad; + k = hlen; } - else if(k < hblock) + + if(k < hblock) { // zero pad the key if it is too short - memcpy(k_xor_opad, key, k); + if(key != k_xor_opad) + memcpy(k_xor_opad, key, k); for(i = k; i < hblock; ++i) k_xor_opad[i] = 0; key = k_xor_opad;