Browse Source

add tests for MAX_RSA_SIZE sized openssl-standard RSA keys

Steffen Jaeckel 8 years ago
parent
commit
0500aaec45
1 changed files with 61 additions and 0 deletions
  1. 61 0
      tests/rsa_test.c

+ 61 - 0
tests/rsa_test.c

@@ -285,6 +285,63 @@ static int rsa_compat_test(void)
    return 0;
 }
 
+static int _rsa_key_cmp(const int should_type, const rsa_key *should, const rsa_key *is)
+{
+   if(should_type != is->type)
+      return CRYPT_ERROR;
+   if(should_type == PK_PRIVATE) {
+      if(mp_cmp(should->q, is->q) != LTC_MP_EQ)
+         return CRYPT_ERROR;
+      if(mp_cmp(should->p, is->p) != LTC_MP_EQ)
+         return CRYPT_ERROR;
+      if(mp_cmp(should->qP, is->qP) != LTC_MP_EQ)
+         return CRYPT_ERROR;
+      if(mp_cmp(should->dP, is->dP) != LTC_MP_EQ)
+         return CRYPT_ERROR;
+      if(mp_cmp(should->dQ, is->dQ) != LTC_MP_EQ)
+         return CRYPT_ERROR;
+      if(mp_cmp(should->d, is->d) != LTC_MP_EQ)
+         return CRYPT_ERROR;
+   }
+   if(mp_cmp(should->N, is->N) != LTC_MP_EQ)
+      return CRYPT_ERROR;
+   if(mp_cmp(should->e, is->e) != LTC_MP_EQ)
+      return CRYPT_ERROR;
+   return CRYPT_OK;
+}
+
+static int _rsa_issue_301(int prng_idx)
+{
+   rsa_key       key, key_in;
+   unsigned char buf[MAX_RSA_SIZE];
+   unsigned long len;
+
+   DO(rsa_make_key(&yarrow_prng, prng_idx, MAX_RSA_SIZE/8, 65537, &key));
+
+   len = sizeof(buf);
+   DO(rsa_export(buf, &len, PK_PRIVATE, &key));
+   DO(rsa_import(buf, len, &key_in));
+
+   DO(_rsa_key_cmp(PK_PRIVATE, &key, &key_in));
+   rsa_free(&key_in);
+
+   len = sizeof(buf);
+   DO(rsa_export(buf, &len, PK_PUBLIC, &key));
+   DO(rsa_import(buf, len, &key_in));
+
+   DO(_rsa_key_cmp(PK_PUBLIC, &key, &key_in));
+   rsa_free(&key_in);
+
+   len = sizeof(buf);
+   DO(rsa_export(buf, &len, PK_PUBLIC | PK_STD, &key));
+   DO(rsa_import(buf, len, &key_in));
+
+   DO(_rsa_key_cmp(PK_PUBLIC, &key, &key_in));
+   rsa_free(&key_in);
+
+   return 0;
+}
+
 int rsa_test(void)
 {
    unsigned char in[1024], out[1024], tmp[3072];
@@ -308,6 +365,10 @@ int rsa_test(void)
       return 1;
    }
 
+   if (_rsa_issue_301(prng_idx) != 0) {
+      return 1;
+   }
+
    /* make 10 random key */
    for (cnt = 0; cnt < 10; cnt++) {
       DO(rsa_make_key(&yarrow_prng, prng_idx, 1024/8, 65537, &key));