]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - hmac.c
CL_VM_GetLight: allow 2'nd optional parm which sets sampling mask: 1 lightmap (defaul...
[xonotic/darkplaces.git] / hmac.c
diff --git a/hmac.c b/hmac.c
index de44162796b6339164e4c41dd88009bae76c3c43..af0d11968e64bca065d1212d05118a0621453792 100644 (file)
--- a/hmac.c
+++ b/hmac.c
@@ -1,29 +1,29 @@
 #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
 )
 {
        static unsigned char hashbuf[32];
        static unsigned char k_xor_ipad[128];
        static unsigned char k_xor_opad[128];
-       static unsigned char catbuf[4096];
+       static unsigned char catbuf[65600]; // 65535 bytes max quake packet size + 64 for the hash
        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");
+               return false;
        if(sizeof(catbuf) < (size_t) hblock + (size_t) hlen)
-               Host_Error("Invalid hash function used for HMAC - too long hash block length");
+               return false;
        if(sizeof(catbuf) < (size_t) hblock + (size_t) n)
-               Host_Error("Invalid hash function used for HMAC - too long message length");
+               return false;
 
        if(k > hblock)
        {
@@ -56,4 +56,5 @@ void hmac(
        memcpy(catbuf, k_xor_opad, hblock);
        memcpy(catbuf + hblock, hashbuf, hlen);
        hfunc(out, catbuf, hblock + hlen);
+       return true;
 }