#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,
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)
{
memcpy(catbuf, k_xor_opad, hblock);
memcpy(catbuf + hblock, hashbuf, hlen);
hfunc(out, catbuf, hblock + hlen);
+ return true;
}
#define HMAC_H
typedef void (*hashfunc_t) (unsigned char *out, unsigned char *in, int n);
-void hmac(
+qboolean hmac(
hashfunc_t hfunc, int hlen, int hblock,
unsigned char *out,
unsigned char *in, int n,
char argbuf[1500];
dpsnprintf(argbuf, sizeof(argbuf), "%ld %s", (long) time(NULL), Cmd_Args());
memcpy(buf, "\377\377\377\377srcon HMAC-MD4 TIME ", 24);
- HMAC_MDFOUR_16BYTES((unsigned char *) (buf + 24), (unsigned char *) argbuf, strlen(argbuf), (unsigned char *) rcon_password.string, strlen(rcon_password.string));
- buf[40] = ' ';
- strlcpy(buf + 41, argbuf, sizeof(buf) - 41);
- NetConn_Write(mysocket, buf, 41 + strlen(buf + 41), &to);
+ if(HMAC_MDFOUR_16BYTES((unsigned char *) (buf + 24), (unsigned char *) argbuf, strlen(argbuf), (unsigned char *) rcon_password.string, strlen(rcon_password.string)))
+ {
+ buf[40] = ' ';
+ strlcpy(buf + 41, argbuf, sizeof(buf) - 41);
+ NetConn_Write(mysocket, buf, 41 + strlen(buf + 41), &to);
+ }
}
else
{
if(abs(t1 - t2) > rcon_secure_maxdiff.integer)
return false;
- HMAC_MDFOUR_16BYTES((unsigned char *) mdfourbuf, (unsigned char *) s, slen, (unsigned char *) password, strlen(password));
+ if(!HMAC_MDFOUR_16BYTES((unsigned char *) mdfourbuf, (unsigned char *) s, slen, (unsigned char *) password, strlen(password)))
+ return false;
+
return !memcmp(mdfourbuf, hash, 16);
}