Пример #1
0
unsigned udns_jranval(struct udns_jranctx *x) {
  /* This routine can be made to work with either 32 or 64bit words -
   * if JRAN_32_64 is defined when compiling the file.
   * We use if() instead of #if since there's no good
   * portable way to check sizeof() in preprocessor without
   * introducing some ugly configure-time checks.
   * Most compilers will optimize the wrong branches away anyway.
   * By default it assumes 32bit integers
   */
#ifdef JRAN_32_64
  if (sizeof(unsigned) == 4) {
#endif
    unsigned e = tr32(x->a - rot32(x->b, 27));
    x->a = tr32(x->b ^ rot32(x->c, 17));
    x->b = tr32(x->c + x->d);
    x->c = tr32(x->d + e);
    x->d = tr32(e + x->a);
#ifdef JRAN_32_64
  }
  else if (sizeof(unsigned) == 8) { /* assuming it's 64bits */
    unsigned e = x->a - rot64(x->b, 7);
    x->a = x->b ^ rot64(x->c, 13);
    x->b = x->c + rot64(x->d, 37);
    x->c = x->d + e;
    x->d = e + x->a;
  }
  else {
    unsigned e = 0;
    x->d = 1/e; /* bail */
  }
#endif
  return x->d;
}
Пример #2
0
static uint32_t
hashmac(uint8_t *buf)
{
	uint32_t a, b, c;

	a = (uint32_t)buf[0] + ((uint32_t)buf[1]<<8);
	b = (uint32_t)buf[2] + ((uint32_t)buf[3]<<8);
	c = (uint32_t)buf[4] + ((uint32_t)buf[5]<<8);

// from lookup3.c, by Bob Jenkins, May 2006, Public Domain.
// http://burtleburtle.net/bob/c/lookup3.c
#define rot32(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
	c ^= b; c -= rot32(b,14);
	a ^= c; a -= rot32(c,11);
	b ^= a; b -= rot32(a,25);
	c ^= b; c -= rot32(b,16);
	a ^= c; a -= rot32(c,4);
	b ^= a; b -= rot32(a,14);
	c ^= b; c -= rot32(b,24);
#undef rot32

	return c;
}