test.c (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#include <stdint.h>
#include <stdio.h>
static void
add_shifted (uint32_t *h, const uint32_t *c, uint8_t shift)
{
uint32_t shifted[16];
for (uint8_t i = 0; i < 16; ++i)
{
shifted[i] = 0x0;
}
shifted[shift / 32] = (c[0] << (shift % 32)) & 0xffffffff;
for (uint8_t i = shift / 32 + 1; i < shift / 32 + 9 && i < 16; ++i)
{
if (shift % 32 == 0)
{
shifted[i] = c[i - shift / 32];
}
else
{
shifted[i] = (c[i - shift / 32 - 1] >> (32 - (shift % 32)))
| ((c[i - shift / 32] << (shift % 32)) & 0xffffffff);
}
}
if (shift / 32 + 9 < 16)
{
shifted[shift / 32 + 9] = c[8] >> (32 - (shift % 32));
}
uint64_t acc = 0;
for (unsigned int i = 0; i < 16; ++i)
{
acc += (uint64_t)h[i] + (uint64_t)shifted[i];
h[i] = acc & 0xffffffff;
acc >>= 32;
}
}
int
main ()
{
uint32_t buf[16] = {
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
};
uint32_t to_add[9] = {
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
};
for (uint16_t i = 0; i <= 255; ++i)
{
add_shifted (buf, to_add, i);
for (unsigned int i = 0; i < 16; ++i)
{
printf ("%08x", buf[15 - i]);
}
printf ("\n");
}
return 0;
}
|