Forum > FPC development
True hard random generator
sam707:
As i read wiki I understood FPC uses Mersenne Twister algo to get pseudo random numbers.
While I was looking for alternate algorithms, I found out that some processors have an inbuilt hardware (true) random number generator.
My question is simple :
Will FPC use this feature in a near future, or should I make ASMs functions and procedure to use it?
namely RdSeed and RdRand ASM instructions described on following link
https://en.wikipedia.org/wiki/RdRand
these ASM instructions are quiet slow compared to Mersenne Twister, as explained in the above article, BUT, they exist to give TRUE random, giving high level cryptographic compliance. So, in many projects, it should be USEFUL
sam707:
making asm proc/func is not big deal tho, I'm still investigating algoritms, even will try to mix some ;D
Eugene Loza:
You may try this one: http://wiki.freepascal.org/Dev_random (Linux-only)
Thaddy:
I will add or add to/modify the following three randoms to the wiki, I already have such code including code that uses rdseed/rdrand or hwrng to seed the standard random:
/dev/random, /dev/urandom that take entropy from several sources on nixes. Including the use of hwrng if available. There is already an entry.
https://en.wikipedia.org/wiki//dev/random
Microsoft's cryptgenrandom that take entropy from several sources on nixes. Including the use of hwrng if available.
https://en.wikipedia.org/wiki/CryptGenRandom
hwrng if availabale on a system (e.g. Raspberry Pi, modern intel. This is true hardware random that takes entropy from physics behavior on the chip
e.g. https://sites.google.com/site/astudyofentropy/project-definition/raspberry-pi-internal-hardware-random-number-generator
I have an article ready but my health failed badly and I needed to add a few more examples.
Note the standard random functions will always be a PRNG and possible always the mersenne twister. This is because its purpose also lies in statstics and must be reproducable:
Given the same seed it *must* produce the same random series.
True random is available through other means already and is not repeatable. Its purpose lies e.g. in cryptography.
I already added a number of alternative PRNG's to the wiki for e.g. Delphi compatible random and e.g. superfast prng's for gaming etc.
I also provided a patch in trunk for a generic version of RandomFrom
Further note the the OS, both Windows and nixes (IIRC except BSD), already use hwrng/rdrand/rdseed as a source of entropy for resp. CryptGenRandom and /dev/random /dev/urandom so to some extend a separate function is not required.
Also note hwrnd/rdrand/rdseed are slow, hence if some speed is required it is best to use them just to seed a quality PRNG like the mersenne twister or KISS.
A simple example for linux:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program hwrndtest;{takes a hwrng value if present and seeds Randseed with it.}{$ifdef fpc}{$mode delphi}{$H+}{$I-}{$endif}uses sysutils,classes;varL:TFilestream;begin if fileexists('/dev/hwrng') then begin L:= TFilestream.create('/dev/hwrng', fmOpenread); try RandSeed:=L.ReadDword; finally writeln(RandSeed); L.Free; end; end else writeln('no hardware rng present');end.
sam707:
Big thank you @thaddy, your answer was very accurate this time.
After reading plenty of stuffs, I found that article of interest for my purpose and I'm going to give it a try (because i'ma crossplatfarm moron ya kno :D )
https://en.wikipedia.org/wiki/Blum_Blum_Shub
Navigation
[0] Message Index
[#] Next page