++subcounter;
subcounter &= 15;
}
+ void initialize(const uint32_t *k, const uint32_t *n,
+ const uint64_t *c, const int *s)
+ {
+ int i;
+ for (i = 0; i < 8; ++i)
+ {
+ key[i] = k[i];
+ }
+ nonce[0] = n[0];
+ nonce[1] = n[1];
+ counter = *c;
+ subcounter = (*s) & 15;
+ if (subcounter)
+ {
+ runstate();
+ }
+ }
+ void extract_state(uint32_t *k, uint32_t *n, uint64_t *c, int *s) const
+ {
+ int i;
+ for (i = 0; i < 8; ++i)
+ {
+ k[i] = key[i];
+ }
+ n[0] = nonce[0];
+ n[1] = nonce[1];
+ *c = counter;
+ *s = subcounter;
+ }
};
}
#endif
extern "C" void dice_setstate(const uint32_t *key, const uint32_t *nonce, const uint64_t *counter, const int *subcounter)
{
- dice_generator.counter = *counter;
- memcpy(dice_generator.key, key, 8 * sizeof(uint32_t));
- memcpy(dice_generator.nonce, nonce, 2 * sizeof(uint32_t));
- dice_generator.subcounter = (*subcounter) & 15;
- if (dice_generator.subcounter != 0)
- {
- /* if the subcounter wasn't zero, the generator will DTwrongT. */
- dice_generator.runstate();
- }
+ dice_generator.initialize(key, nonce, counter, subcounter);
}
extern "C" void dice_getstate(uint32_t *key, uint32_t *nonce, uint64_t *counter, int *subcounter)
{
- memcpy(key, dice_generator.key, 8 * sizeof(uint32_t));
- memcpy(dice_generator.nonce, nonce, 2 * sizeof(uint32_t));
- *subcounter = dice_generator.subcounter;
- *counter = dice_generator.counter;
+ dice_generator.extract_state(key, nonce, counter, subcounter);
}
// vim:ts=8:sw=4:expandtab:fo=cq