/** * gnutls_privkey_import_dsa_raw: * @key: The structure to store the parsed key * @p: holds the p * @q: holds the q * @g: holds the g * @y: holds the y * @x: holds the x * * This function will convert the given DSA raw parameters to the * native #gnutls_privkey_t format. The output will be stored * in @key. * * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a * negative error value. **/ int gnutls_privkey_import_dsa_raw(gnutls_privkey_t key, const gnutls_datum_t * p, const gnutls_datum_t * q, const gnutls_datum_t * g, const gnutls_datum_t * y, const gnutls_datum_t * x) { int ret; gnutls_x509_privkey_t xkey; ret = gnutls_x509_privkey_init(&xkey); if (ret < 0) return gnutls_assert_val(ret); ret = gnutls_x509_privkey_import_dsa_raw(xkey, p, q, g, y, x); if (ret < 0) { gnutls_assert(); goto error; } ret = gnutls_privkey_import_x509(key, xkey, GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE); if (ret < 0) { gnutls_assert(); goto error; } return 0; error: gnutls_x509_privkey_deinit(xkey); return ret; }
static int dsa_params_to_pem(const legacy_privkey_t *params, dnssec_binary_t *pem) { _cleanup_x509_privkey_ gnutls_x509_privkey_t key = NULL; int result = gnutls_x509_privkey_init(&key); if (result != GNUTLS_E_SUCCESS) { return DNSSEC_ENOMEM; } gnutls_datum_t p = binary_to_datum(¶ms->prime); gnutls_datum_t q = binary_to_datum(¶ms->subprime); gnutls_datum_t g = binary_to_datum(¶ms->base); gnutls_datum_t x = binary_to_datum(¶ms->private_value); gnutls_datum_t y = binary_to_datum(¶ms->public_value); result = gnutls_x509_privkey_import_dsa_raw(key, &p, &q, &g, &y, &x); if (result != DNSSEC_EOK) { return DNSSEC_KEY_IMPORT_ERROR; } return pem_from_x509(key, pem); }