]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
allow a missing u
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Fri, 31 Jan 2014 13:17:33 +0000 (14:17 +0100)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Fri, 31 Jan 2014 13:21:20 +0000 (14:21 +0100)
lib/gnutls_privkey_raw.c
lib/nettle/pk.c
lib/x509/privkey.c

index dafbe11e21a6779352d7909f8a54f87f4bd6f65c..002447d4e528cc00095918836bc0679212f12d4c 100644 (file)
@@ -180,9 +180,9 @@ int ret;
  * @d: holds the private exponent
  * @p: holds the first prime (p)
  * @q: holds the second prime (q)
- * @u: holds the coefficient
- * @e1: holds e1 = d mod (p-1), may be null
- * @e2: holds e2 = d mod (q-1), may be null
+ * @u: holds the coefficient (optional)
+ * @e1: holds e1 = d mod (p-1) (optional)
+ * @e2: holds e2 = d mod (q-1) (optional)
  *
  * This function will convert the given RSA raw parameters to the
  * native #gnutls_privkey_t format.  The output will be stored in
index a0e72845a9b82123ccbc2f37e8466704b9136971..3006d93ba6e8d2c00462ba468c478239d84ec40e 100644 (file)
@@ -1437,7 +1437,7 @@ wrap_nettle_pk_fixup(gnutls_pk_algorithm_t algo,
                     gnutls_direction_t direction,
                     gnutls_pk_params_st * params)
 {
-       int result;
+       int ret;
 
        if (direction == GNUTLS_IMPORT && algo == GNUTLS_PK_RSA) {
                /* do not trust the generated values. Some old private keys
@@ -1445,6 +1445,14 @@ wrap_nettle_pk_fixup(gnutls_pk_algorithm_t algo,
                 * old but it seemed some of the shipped example private
                 * keys were as old.
                 */
+               if (params->params_nr < RSA_PRIVATE_PARAMS - 3)
+                       return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+
+               if (params->params[RSA_COEF] == NULL) {
+                       ret = _gnutls_mpi_init(&params->params[RSA_COEF]);
+                       if (ret < 0)
+                               return gnutls_assert_val(ret);
+               }
                mpz_invert(TOMPZ(params->params[RSA_COEF]),
                           TOMPZ(params->params[RSA_PRIME2]),
                           TOMPZ(params->params[RSA_PRIME1]));
@@ -1453,11 +1461,10 @@ wrap_nettle_pk_fixup(gnutls_pk_algorithm_t algo,
                zrelease_mpi_key(&params->params[RSA_E1]);
                zrelease_mpi_key(&params->params[RSA_E2]);
 
-               result = calc_rsa_exp(params);
-               if (result < 0) {
-                       gnutls_assert();
-                       return result;
-               }
+               ret = calc_rsa_exp(params);
+               if (ret < 0)
+                       return gnutls_assert_val(ret);
+
                params->params_nr = RSA_PRIVATE_PARAMS;
        }
 
index 49688571d77e739fec3919acf38ebc8a6b2f491b..192eea6fe6b3dd8890fdfe44ac90eaee67c96b80 100644 (file)
@@ -718,9 +718,9 @@ gnutls_x509_privkey_import_rsa_raw(gnutls_x509_privkey_t key,
  * @d: holds the private exponent
  * @p: holds the first prime (p)
  * @q: holds the second prime (q)
- * @u: holds the coefficient
- * @e1: holds e1 = d mod (p-1)
- * @e2: holds e2 = d mod (q-1)
+ * @u: holds the coefficient (optional)
+ * @e1: holds e1 = d mod (p-1) (optional)
+ * @e2: holds e2 = d mod (q-1) (optional)
  *
  * This function will convert the given RSA raw parameters to the
  * native #gnutls_x509_privkey_t format.  The output will be stored in
@@ -790,18 +790,20 @@ gnutls_x509_privkey_import_rsa_raw2(gnutls_x509_privkey_t key,
        }
        key->params.params_nr++;
 
-       siz = u->size;
-       if (_gnutls_mpi_init_scan_nz(&key->params.params[5], u->data, siz)) {
-               gnutls_assert();
-               ret = GNUTLS_E_MPI_SCAN_FAILED;
-               goto cleanup;
+       if (u) {
+               siz = u->size;
+               if (_gnutls_mpi_init_scan_nz(&key->params.params[RSA_COEF], u->data, siz)) {
+                       gnutls_assert();
+                       ret = GNUTLS_E_MPI_SCAN_FAILED;
+                       goto cleanup;
+               }
+               key->params.params_nr++;
        }
-       key->params.params_nr++;
 
        if (e1 && e2) {
                siz = e1->size;
                if (_gnutls_mpi_init_scan_nz
-                   (&key->params.params[6], e1->data, siz)) {
+                   (&key->params.params[RSA_E1], e1->data, siz)) {
                        gnutls_assert();
                        ret = GNUTLS_E_MPI_SCAN_FAILED;
                        goto cleanup;
@@ -810,7 +812,7 @@ gnutls_x509_privkey_import_rsa_raw2(gnutls_x509_privkey_t key,
 
                siz = e2->size;
                if (_gnutls_mpi_init_scan_nz
-                   (&key->params.params[7], e2->data, siz)) {
+                   (&key->params.params[RSA_E2], e2->data, siz)) {
                        gnutls_assert();
                        ret = GNUTLS_E_MPI_SCAN_FAILED;
                        goto cleanup;