Skip to content

Commit

Permalink
#442 RSAGenerate key length issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kjur committed Jun 19, 2020
1 parent 108c7df commit 3bcc088
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.txt
Expand Up @@ -6,8 +6,13 @@ ChangeLog for jsrsasign
- allow alternative algorithms to sign CRLs (#440)
- src/asn1cms.js
- improve CMSUtil.newSignedData helper with detached signatures (#441)
- ext/rsa2.js
- RSAGenerate fixed for not having requesting key length (#442)
- sample_node
- pemtobin was fixed for pemtohex function
- test
- qunit-do-rsagenkeylen.html new test code for (#442)
- index.html, qunit-do-x509.html link update

extended Authority/SubjectKeyIdentifier support
* Changes from 8.0.15 to 8.0.16 (2020-Mar-29)
Expand Down
12 changes: 7 additions & 5 deletions ext/rsa2.js
Expand Up @@ -202,11 +202,13 @@ function RSAGenerate(B,E) {
var phi = p1.multiply(q1);
if(phi.gcd(ee).compareTo(BigInteger.ONE) == 0) {
this.n = this.p.multiply(this.q); // this.n = p * q
this.d = ee.modInverse(phi); // this.d =
this.dmp1 = this.d.mod(p1); // this.dmp1 = d mod (p - 1)
this.dmq1 = this.d.mod(q1); // this.dmq1 = d mod (q - 1)
this.coeff = this.q.modInverse(this.p); // this.coeff = (q ^ -1) mod p
break;
if (this.n.bitLength() == B) {
this.d = ee.modInverse(phi); // this.d =
this.dmp1 = this.d.mod(p1); // this.dmp1 = d mod (p - 1)
this.dmq1 = this.d.mod(q1); // this.dmq1 = d mod (q - 1)
this.coeff = this.q.modInverse(this.p); // this.coeff = (q ^ -1) mod p
break;
}
}
}
this.isPrivate = true;
Expand Down
1 change: 1 addition & 0 deletions test/index.html
Expand Up @@ -69,6 +69,7 @@
<li><a href="qunit-do-keyutil-keyid.html">qunit-do-keyutil-keyid.html</a></li>
<li><a href="qunit-do-package-jwths.html">qunit-do-package-jwths.html</a></li>
<li><a href="qunit-do-package-rsa.html">qunit-do-package-rsa.html</a></li>
<li><a href="qunit-do-rsagenkeylen.html">qunit-do-rsagenkeylen.html</a></li>
<li><a href="qunit-do-rsapem.html">qunit-do-rsapem.html</a></li>
<li><a href="qunit-do-rsasign-pss.html">qunit-do-rsasign-pss.html</a></li>
<li><a href="qunit-do-rsasign.html">qunit-do-rsasign.html</a></li>
Expand Down
50 changes: 50 additions & 0 deletions test/qunit-do-rsagenkeylen.html
@@ -0,0 +1,50 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for RSAKey genarated key length test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/prng4.js"></script>
<script src="../ext/rng.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>

<script>
$(document).ready(function(){
//=========================================================================
module("RSAKey.generate() Test");

test("RSAGenerate 100 generated 512bit key size check test", function() {
var nbit = 512;
//var nbit = 1024;
//var nbit = 2048;
var isCorrectLength = true;
for (var i = 0; i < 100; i++) {
var key = new RSAKey();
key.generate(nbit, '10001');
if (key.n.bitLength() != nbit) isCorrectLength = false;
}
equal(isCorrectLength, true, "all 100 keys are " + nbit + "bit length");
});

});
</script>

</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>

<p>
<a href="../">TOP</a> |
<a href="index.html">TEST INDEX</a> |
</p>

</body>
</html>
1 change: 0 additions & 1 deletion test/qunit-do-x509.html
Expand Up @@ -494,6 +494,5 @@
</p>

</body>
<center><p>&copy; 2010-2017 Kenji Urushima</p></center>
</html>

0 comments on commit 3bcc088

Please sign in to comment.