Skip to content
Merged
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
2 changes: 1 addition & 1 deletion ext/jsbn.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ function bnpSquareTo(r) {
// r != q, this != m. q or r may be null.
function bnpDivRemTo(m,q,r) {
var pm = m.abs();
if(pm.t <= 0) return;
if(pm.t <= 0) throw "BigInteger divide by zero";
var pt = this.abs();
if(pt.t < pm.t) {
if(q != null) q.fromInt(0);
Expand Down
9 changes: 9 additions & 0 deletions ext/rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ function RSASetPublic(N, E) {
} else {
throw "Invalid RSA public key";
}

if (this.n == null ||
typeof this.n.compareTo !== "function" ||
this.n.compareTo(BigInteger.ONE) <= 0 ||
this.e == null ||
isNaN(this.e) ||
this.e <= 0) {
throw "Invalid RSA public key";
}
}

// Perform raw public operation on "x": return x^e (mod n)
Expand Down
26 changes: 25 additions & 1 deletion test/qunit-do-crypto.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,31 @@
equal(n, 100, "100 times success:" + n0 + ":" + n1 + ":" + n2 + ":" + n3);
});

test("RSASetPublic rejects zero modulus", function() {
throws(function() {
var pub = new RSAKey();
pub.setPublic("00", "10001");
},
"Invalid RSA public key",
"reject zero modulus");
});

test("KEYUTIL.getKey rejects JWK with zero modulus", function() {
throws(function() {
KEYUTIL.getKey({kty: "RSA", n: "AA", e: "AQAB"});
},
"Invalid RSA public key",
"reject JWK n=0");
});

test("BigInteger.modPowInt throws when modulus is zero", function() {
throws(function() {
new BigInteger("deadbeef", 16).modPowInt(65537, BigInteger.ZERO);
},
"BigInteger divide by zero",
"reject mod(0)");
});

test("MessageDigest test", function() {
expect(10);
var md1 = new KJUR.crypto.MessageDigest({"alg": "sha1", "prov": "cryptojs"});
Expand Down Expand Up @@ -419,4 +444,3 @@ <h2 id="qunit-userAgent"></h2>
</p>
</body>
</html>

Loading