Skip to content

Instantly share code, notes, and snippets.

@zg
Created July 26, 2011 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zg/1105924 to your computer and use it in GitHub Desktop.
Save zg/1105924 to your computer and use it in GitHub Desktop.
Part of cloak.c from UnrealIRCd
static char *hidehost_ipv4(char *host)
{
unsigned int a, b, c, d;
static char buf[512], res[512], res2[512], result[128];
unsigned long n;
unsigned int alpha, beta, gamma;
/*
* Output: ALPHA.BETA.GAMMA.IP
* ALPHA is unique for a.b.c.d
* BETA is unique for a.b.c.*
* GAMMA is unique for a.b.*
* We cloak like this:
* ALPHA = downsample(md5(md5("KEY2:A.B.C.D:KEY3")+"KEY1"));
* BETA = downsample(md5(md5("KEY3:A.B.C:KEY1")+"KEY2"));
* GAMMA = downsample(md5(md5("KEY1:A.B:KEY2")+"KEY3"));
*/
sscanf(host, "%u.%u.%u.%u", &a, &b, &c, &d);
/* ALPHA... */
ircsprintf(buf, "%s:%s:%s", KEY2, host, KEY3);
DoMD5(res, buf, strlen(buf));
strcpy(res+16, KEY1); /* first 16 bytes are filled, append our key.. */
n = strlen(res+16) + 16;
DoMD5(res2, res, n);
alpha = downsample(res2);
/* BETA... */
ircsprintf(buf, "%s:%d.%d.%d:%s", KEY3, a, b, c, KEY1);
DoMD5(res, buf, strlen(buf));
strcpy(res+16, KEY2); /* first 16 bytes are filled, append our key.. */
n = strlen(res+16) + 16;
DoMD5(res2, res, n);
beta = downsample(res2);
/* GAMMA... */
ircsprintf(buf, "%s:%d.%d:%s", KEY1, a, b, KEY2);
DoMD5(res, buf, strlen(buf));
strcpy(res+16, KEY3); /* first 16 bytes are filled, append our key.. */
n = strlen(res+16) + 16;
DoMD5(res2, res, n);
gamma = downsample(res2);
ircsprintf(result, "%X.%X.%X.IP", alpha, beta, gamma);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment