Skip to content

Commit c061fdb

Browse files
author
s.vychegzhanin
committed
Fixed a issue when the key was generated by 1 bit smaller than specified
1 parent 725b335 commit c061fdb

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ Questions, comments, bug reports, and pull requests are all welcome.
209209

210210
## Changelog
211211

212+
### 0.2.30
213+
* Fixed a issue when the key was generated by 1 bit smaller than specified. It may slow down the generation of large keys.
214+
212215
### 0.2.24
213216
* Now used old hash APIs for webpack compatible.
214217

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-rsa",
3-
"version": "0.2.26",
3+
"version": "0.2.30",
44
"description": "Node.js RSA library",
55
"main": "src/NodeRSA.js",
66
"scripts": {

src/libs/rsa.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ module.exports.Key = (function () {
115115
var phi = p1.multiply(q1);
116116
if (phi.gcd(ee).compareTo(BigInteger.ONE) === 0) {
117117
this.n = this.p.multiply(this.q);
118+
if (this.n.bitLength() < B) {
119+
continue;
120+
}
118121
this.d = ee.modInverse(phi);
119122
this.dmp1 = this.d.mod(p1);
120123
this.dmq1 = this.d.mod(q1);
@@ -303,10 +306,6 @@ module.exports.Key = (function () {
303306
this.cache = this.cache || {};
304307
// Bit & byte length
305308
this.cache.keyBitLength = this.n.bitLength();
306-
if (this.cache.keyBitLength % 2 == 1) {
307-
this.cache.keyBitLength = this.cache.keyBitLength + 1;
308-
}
309-
310309
this.cache.keyByteLength = (this.cache.keyBitLength + 6) >> 3;
311310
};
312311

0 commit comments

Comments
 (0)