Skip to content

Instantly share code, notes, and snippets.

@popcornmix
Created November 7, 2016 12:59
Show Gist options
  • Save popcornmix/8785db9354a2ef0589c55aac78f01f18 to your computer and use it in GitHub Desktop.
Save popcornmix/8785db9354a2ef0589c55aac78f01f18 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
uint64_t compute_hash(const uint8_t *in, uint32_t len);
static uint16_t lfsr = 0xACE1u;
static uint32_t bit;
static uint32_t myrand()
{
bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1;
return lfsr = (lfsr >> 1) | (bit << 15);
}
int main(int argc, char **argv)
{
unsigned seed = 0x12345678;
srand(seed);
int iterations = 1;
if (argc > 1)
seed = strtol(argv[1], 0, 0);
if (argc > 2)
iterations = strtol(argv[2], 0, 0);
for (int i = 0; i<iterations; i++)
{
int len = rand() % 4096;
uint8_t *p = malloc(len);
for (int j=0; j<len; j++)
((unsigned char *)p)[j] = myrand() >> 8;
uint64_t hash = compute_hash(p, len);
printf("%08x%08x\n", (uint32_t)(hash>>32), (uint32_t)(hash>>0));
free(p);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment