return 0;
}
+static int calc_dsa_pub(gnutls_pk_params_st * params)
+{
+ int ret;
+
+ params->params[DSA_Y] = NULL;
+
+ ret = _gnutls_mpi_init(¶ms->params[DSA_Y]);
+ if (ret < 0)
+ return gnutls_assert_val(ret);
+
+ /* y = g^x mod p */
+ ret = _gnutls_mpi_powm(params->params[DSA_Y], params->params[DSA_G],
+ params->params[DSA_X], params->params[DSA_P]);
+ if (ret < 0) {
+ zrelease_mpi_key(¶ms->params[DSA_Y]);
+ return gnutls_assert_val(ret);
+ }
+
+ return 0;
+}
+
static int
wrap_nettle_pk_fixup(gnutls_pk_algorithm_t algo,
gnutls_direction_t direction,
params->spki.salt_size, pub_size,
GNUTLS_E_PK_INVALID_PUBKEY_PARAMS);
}
-
+ } else if (algo == GNUTLS_PK_DSA) {
+ if (params->params[DSA_Y] == NULL) {
+ ret = calc_dsa_pub(params);
+ if (ret < 0)
+ return gnutls_assert_val(ret);
+ params->params_nr++;
+ }
}
#if ENABLE_GOST
else if (algo == GNUTLS_PK_GOST_01 ||
* @p: holds the p
* @q: holds the q
* @g: holds the g
- * @y: holds the y
+ * @y: holds the y (optional)
* @x: holds the x
*
* This function will convert the given DSA raw parameters to the
* @p: holds the p
* @q: holds the q
* @g: holds the g
- * @y: holds the y
+ * @y: holds the y (optional)
* @x: holds the x
*
* This function will convert the given DSA raw parameters to the
goto cleanup;
}
- siz = y->size;
- if (_gnutls_mpi_init_scan_nz(&key->params.params[3], y->data, siz)) {
- gnutls_assert();
- ret = GNUTLS_E_MPI_SCAN_FAILED;
- goto cleanup;
+ if (y) {
+ siz = y->size;
+ if (_gnutls_mpi_init_scan_nz(&key->params.params[3], y->data, siz)) {
+ gnutls_assert();
+ ret = GNUTLS_E_MPI_SCAN_FAILED;
+ goto cleanup;
+ }
}
siz = x->size;
gnutls_free(x.data);
gnutls_privkey_deinit(key);
+ /* Optional y argument */
+ ret = gnutls_privkey_init(&key);
+ if (ret < 0)
+ fail("error\n");
+
+ ret = gnutls_privkey_import_dsa_raw(key, &_dsa_p, &_dsa_q, &_dsa_g, NULL, &_dsa_x);
+ if (ret < 0)
+ fail("error\n");
+
+ ret = gnutls_privkey_export_dsa_raw2(key, &p, &q, &g, &y, &x, 0);
+ if (ret < 0)
+ fail("error: %s\n", gnutls_strerror(ret));
+
+ CMP("p", &p, dsa_p);
+ CMP("q", &q, dsa_q);
+ CMP("g", &g, dsa_g);
+ CMP("y", &y, dsa_y);
+ CMP("x", &x, dsa_x);
+ gnutls_free(p.data);
+ gnutls_free(q.data);
+ gnutls_free(g.data);
+ gnutls_free(y.data);
+ gnutls_free(x.data);
+ gnutls_privkey_deinit(key);
+
/* RSA */
/* Optional arguments */