c++ - Fast pseudorandom number generator for cryptography in C -
i using following code generate sequence of pseudo-random numbers used cryptographic purposes, read somewhere may not secure. can give me c implementation of better generator -- main goal method fast. instance, did research , came across blum blum shub method, totally kill performance doing pow(n) calculations.
ps. , please don't quote wikipedia articles w/o c/c++ code. i'm looking c or c++ code sample of i'm showing below.
#define rol(v, shift) ((((v) >> ((sizeof(v) * 8) - (shift))) | ((v) << (shift)))) ulonglong uipsn = doseed(); //64-bit unsigned integer for(int = 0; < sizeofarray; i++) { uipsn = uipsn * 214013l + 2531011l; uipsn = rol(uipsn, 16); //apply 'uipsn' }
isaac (http://www.burtleburtle.net/bob/rand/isaacafa.html) 1 of fastest cryptographically secure prngs (code @ site). approach use block cipher in counter mode. twofish, reasonably fast , freely available, effective.
if don't need lot of numbers, modern operating systems have built-in rngs suitable cryptographic use, though typically can't produce lots of numbers because rely on accumulating entropy sources input timings. unix-like systems (linux, osx) have /dev/random, windows has cryptgenrandom. if these aren't suitable needs, should use them seed prng end using.
Comments
Post a Comment