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

Is seeding wrong? #114

Closed
EP-u-NW opened this issue Jul 3, 2021 · 4 comments
Closed

Is seeding wrong? #114

EP-u-NW opened this issue Jul 3, 2021 · 4 comments

Comments

@EP-u-NW
Copy link

EP-u-NW commented Jul 3, 2021

While reading tutorials/rsa.md

SecureRandom exampleSecureRandom() {
  final secureRandom = FortunaRandom();

  final seedSource = Random.secure();
  final seeds = <int>[];
  for (int i = 0; i < 32; i++) {
    seeds.add(seedSource.nextInt(255));
  }
  secureRandom.seed(KeyParameter(Uint8List.fromList(seeds)));

  return secureRandom;
}

I noticed that seedSource.nextInt(255) is used for seeding. Since in dart Random.nextInt() is exclusive, it should in my opinion be seedSource.nextInt(256) to cover the whole value range of a unsigned 1 byte integer.

If you search this repos files for .nextInt(255) this same thing will show up multiple times. In most places it's not cricital (examples and tutorials), but in lib\asymmetric\pkcs1.dart and lib\asymetric\oaep.dart it might be a serious security vulnerability.

Edit: I noticed that .nextInt(255) was removed from the files in lib I mentioned above just yesterday and replaced with

return Platform.instance.platformEntropySource().getBytes(32);`

but not in the examples and tutorials.

@mwcw
Copy link
Collaborator

mwcw commented Jul 5, 2021

Hi yes

You are right about the .nextInt(255) and

We discovered it independently when abstracting away calls to Random.secure.

the reason for return Platform.instance.platformEntropySource().getBytes(32);

Is because on the nodejs runtime it fails to find Random.secure and a source of entropy needs to be sourced from the underlying platform.

@EP-u-NW
Copy link
Author

EP-u-NW commented Jul 5, 2021

I'll leave this issue open until the tutorials are updated with the new code 😄 But feel free to close it if you think thats not necessary.

@mwcw
Copy link
Collaborator

mwcw commented Jul 5, 2021

I'll leave this issue open until the tutorials are updated with the new code 😄

Lol.. I am just waiting for it to sync up then I will do a release.

MW

@mwcw
Copy link
Collaborator

mwcw commented Jul 5, 2021

Released: #115

@EP-u-NW EP-u-NW closed this as completed Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant