@@ -285,6 +285,63 @@ static int rsa_compat_test(void)
285285 return 0 ;
286286}
287287
288+ static int _rsa_key_cmp (const int should_type , const rsa_key * should , const rsa_key * is )
289+ {
290+ if (should_type != is -> type )
291+ return CRYPT_ERROR ;
292+ if (should_type == PK_PRIVATE ) {
293+ if (mp_cmp (should -> q , is -> q ) != LTC_MP_EQ )
294+ return CRYPT_ERROR ;
295+ if (mp_cmp (should -> p , is -> p ) != LTC_MP_EQ )
296+ return CRYPT_ERROR ;
297+ if (mp_cmp (should -> qP , is -> qP ) != LTC_MP_EQ )
298+ return CRYPT_ERROR ;
299+ if (mp_cmp (should -> dP , is -> dP ) != LTC_MP_EQ )
300+ return CRYPT_ERROR ;
301+ if (mp_cmp (should -> dQ , is -> dQ ) != LTC_MP_EQ )
302+ return CRYPT_ERROR ;
303+ if (mp_cmp (should -> d , is -> d ) != LTC_MP_EQ )
304+ return CRYPT_ERROR ;
305+ }
306+ if (mp_cmp (should -> N , is -> N ) != LTC_MP_EQ )
307+ return CRYPT_ERROR ;
308+ if (mp_cmp (should -> e , is -> e ) != LTC_MP_EQ )
309+ return CRYPT_ERROR ;
310+ return CRYPT_OK ;
311+ }
312+
313+ static int _rsa_issue_301 (int prng_idx )
314+ {
315+ rsa_key key , key_in ;
316+ unsigned char buf [MAX_RSA_SIZE ];
317+ unsigned long len ;
318+
319+ DO (rsa_make_key (& yarrow_prng , prng_idx , MAX_RSA_SIZE /8 , 65537 , & key ));
320+
321+ len = sizeof (buf );
322+ DO (rsa_export (buf , & len , PK_PRIVATE , & key ));
323+ DO (rsa_import (buf , len , & key_in ));
324+
325+ DO (_rsa_key_cmp (PK_PRIVATE , & key , & key_in ));
326+ rsa_free (& key_in );
327+
328+ len = sizeof (buf );
329+ DO (rsa_export (buf , & len , PK_PUBLIC , & key ));
330+ DO (rsa_import (buf , len , & key_in ));
331+
332+ DO (_rsa_key_cmp (PK_PUBLIC , & key , & key_in ));
333+ rsa_free (& key_in );
334+
335+ len = sizeof (buf );
336+ DO (rsa_export (buf , & len , PK_PUBLIC | PK_STD , & key ));
337+ DO (rsa_import (buf , len , & key_in ));
338+
339+ DO (_rsa_key_cmp (PK_PUBLIC , & key , & key_in ));
340+ rsa_free (& key_in );
341+
342+ return 0 ;
343+ }
344+
288345int rsa_test (void )
289346{
290347 unsigned char in [1024 ], out [1024 ], tmp [3072 ];
@@ -308,6 +365,10 @@ int rsa_test(void)
308365 return 1 ;
309366 }
310367
368+ if (_rsa_issue_301 (prng_idx ) != 0 ) {
369+ return 1 ;
370+ }
371+
311372 /* make 10 random key */
312373 for (cnt = 0 ; cnt < 10 ; cnt ++ ) {
313374 DO (rsa_make_key (& yarrow_prng , prng_idx , 1024 /8 , 65537 , & key ));
0 commit comments