File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed
Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -354,7 +354,7 @@ function bnpSquareTo(r) {
354354// r != q, this != m. q or r may be null.
355355function bnpDivRemTo ( m , q , r ) {
356356 var pm = m . abs ( ) ;
357- if ( pm . t <= 0 ) return ;
357+ if ( pm . t <= 0 ) throw "BigInteger divide by zero" ;
358358 var pt = this . abs ( ) ;
359359 if ( pt . t < pm . t ) {
360360 if ( q != null ) q . fromInt ( 0 ) ;
Original file line number Diff line number Diff line change @@ -167,6 +167,15 @@ function RSASetPublic(N, E) {
167167 } else {
168168 throw "Invalid RSA public key" ;
169169 }
170+
171+ if ( this . n == null ||
172+ typeof this . n . compareTo !== "function" ||
173+ this . n . compareTo ( BigInteger . ONE ) <= 0 ||
174+ this . e == null ||
175+ isNaN ( this . e ) ||
176+ this . e <= 0 ) {
177+ throw "Invalid RSA public key" ;
178+ }
170179}
171180
172181// Perform raw public operation on "x": return x^e (mod n)
Original file line number Diff line number Diff line change 232232 equal ( n , 100 , "100 times success:" + n0 + ":" + n1 + ":" + n2 + ":" + n3 ) ;
233233} ) ;
234234
235+ test ( "RSASetPublic rejects zero modulus" , function ( ) {
236+ throws ( function ( ) {
237+ var pub = new RSAKey ( ) ;
238+ pub . setPublic ( "00" , "10001" ) ;
239+ } ,
240+ "Invalid RSA public key" ,
241+ "reject zero modulus" ) ;
242+ } ) ;
243+
244+ test ( "KEYUTIL.getKey rejects JWK with zero modulus" , function ( ) {
245+ throws ( function ( ) {
246+ KEYUTIL . getKey ( { kty : "RSA" , n : "AA" , e : "AQAB" } ) ;
247+ } ,
248+ "Invalid RSA public key" ,
249+ "reject JWK n=0" ) ;
250+ } ) ;
251+
252+ test ( "BigInteger.modPowInt throws when modulus is zero" , function ( ) {
253+ throws ( function ( ) {
254+ new BigInteger ( "deadbeef" , 16 ) . modPowInt ( 65537 , BigInteger . ZERO ) ;
255+ } ,
256+ "BigInteger divide by zero" ,
257+ "reject mod(0)" ) ;
258+ } ) ;
259+
235260test ( "MessageDigest test" , function ( ) {
236261 expect ( 10 ) ;
237262 var md1 = new KJUR . crypto . MessageDigest ( { "alg" : "sha1" , "prov" : "cryptojs" } ) ;
@@ -419,4 +444,3 @@ <h2 id="qunit-userAgent"></h2>
419444</ p >
420445</ body >
421446</ html >
422-
You can’t perform that action at this time.
0 commit comments