Skip to content

Commit

Permalink
Fixed a issue when the key was generated by 1 bit smaller than specified
Browse files Browse the repository at this point in the history
  • Loading branch information
s.vychegzhanin committed Jan 11, 2016
1 parent 725b335 commit c061fdb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ Questions, comments, bug reports, and pull requests are all welcome.

## Changelog

### 0.2.30
* Fixed a issue when the key was generated by 1 bit smaller than specified. It may slow down the generation of large keys.

### 0.2.24
* Now used old hash APIs for webpack compatible.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-rsa",
"version": "0.2.26",
"version": "0.2.30",
"description": "Node.js RSA library",
"main": "src/NodeRSA.js",
"scripts": {
Expand Down
7 changes: 3 additions & 4 deletions src/libs/rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ module.exports.Key = (function () {
var phi = p1.multiply(q1);
if (phi.gcd(ee).compareTo(BigInteger.ONE) === 0) {
this.n = this.p.multiply(this.q);
if (this.n.bitLength() < B) {
continue;
}
this.d = ee.modInverse(phi);
this.dmp1 = this.d.mod(p1);
this.dmq1 = this.d.mod(q1);
Expand Down Expand Up @@ -303,10 +306,6 @@ module.exports.Key = (function () {
this.cache = this.cache || {};
// Bit & byte length
this.cache.keyBitLength = this.n.bitLength();
if (this.cache.keyBitLength % 2 == 1) {
this.cache.keyBitLength = this.cache.keyBitLength + 1;
}

this.cache.keyByteLength = (this.cache.keyBitLength + 6) >> 3;
};

Expand Down

0 comments on commit c061fdb

Please sign in to comment.