veorq/SipHash

Sip RNG

dhardy opened this issue · 1 comments

I have implemented a psuedo-random number generator based on SipHash, and hope I might be able to get some feedback on the design?

This PRNG construction appears to be statistically high-quality, though only with moderate speed, and I don't know about cryptographic strength.

The motivation to doing this is to provide a "universal PRNG seeder", meaning:

  • any input can be deterministically transformed into a key of any required size
  • the output key has a high chance of avoiding low hamming-weight values even for naive input
  • for similar input values, there is a high chance that the output keys are very different

This is not intended for use in cryptography, but only for deterministic PRNGs used in simulations.


The choice of how many rounds to use, and where, is arbitrary, but designed to be similar to the standard 2-4 selection used by SipHash.

The additional tweaks to state between these rounds are entirely arbitrary choices other than being some extra tweak.

A quick guide to the source code:

  • 39, 57, 69: hasher state
  • 51, 69: RNG state
  • 320: SipHash::write function
  • 216: SipHash for short input
  • 361: SipHash::finish function for standard output
  • 242: conversion from SipHash to SipRng
  • 146: SipRng::next_u64 function
  • 410: c_rounds / d_rounds functions
  • 440, 462: test vectors
veorq commented

This is not the right place for such review work.