Skip to content

Is seeding wrong? #114

@ghost

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions