Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
f3eb1127
Commit
f3eb1127
authored
Aug 22, 2015
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
rng: static initialisation of hasRdrand()
parent
ddc7b2fb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/rng.h
+13
-6
13 additions, 6 deletions
include/opendht/rng.h
src/rng.cpp
+4
-6
4 additions, 6 deletions
src/rng.cpp
with
17 additions
and
12 deletions
include/opendht/rng.h
+
13
−
6
View file @
f3eb1127
...
...
@@ -68,7 +68,7 @@ public:
}
double
entropy
()
const
{
if
(
has
_r
drand
or
has
_r
dseed
)
if
(
has
R
drand
()
or
has
R
dseed
()
)
return
1.
;
return
0.
;
}
...
...
@@ -76,11 +76,21 @@ public:
private
:
random_device
&
operator
=
(
random_device
&
)
=
delete
;
const
bool
has_rdrand
;
const
bool
has_rdseed
;
pseudo_engine
gen
;
std
::
uniform_int_distribution
<
result_type
>
dis
{};
static
bool
hasIntelCpu
();
static
bool
hasRdrand
()
{
static
const
bool
hasrdrand
=
_hasRdrand
();
return
hasrdrand
;
}
static
bool
hasRdseed
()
{
static
const
bool
hasrdseed
=
_hasRdseed
();
return
hasrdseed
;
}
static
bool
_hasRdrand
();
static
bool
_hasRdseed
();
struct
CPUIDinfo
{
unsigned
int
EAX
;
unsigned
int
EBX
;
...
...
@@ -88,9 +98,6 @@ private:
unsigned
int
EDX
;
void
get
(
const
unsigned
int
func
,
const
unsigned
int
subfunc
);
};
static
bool
hasIntelCpu
();
static
bool
hasRdrand
();
static
bool
hasRdseed
();
bool
rdrandStep
(
result_type
*
r
);
bool
rdrand
(
result_type
*
r
);
bool
rdseedStep
(
result_type
*
r
);
...
...
This diff is collapsed.
Click to expand it.
src/rng.cpp
+
4
−
6
View file @
f3eb1127
...
...
@@ -37,8 +37,6 @@ namespace dht {
namespace
crypto
{
random_device
::
random_device
()
:
has_rdrand
(
hasRdrand
()),
has_rdseed
(
hasRdseed
()),
gen
(
std
::
chrono
::
system_clock
::
now
().
time_since_epoch
().
count
())
{}
...
...
@@ -47,9 +45,9 @@ random_device::operator()()
{
result_type
prand
=
dis
(
gen
);
result_type
hwrand
;
if
(
has
_r
dseed
and
rdseed
(
&
hwrand
))
if
(
has
R
dseed
()
and
rdseed
(
&
hwrand
))
prand
^=
hwrand
;
else
if
(
has
_r
drand
and
rdrand
(
&
hwrand
))
else
if
(
has
R
drand
()
and
rdrand
(
&
hwrand
))
prand
^=
hwrand
;
return
prand
;
}
...
...
@@ -78,7 +76,7 @@ random_device::hasIntelCpu()
}
bool
random_device
::
hasRdrand
()
random_device
::
_
hasRdrand
()
{
if
(
!
hasIntelCpu
())
return
false
;
...
...
@@ -92,7 +90,7 @@ random_device::hasRdrand()
}
bool
random_device
::
hasRdseed
()
random_device
::
_
hasRdseed
()
{
if
(
!
hasIntelCpu
())
return
false
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment