Skip to content
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

Add additional PRNG #1774

Merged
merged 3 commits into from
May 19, 2021
Merged

Add additional PRNG #1774

merged 3 commits into from
May 19, 2021

Conversation

t-bast
Copy link
Member

@t-bast t-bast commented Apr 19, 2021

In case of catastrophic failures of the SecureRandom instance, we add a secondary randomness source that we mix into the random stream.

This is a somewhat weak random source and should not be used on its own, but it doesn't hurt to xor it with the output of SecureRandom.

The second commit should be reviewed independently: it simply adds parenthesis to functions that generate random things, since these have side-effects. It's trivial but painful to review since it touches a lot of test files.

NB: this feature make a lot of sense in https://github.com/acinq/lightning-kmp as well since mobile platforms may have more common randomness failures.

@t-bast t-bast force-pushed the secondary-random-generator branch 2 times, most recently from d152522 to dd903c4 Compare April 20, 2021 10:44
@codecov-commenter
Copy link

codecov-commenter commented Apr 20, 2021

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 95.19231% with 5 lines in your changes missing coverage. Please review.

Project coverage is 89.38%. Comparing base (5a92f84) to head (9fb8417).
Report is 654 commits behind head on master.

Files with missing lines Patch % Lines
...scala/fr/acinq/eclair/payment/send/Autoprobe.scala 0.00% 2 Missing ⚠️
...scala/fr/acinq/eclair/crypto/WeakEntropyPool.scala 94.73% 1 Missing ⚠️
...scala/fr/acinq/eclair/tor/TorProtocolHandler.scala 50.00% 1 Missing ⚠️
...nt/src/main/scala/fr/acinq/eclair/FrontSetup.scala 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1774      +/-   ##
==========================================
+ Coverage   89.27%   89.38%   +0.10%     
==========================================
  Files         143      145       +2     
  Lines       10948    11030      +82     
  Branches      480      466      -14     
==========================================
+ Hits         9774     9859      +85     
+ Misses       1174     1171       -3     
Files with missing lines Coverage Δ
...r-core/src/main/scala/fr/acinq/eclair/Eclair.scala 53.14% <ø> (ø)
...re/src/main/scala/fr/acinq/eclair/NodeParams.scala 92.69% <100.00%> (ø)
...ir-core/src/main/scala/fr/acinq/eclair/Setup.scala 80.35% <100.00%> (+0.11%) ⬆️
...c/main/scala/fr/acinq/eclair/channel/Channel.scala 86.33% <100.00%> (ø)
...src/main/scala/fr/acinq/eclair/crypto/Random.scala 100.00% <100.00%> (ø)
...air/crypto/keymanager/LocalChannelKeyManager.scala 88.63% <100.00%> (ø)
...-core/src/main/scala/fr/acinq/eclair/io/Peer.scala 89.89% <100.00%> (ø)
...-core/src/main/scala/fr/acinq/eclair/package.scala 75.55% <100.00%> (+0.55%) ⬆️
.../scala/fr/acinq/eclair/payment/PaymentPacket.scala 91.42% <100.00%> (ø)
...scala/fr/acinq/eclair/payment/PaymentRequest.scala 92.13% <100.00%> (ø)
... and 7 more

... and 1 file with indirect coverage changes

@t-bast t-bast force-pushed the secondary-random-generator branch from 99da5a4 to 1c31cf7 Compare April 22, 2021 10:06
@t-bast t-bast marked this pull request as ready for review April 22, 2021 10:07
@t-bast t-bast force-pushed the secondary-random-generator branch 2 times, most recently from 35037f1 to 0df44d9 Compare April 26, 2021 17:24
In case of catastrophic failures of the `SecureRandom` instance, we add
a secondary randomness source that we mix into the random stream.

This is a somewhat weak random source and should not be used on its own,
but it doesn't hurt to xor it with the output of `SecureRandom`.

We use an actor that listens to events in the system and inject them
in our weak pseudo-RNG.
These functions have side-effects, it was incorrect and misleading to expose
them without parenthesis.
@t-bast t-bast force-pushed the secondary-random-generator branch from 1e9f0ce to 1e1037f Compare May 17, 2021 15:18
@pm47 pm47 requested a review from sstone May 17, 2021 15:23
pm47
pm47 previously approved these changes May 17, 2021
Copy link
Member

@pm47 pm47 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

According to this, XORing two pseudorandom data sources cannot reduce randomness, as long as the two sources are unrelated to each other. This is the case here because we know exactly how the WeakRandom generator works.

@pm47
Copy link
Member

pm47 commented May 17, 2021

Let's wait for a full review from @sstone before merging.

ChaCha20 is designed to allow encrypting directly inside the plaintext
array to avoid allocating another array for the ciphertext. We add a test
case to ensure this is working as expected.
@t-bast t-bast merged commit 76894bd into master May 19, 2021
@t-bast t-bast deleted the secondary-random-generator branch May 19, 2021 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants