@@ -369,6 +369,52 @@ static int s_rsa_issue_301(int prng_idx)
369
369
return CRYPT_OK ;
370
370
}
371
371
372
+ static int s_rsa_public_ubin_e (int prng_idx )
373
+ {
374
+ rsa_key key ;
375
+ unsigned char e [32 ] = {0 };
376
+ unsigned long elen = sizeof (e );
377
+
378
+ /* Check public exponent too small */
379
+ e [elen - 1 ] = 1 ;
380
+ SHOULD_FAIL_WITH (rsa_make_key_ubin_e (& yarrow_prng , prng_idx , 128 , e , elen , & key ),
381
+ CRYPT_INVALID_ARG );
382
+
383
+ /*
384
+ * Generate about 256 bits to check error when public exponent
385
+ * overflow.
386
+ */
387
+ DO (rng_make_prng (elen * 8 , prng_idx , & yarrow_prng , NULL ));
388
+ LTC_ARGCHK (yarrow_read (e , elen , & yarrow_prng ) == elen );
389
+
390
+ /* Ensure that public exponent is:
391
+ * - odd value
392
+ * - MSB is even
393
+ */
394
+ e [elen - 1 ] |= 0x1 ;
395
+ e [0 ] &= ~0x1 ;
396
+
397
+ /* Check public exponent overflow */
398
+ /* Set high bit of MSB set to get 256 bits, to get e overflow */
399
+ e [0 ] |= 0x80 ;
400
+ SHOULD_FAIL_WITH (rsa_make_key_ubin_e (& yarrow_prng , prng_idx , 128 , e , elen , & key ),
401
+ CRYPT_INVALID_ARG );
402
+
403
+
404
+ /* Check public exponent not odd but e value < 256 bits */
405
+ e [elen - 1 ] &= ~0x1 ;
406
+ e [0 ] &= ~0x80 ;
407
+ SHOULD_FAIL_WITH (rsa_make_key_ubin_e (& yarrow_prng , prng_idx , 128 , e , elen , & key ),
408
+ CRYPT_INVALID_ARG );
409
+
410
+ /* Ensure that public exponent is odd value and e value < 256 bits */
411
+ e [elen - 1 ] |= 0x1 ;
412
+ DO (rsa_make_key_ubin_e (& yarrow_prng , prng_idx , 128 , e , elen , & key ));
413
+ rsa_free (& key );
414
+
415
+ return CRYPT_OK ;
416
+ }
417
+
372
418
#ifdef LTC_TEST_READDIR
373
419
static int s_rsa_import_x509 (const void * in , unsigned long inlen , void * key )
374
420
{
@@ -426,6 +472,7 @@ int rsa_test(void)
426
472
427
473
DO (s_rsa_cryptx_issue_69 ());
428
474
DO (s_rsa_issue_301 (prng_idx ));
475
+ DO (s_rsa_public_ubin_e (prng_idx ));
429
476
430
477
/* make 10 random key */
431
478
for (cnt = 0 ; cnt < 10 ; cnt ++ ) {
0 commit comments