* @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
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
* 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(¶ms->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]));
zrelease_mpi_key(¶ms->params[RSA_E1]);
zrelease_mpi_key(¶ms->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;
}
* @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
}
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;
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;