Skip to content

Commit

Permalink
ecdsa-modified: fix getBigRandom()
Browse files Browse the repository at this point in the history
this replaces the previously remainder-based limiting of the random number
which caused bias toward small numbers and excluded zero altogether by
simple filtering as proposed frequently in
kjur#221
and because the performance in most cases is actually faster than in the
present implementation;

also, an adaptation of swiftlang/swift#39143 has
been considered but it performed significantly slower for large integers;
  • Loading branch information
tvogel committed Nov 14, 2024
1 parent 58bb241 commit 4c12028
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/ecdsa-modified-1.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ KJUR.crypto.ECDSA = function(params) {
//===========================
// PUBLIC METHODS
//===========================
/*
* Generate uniformly distributed big random integer in 0 <= x < limit
*/
this.getBigRandom = function (limit) {
return new _BigInteger(limit.bitLength(), rng)
.mod(limit.subtract(_BigInteger.ONE))
.add(_BigInteger.ONE)
;
var bitLength = limit.subtract(_BigInteger.ONE).bitLength();
do {
var result = new _BigInteger(bitLength, rng);
} while (result.compareTo(limit) >= 0);
return result;
};

this.setNamedCurve = function(curveName) {
Expand Down

0 comments on commit 4c12028

Please sign in to comment.