params.params[DH_P] = _gnutls_mpi_copy(dh_params->params[0]);
params.params[DH_G] = _gnutls_mpi_copy(dh_params->params[1]);
- params.params_nr = 3; /* include empty q */
+ params.params_nr = 5;
params.algo = GNUTLS_PK_DH;
priv_key->data = NULL;
gnutls_free(priv_key->data);
cleanup:
gnutls_pk_params_clear(¶ms);
+ gnutls_pk_params_release(¶ms);
return ret;
}
int ret;
gnutls_pk_params_init(&pub);
- gnutls_pk_params_init(&priv);
+ pub.params_nr = 5;
pub.algo = GNUTLS_PK_DH;
+ gnutls_pk_params_init(&priv);
+ priv.params_nr = 5;
+ priv.algo = GNUTLS_PK_DH;
+
if (_gnutls_mpi_init_scan_nz
(&pub.params[DH_Y], peer_key->data,
peer_key->size) != 0) {
goto cleanup;
}
- priv.params_nr = 3; /* include, possibly empty, q */
- priv.algo = GNUTLS_PK_DH;
-
Z->data = NULL;
ret = _gnutls_pk_derive(GNUTLS_PK_DH, Z, &priv, &pub);
ret = 0;
cleanup:
gnutls_pk_params_clear(&pub);
+ gnutls_pk_params_release(&pub);
gnutls_pk_params_clear(&priv);
+ gnutls_pk_params_release(&priv);
return ret;
}
int ret;
gnutls_pk_params_init(¶ms);
+ params.params_nr = 3;
params.curve = curve;
params.algo = GNUTLS_PK_ECDSA;
gnutls_free(k->data);
cleanup:
gnutls_pk_params_clear(¶ms);
+ gnutls_pk_params_release(¶ms);
return ret;
}
int ret;
gnutls_pk_params_init(&pub);
- gnutls_pk_params_init(&priv);
-
+ pub.params_nr = 3;
pub.algo = GNUTLS_PK_ECDSA;
pub.curve = curve;
+ gnutls_pk_params_init(&priv);
+ priv.params_nr = 3;
+ priv.algo = GNUTLS_PK_ECDSA;
+ priv.curve = curve;
+
if (_gnutls_mpi_init_scan_nz
(&pub.params[ECC_Y], peer_y->data,
peer_y->size) != 0) {
goto cleanup;
}
- pub.params_nr = 2;
-
if (_gnutls_mpi_init_scan_nz
(&priv.params[ECC_Y], y->data,
y->size) != 0) {
goto cleanup;
}
-
- priv.params_nr = 3;
- priv.algo = GNUTLS_PK_ECDSA;
- priv.curve = curve;
-
Z->data = NULL;
ret = _gnutls_pk_derive(GNUTLS_PK_ECDSA, Z, &priv, &pub);
ret = 0;
cleanup:
gnutls_pk_params_clear(&pub);
+ gnutls_pk_params_release(&pub);
gnutls_pk_params_clear(&priv);
+ gnutls_pk_params_release(&priv);
return ret;
}
fail("error\n");
}
-static void genkey(gnutls_dh_params_t *dh_params,
+static void genkey(const gnutls_dh_params_t dh_params,
gnutls_datum_t *priv_key, gnutls_datum_t *pub_key)
{
int ret;
- ret = _gnutls_dh_generate_key(*dh_params, priv_key, pub_key);
+ ret = _gnutls_dh_generate_key(dh_params, priv_key, pub_key);
if (ret != 0)
fail("error\n");
}
-static void compute_key(const char *name, gnutls_dh_params_t *dh_params,
- gnutls_datum_t *priv_key, gnutls_datum_t *pub_key,
+static void compute_key(const char *name, const gnutls_dh_params_t dh_params,
+ const gnutls_datum_t *priv_key, const gnutls_datum_t *pub_key,
const gnutls_datum_t *peer_key, int expect_error,
gnutls_datum_t *result, bool expect_success)
{
bool success;
int ret;
- ret = _gnutls_dh_compute_key(*dh_params, priv_key, pub_key,
+ ret = _gnutls_dh_compute_key(dh_params, priv_key, pub_key,
peer_key, &Z);
if (expect_error != ret)
fail("%s: error %d (expected %d)\n", name, ret, expect_error);
params(&dh_params, &test_data[i].prime, &test_data[i].q,
&test_data[i].generator);
- genkey(&dh_params, &priv_key, &pub_key);
+ genkey(dh_params, &priv_key, &pub_key);
- compute_key(test_data[i].name, &dh_params, &priv_key,
+ compute_key(test_data[i].name, dh_params, &priv_key,
&pub_key, &test_data[i].peer_key,
test_data[i].expected_error, NULL, 0);
fail("error\n");
}
-static void compute_key(gnutls_ecc_curve_t curve, gnutls_datum_t *x,
- gnutls_datum_t *y, gnutls_datum_t *key,
+static void compute_key(gnutls_ecc_curve_t curve, const gnutls_datum_t *x,
+ const gnutls_datum_t *y, const gnutls_datum_t *key,
const gnutls_datum_t *peer_x,
const gnutls_datum_t *peer_y,
int expect_error,