RandomRDRand.st
changeset 5067 2fbc7ccd7e68
parent 4927 8e944da8fc20
child 5080 aeb43e5edb85
equal deleted inserted replaced
5066:3e6e4e1231d8 5067:2fbc7ccd7e68
    42 "
    42 "
    43     This generator uses the rdgen random generator which is built into modern intel chips.
    43     This generator uses the rdgen random generator which is built into modern intel chips.
    44     Before using, you should check via the isSupported query.
    44     Before using, you should check via the isSupported query.
    45 
    45 
    46     Warning:
    46     Warning:
    47 	there have been discussions about the security of the intel rdgen instruction
    47         there have been discussions about the security of the intel rdgen instruction
    48 	and whether there are NSA backdoors built into it.
    48         and whether there are NSA backdoors built into it.
    49 	Linus Torwalds refuses to use it for /dev/urandom in the linux kernel, for that very reason.
    49         Linus Torwalds refuses to use it for /dev/urandom in the linux kernel, for that very reason.
    50 	Be sure you know what you are doing, if you use this generator for sensitive cryptographic stuff.
    50         Be sure you know what you are doing, if you use this generator for sensitive cryptographic stuff.
    51 	We recommend using one of the libcrypt-based generators and use this only to get additional
    51         We recommend using one of the libcrypt-based generators and use this only to get additional
    52 	entropy for the seed.
    52         entropy for the seed.
    53 
    53 
       
    54     Warning2:
       
    55         the initial release of the AMD Ryzen3000 (without BIOS update) has a bug in returning the same
       
    56         (all 1s) random number every time.
       
    57         The code here checks for that an raises an error in the constructor if that bug is detected.
       
    58         Be sure to catch this exception in your code and fall back to another random generator if raised.
       
    59         
    54     NO WARRANTY
    60     NO WARRANTY
    55 
    61 
    56     RandomRDGen new nextInteger
    62     RandomRDGen new nextInteger
    57 
    63 
    58     [see also:]
    64     [see also:]
    59 	RandomGenerator - the default; uses the machine's /dev/random if available
    65         RandomGenerator - the default; uses the machine's /dev/random if available
    60 	Random  - fast, but generates less quality random numbers
    66         Random  - fast, but generates less quality random numbers
    61 	RandomTT800 - another random generator
    67         RandomTT800 - another random generator
    62 	RandomParkMiller - another random generator
    68         RandomParkMiller - another random generator
    63 	RandomMT19937 - another random generator
    69         RandomMT19937 - another random generator
    64 	RandomKISS - another random generator
    70         RandomKISS - another random generator
    65 	exept:libcrypt - a library containing more stuff based on hashes and cyphers
    71         exept:libcrypt - a library containing more stuff based on hashes and cyphers
    66 
    72 
    67     [author:]
    73     [author:]
    68 	Claus Gittinger.
    74         Claus Gittinger.
    69 "
    75 "
    70 ! !
    76 ! !
    71 
    77 
    72 !RandomRDRand class methodsFor:'instance creation'!
    78 !RandomRDRand class methodsFor:'instance creation'!
    73 
    79 
   103 ! !
   109 ! !
   104 
   110 
   105 !RandomRDRand methodsFor:'initialization'!
   111 !RandomRDRand methodsFor:'initialization'!
   106 
   112 
   107 initialize
   113 initialize
       
   114     "check for Ryzen RDRAND bug (returning the same all-ones everytime)"
       
   115 
       
   116     |i1 i2|
       
   117 
       
   118     i1 := self nextInteger.
       
   119     i2 := self nextInteger.
       
   120     (i1 = i2) ifTrue:[
       
   121         self error:'Ryzen RDRand bug detected'
       
   122     ].
       
   123 
       
   124     "
       
   125      self new
       
   126     "
       
   127 
       
   128     "Modified (comment): / 25-07-2019 / 13:30:28 / Claus Gittinger"
   108 !
   129 !
   109 
   130 
   110 seed:seed
   131 seed:seed
   111     "/ ignored
   132     "/ ignored
   112 ! !
   133 ! !