Skip to content

Commit 44b1dde

Browse files
RuiyuZhuRuiyu Zhuwangxiao1254
authored
Fix silent failure in CPU seed generation (#156)
* Fix silent failure in CPU seed generation According to https://bugzilla.kernel.org/show_bug.cgi?id=85911, an AMD CPU may keep generating all zero or all one "random values" after sleep-resume. This commit is to address this concern * add explanation Co-authored-by: Ruiyu Zhu <[email protected]> Co-authored-by: Xiao Wang <[email protected]>
1 parent 54f35ef commit 44b1dde

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

emp-tool/utils/prg.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "emp-tool/utils/aes.h"
55
#include "emp-tool/utils/utils.h"
66
#include "emp-tool/utils/constants.h"
7+
#include <climits>
78
#include <memory>
89

910
#ifdef ENABLE_RDSEED
@@ -31,12 +32,13 @@ class PRG { public:
3132
#else
3233
unsigned long long r0, r1;
3334
int i = 0;
35+
// To prevent an AMD CPU bug. (PR #156)
3436
for(; i < 10; ++i)
35-
if(_rdseed64_step(&r0) == 1) break;
37+
if((_rdseed64_step(&r0) == 1) && (r0 != ULLONG_MAX) && (r0 != 0)) break;
3638
if(i == 10)error("RDSEED FAILURE");
3739

3840
for(i = 0; i < 10; ++i)
39-
if(_rdseed64_step(&r1) == 1) break;
41+
if((_rdseed64_step(&r1) == 1) && (r1 != ULLONG_MAX) && (r1 != 0)) break;
4042
if(i == 10)error("RDSEED FAILURE");
4143

4244
v = makeBlock(r0, r1);

0 commit comments

Comments
 (0)