Improve Fortuna PRNG #363
Labels
No labels
bug
duplicate
enhancement
feature
help wanted
improve API
invalid
needs documentation
not-planned
rtfm
stale
support
wishlist
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libtom/libtomcrypt!363
Loading…
Reference in a new issue
No description provided.
Delete branch "improve/fortuna"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This updates the Fortuna implementation to be more in-line with the original specification.
It adds the
fortuna_add_random_event()function, an alternative tofortuna_add_entropy()and makesfortuna_update_seed()public.Additionally it fixes a bug in the reseed rate-limit which should only happen after
pool0_len >= 64ANDrate-limit expiredwhich was an OR before, c.f. Chapter 9.5.5 of [1].Or simplified as stated by @tyzoid in IRC, the new behavior is "...if we've got enough entropy in the buffer, and it's been long enough that we probably should reseed, then we will do so" whereas the old buggy behavior was "...pretty much constantly reseeding with an empty buffer".
Not that I am against this PR, I only need more time for review, stay tuned.
LGTM Otherwise.
@ -64,0 +80,4 @@cur_time -= CONST64(116444736000000000); /* subtract epoch in microseconds */cur_time /= 1000; /* nanoseconds -> microseconds */#endifreturn cur_time / 100;cur_timehere is uninitialized if neither_POSIX_C_SOURCE >= 200112Lor_WIN32is defined. I'd recommend either initializing it to0on line 68, or adding an additional#elsebefore line 82, with an#errortrigger to positively alert to a problem.@ -366,0 +378,4 @@* LTC_FORTUNA_RESEED_RATELIMIT_TIMED* is defined.*/#undef LTC_FORTUNA_RESEED_RATELIMIT_TIMEDWe should warn if we
#undefthis constant here, because it indicates a fault in user-code.@ -64,0 +80,4 @@cur_time -= CONST64(116444736000000000); /* subtract epoch in microseconds */cur_time /= 1000; /* nanoseconds -> microseconds */#endifreturn cur_time / 100;As pointed out by @sjaeckel on IRC, this isn't a problem, because
src/headers/tomcrypt_custom.hon line 362 checks to make sure that these constants are defined.@ -366,0 +378,4 @@* LTC_FORTUNA_RESEED_RATELIMIT_TIMED* is defined.*/#undef LTC_FORTUNA_RESEED_RATELIMIT_TIMEDdone
LGTM.