Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/key_generators/ec_key_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ class ECKeyGenerator implements KeyGenerator {
}

@override
AsymmetricKeyPair generateKeyPair() {
AsymmetricKeyPair generateKeyPair({BigInt? d = null}) {
var n = _params.n;
var nBitLength = n.bitLength;
BigInt? d;

do {
d = _random.nextBigInteger(nBitLength);
} while (d == BigInt.zero || (d >= n));
if (d == null) {
do {
d = _random.nextBigInteger(nBitLength);
} while (d == BigInt.zero || (d >= n));
}

var Q = _params.G * d;

Expand Down
2 changes: 1 addition & 1 deletion lib/key_generators/rsa_key_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class RSAKeyGenerator implements KeyGenerator {
}

@override
AsymmetricKeyPair generateKeyPair() {
AsymmetricKeyPair generateKeyPair({BigInt? d = null}) {
BigInt p, q, n, e;

// p and q values should have a length of half the strength in bits
Expand Down
2 changes: 1 addition & 1 deletion lib/src/api/key_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ abstract class KeyGenerator extends Algorithm {
void init(CipherParameters params);

/// Generate a key pair.
AsymmetricKeyPair generateKeyPair();
AsymmetricKeyPair generateKeyPair({BigInt? d = null});
}