-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement JitterRng
, based on jitterentropy-library
.
#28
Changes from 1 commit
07e1d58
6e40910
49e9bb0
ed358de
c57aa1a
08dc010
14136e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,7 +109,7 @@ impl ErrorKind { | |
ErrorKind::CoarseTimer => "coarse timer", | ||
ErrorKind::NotMonotonic => "timer not monotonic", | ||
ErrorKind::TinyVariantions => "time delta variations too small", | ||
ErrorKind::ToManyStuck => "to many stuck results", | ||
ErrorKind::ToManyStuck => "too many stuck results", | ||
ErrorKind::__Nonexhaustive => unreachable!(), | ||
} | ||
} | ||
|
@@ -127,7 +127,7 @@ impl fmt::Display for TimerError { | |
ErrorKind::TinyVariantions => | ||
write!(f, "Variations of deltas of time too small."), | ||
ErrorKind::ToManyStuck => | ||
write!(f, "To many stuck results (indicating no added entropy)."), | ||
write!(f, "Too many stuck results (indicating no added entropy)."), | ||
ErrorKind::__Nonexhaustive => unreachable!(), | ||
} | ||
} | ||
|
@@ -361,6 +361,9 @@ impl JitterRng { | |
// Get time stamp and calculate time delta to previous | ||
// invocation to measure the timing variations | ||
let time = (self.timer)(); | ||
// Note: wrapping_sub combined with a cast to `i64` generates a correct | ||
// delta, even in the unlikely case this is a timer than is not strictly | ||
// monotonic. | ||
let current_delta = time.wrapping_sub(self.prev_time) as i64; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be worth adding a note that wrapping arithmetic on unsigned integers followed by cast to i64 generates correct deltas in most cases (including where both times have the highest bit set and where one has wrapped). [The exception is where the actual delta is not representable as an |
||
self.prev_time = time; | ||
|
||
|
@@ -422,7 +425,7 @@ impl JitterRng { | |
// we rely on it to not recognise the opportunity. | ||
for i in 0..64 { | ||
let apply = (self.data >> i) & 1; | ||
let mask = !((apply as i64) - 1) as u64; | ||
let mask = !apply.wrapping_sub(1); | ||
mixer ^= CONSTANT & mask; | ||
mixer = mixer.rotate_left(1); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a timer that is not strictly ... ?