Blame lib/privkey_raw.c

Packit aea12f
/*
Packit aea12f
 * Copyright (C) 2010-2014 Free Software Foundation, Inc.
Packit aea12f
 * 
Packit aea12f
 * Author: Nikos Mavrogiannopoulos
Packit aea12f
 *
Packit aea12f
 * The GnuTLS is free software; you can redistribute it and/or
Packit aea12f
 * modify it under the terms of the GNU Lesser General Public License
Packit aea12f
 * as published by the Free Software Foundation; either version 2.1 of
Packit aea12f
 * the License, or (at your option) any later version.
Packit aea12f
 *
Packit aea12f
 * This library is distributed in the hope that it will be useful, but
Packit aea12f
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit aea12f
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit aea12f
 * Lesser General Public License for more details.
Packit aea12f
 *
Packit aea12f
 * You should have received a copy of the GNU Lesser General Public License
Packit aea12f
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
Packit aea12f
 */
Packit aea12f
Packit aea12f
#include "gnutls_int.h"
Packit aea12f
#include <gnutls/pkcs11.h>
Packit aea12f
#include <stdio.h>
Packit aea12f
#include <string.h>
Packit aea12f
#include "errors.h"
Packit aea12f
#include <datum.h>
Packit aea12f
#include <pkcs11_int.h>
Packit aea12f
#include <gnutls/abstract.h>
Packit aea12f
#include <pk.h>
Packit aea12f
#include <x509_int.h>
Packit aea12f
#include <tls-sig.h>
Packit aea12f
#include <algorithms.h>
Packit aea12f
#include <fips.h>
Packit aea12f
#include <abstract_int.h>
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_privkey_export_rsa_raw:
Packit aea12f
 * @key: Holds the certificate
Packit aea12f
 * @m: will hold the modulus
Packit aea12f
 * @e: will hold the public exponent
Packit aea12f
 * @d: will hold the private exponent
Packit aea12f
 * @p: will hold the first prime (p)
Packit aea12f
 * @q: will hold the second prime (q)
Packit aea12f
 * @u: will hold the coefficient
Packit aea12f
 * @e1: will hold e1 = d mod (p-1)
Packit aea12f
 * @e2: will hold e2 = d mod (q-1)
Packit aea12f
 *
Packit aea12f
 * This function will export the RSA private key's parameters found
Packit aea12f
 * in the given structure. The new parameters will be allocated using
Packit aea12f
 * gnutls_malloc() and will be stored in the appropriate datum. For
Packit aea12f
 * EdDSA keys, the @y value should be %NULL.
Packit aea12f
 *
Packit aea12f
 * Returns: %GNUTLS_E_SUCCESS on success, otherwise a negative error code.
Packit aea12f
 *
Packit aea12f
 * Since: 3.3.0
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_privkey_export_rsa_raw(gnutls_privkey_t key,
Packit aea12f
				    gnutls_datum_t * m, gnutls_datum_t * e,
Packit aea12f
				    gnutls_datum_t * d, gnutls_datum_t * p,
Packit aea12f
				    gnutls_datum_t * q, gnutls_datum_t * u,
Packit aea12f
				    gnutls_datum_t * e1,
Packit aea12f
				    gnutls_datum_t * e2)
Packit aea12f
{
Packit aea12f
	return gnutls_privkey_export_rsa_raw2(key, m, e, d, p, q, u, e1, e2, 0);
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_privkey_export_rsa_raw2:
Packit aea12f
 * @key: Holds the certificate
Packit aea12f
 * @m: will hold the modulus
Packit aea12f
 * @e: will hold the public exponent
Packit aea12f
 * @d: will hold the private exponent
Packit aea12f
 * @p: will hold the first prime (p)
Packit aea12f
 * @q: will hold the second prime (q)
Packit aea12f
 * @u: will hold the coefficient
Packit aea12f
 * @e1: will hold e1 = d mod (p-1)
Packit aea12f
 * @e2: will hold e2 = d mod (q-1)
Packit aea12f
 * @flags: flags from %gnutls_abstract_export_flags_t
Packit aea12f
 *
Packit aea12f
 * This function will export the RSA private key's parameters found
Packit aea12f
 * in the given structure. The new parameters will be allocated using
Packit aea12f
 * gnutls_malloc() and will be stored in the appropriate datum.
Packit aea12f
 *
Packit aea12f
 * Returns: %GNUTLS_E_SUCCESS on success, otherwise a negative error code.
Packit aea12f
 *
Packit aea12f
 * Since: 3.6.0
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_privkey_export_rsa_raw2(gnutls_privkey_t key,
Packit aea12f
				    gnutls_datum_t * m, gnutls_datum_t * e,
Packit aea12f
				    gnutls_datum_t * d, gnutls_datum_t * p,
Packit aea12f
				    gnutls_datum_t * q, gnutls_datum_t * u,
Packit aea12f
				    gnutls_datum_t * e1,
Packit aea12f
				    gnutls_datum_t * e2,
Packit aea12f
				    unsigned int flags)
Packit aea12f
{
Packit aea12f
gnutls_pk_params_st params;
Packit aea12f
int ret;
Packit aea12f
Packit aea12f
	if (key == NULL) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		return GNUTLS_E_INVALID_REQUEST;
Packit aea12f
	}
Packit aea12f
	
Packit aea12f
	gnutls_pk_params_init(&params);
Packit aea12f
Packit aea12f
	ret = _gnutls_privkey_get_mpis(key, &params);
Packit aea12f
	if (ret < 0)
Packit aea12f
		return gnutls_assert_val(ret);
Packit aea12f
Packit aea12f
	ret = _gnutls_params_get_rsa_raw(&params, m, e, d, p, q, u, e1, e2, flags);
Packit aea12f
Packit aea12f
	gnutls_pk_params_release(&params);
Packit aea12f
Packit aea12f
	return ret;
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_privkey_export_dsa_raw:
Packit aea12f
 * @key: Holds the public key
Packit aea12f
 * @p: will hold the p
Packit aea12f
 * @q: will hold the q
Packit aea12f
 * @g: will hold the g
Packit aea12f
 * @y: will hold the y
Packit aea12f
 * @x: will hold the x
Packit aea12f
 *
Packit aea12f
 * This function will export the DSA private key's parameters found
Packit aea12f
 * in the given structure. The new parameters will be allocated using
Packit aea12f
 * gnutls_malloc() and will be stored in the appropriate datum.
Packit aea12f
 *
Packit aea12f
 * Returns: %GNUTLS_E_SUCCESS on success, otherwise a negative error code.
Packit aea12f
 *
Packit aea12f
 * Since: 3.3.0
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_privkey_export_dsa_raw(gnutls_privkey_t key,
Packit aea12f
			     gnutls_datum_t * p, gnutls_datum_t * q,
Packit aea12f
			     gnutls_datum_t * g, gnutls_datum_t * y,
Packit aea12f
			     gnutls_datum_t * x)
Packit aea12f
{
Packit aea12f
	return gnutls_privkey_export_dsa_raw2(key, p, q, g, y, x, 0);
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_privkey_export_dsa_raw2:
Packit aea12f
 * @key: Holds the public key
Packit aea12f
 * @p: will hold the p
Packit aea12f
 * @q: will hold the q
Packit aea12f
 * @g: will hold the g
Packit aea12f
 * @y: will hold the y
Packit aea12f
 * @x: will hold the x
Packit aea12f
 * @flags: flags from %gnutls_abstract_export_flags_t
Packit aea12f
 *
Packit aea12f
 * This function will export the DSA private key's parameters found
Packit aea12f
 * in the given structure. The new parameters will be allocated using
Packit aea12f
 * gnutls_malloc() and will be stored in the appropriate datum.
Packit aea12f
 *
Packit aea12f
 * Returns: %GNUTLS_E_SUCCESS on success, otherwise a negative error code.
Packit aea12f
 *
Packit aea12f
 * Since: 3.6.0
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_privkey_export_dsa_raw2(gnutls_privkey_t key,
Packit aea12f
			     gnutls_datum_t * p, gnutls_datum_t * q,
Packit aea12f
			     gnutls_datum_t * g, gnutls_datum_t * y,
Packit aea12f
			     gnutls_datum_t * x, unsigned int flags)
Packit aea12f
{
Packit aea12f
gnutls_pk_params_st params;
Packit aea12f
int ret;
Packit aea12f
Packit aea12f
	if (key == NULL) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		return GNUTLS_E_INVALID_REQUEST;
Packit aea12f
	}
Packit aea12f
	
Packit aea12f
	gnutls_pk_params_init(&params);
Packit aea12f
Packit aea12f
	ret = _gnutls_privkey_get_mpis(key, &params);
Packit aea12f
	if (ret < 0)
Packit aea12f
		return gnutls_assert_val(ret);
Packit aea12f
Packit aea12f
	ret = _gnutls_params_get_dsa_raw(&params, p, q, g, y, x, flags);
Packit aea12f
Packit aea12f
	gnutls_pk_params_release(&params);
Packit aea12f
Packit aea12f
	return ret;
Packit aea12f
}
Packit aea12f
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_privkey_export_ecc_raw:
Packit aea12f
 * @key: Holds the public key
Packit aea12f
 * @curve: will hold the curve
Packit aea12f
 * @x: will hold the x-coordinate
Packit aea12f
 * @y: will hold the y-coordinate
Packit aea12f
 * @k: will hold the private key
Packit aea12f
 *
Packit aea12f
 * This function will export the ECC private key's parameters found
Packit aea12f
 * in the given structure. The new parameters will be allocated using
Packit aea12f
 * gnutls_malloc() and will be stored in the appropriate datum.
Packit aea12f
 *
Packit aea12f
 * In EdDSA curves the @y parameter will be %NULL and the other parameters
Packit aea12f
 * will be in the native format for the curve.
Packit aea12f
 *
Packit aea12f
 * Returns: %GNUTLS_E_SUCCESS on success, otherwise a negative error code.
Packit aea12f
 *
Packit aea12f
 * Since: 3.3.0
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_privkey_export_ecc_raw(gnutls_privkey_t key,
Packit aea12f
				       gnutls_ecc_curve_t * curve,
Packit aea12f
				       gnutls_datum_t * x,
Packit aea12f
				       gnutls_datum_t * y,
Packit aea12f
				       gnutls_datum_t * k)
Packit aea12f
{
Packit aea12f
	return gnutls_privkey_export_ecc_raw2(key, curve, x, y, k, 0);
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_privkey_export_ecc_raw2:
Packit aea12f
 * @key: Holds the public key
Packit aea12f
 * @curve: will hold the curve
Packit aea12f
 * @x: will hold the x-coordinate
Packit aea12f
 * @y: will hold the y-coordinate
Packit aea12f
 * @k: will hold the private key
Packit aea12f
 * @flags: flags from %gnutls_abstract_export_flags_t
Packit aea12f
 *
Packit aea12f
 * This function will export the ECC private key's parameters found
Packit aea12f
 * in the given structure. The new parameters will be allocated using
Packit aea12f
 * gnutls_malloc() and will be stored in the appropriate datum.
Packit aea12f
 *
Packit aea12f
 * In EdDSA curves the @y parameter will be %NULL and the other parameters
Packit aea12f
 * will be in the native format for the curve.
Packit aea12f
 *
Packit aea12f
 * Returns: %GNUTLS_E_SUCCESS on success, otherwise a negative error code.
Packit aea12f
 *
Packit aea12f
 * Since: 3.6.0
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_privkey_export_ecc_raw2(gnutls_privkey_t key,
Packit aea12f
				       gnutls_ecc_curve_t * curve,
Packit aea12f
				       gnutls_datum_t * x,
Packit aea12f
				       gnutls_datum_t * y,
Packit aea12f
				       gnutls_datum_t * k,
Packit aea12f
				       unsigned int flags)
Packit aea12f
{
Packit aea12f
gnutls_pk_params_st params;
Packit aea12f
int ret;
Packit aea12f
Packit aea12f
	if (key == NULL) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		return GNUTLS_E_INVALID_REQUEST;
Packit aea12f
	}
Packit aea12f
	
Packit aea12f
	gnutls_pk_params_init(&params);
Packit aea12f
Packit aea12f
	ret = _gnutls_privkey_get_mpis(key, &params);
Packit aea12f
	if (ret < 0)
Packit aea12f
		return gnutls_assert_val(ret);
Packit aea12f
Packit aea12f
	ret = _gnutls_params_get_ecc_raw(&params, curve, x, y, k, flags);
Packit aea12f
Packit aea12f
	gnutls_pk_params_release(&params);
Packit aea12f
Packit aea12f
	return ret;
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_privkey_export_gost_raw2:
Packit aea12f
 * @key: Holds the public key
Packit aea12f
 * @curve: will hold the curve
Packit aea12f
 * @digest: will hold the digest
Packit aea12f
 * @paramset: will hold the GOST parameter set ID
Packit aea12f
 * @x: will hold the x-coordinate
Packit aea12f
 * @y: will hold the y-coordinate
Packit aea12f
 * @k: will hold the private key
Packit aea12f
 * @flags: flags from %gnutls_abstract_export_flags_t
Packit aea12f
 *
Packit aea12f
 * This function will export the GOST private key's parameters found
Packit aea12f
 * in the given structure. The new parameters will be allocated using
Packit aea12f
 * gnutls_malloc() and will be stored in the appropriate datum.
Packit aea12f
 *
Packit aea12f
 * Note: parameters will be stored with least significant byte first. On
Packit aea12f
 * version 3.6.3 this was incorrectly returned in big-endian format.
Packit aea12f
 *
Packit aea12f
 * Returns: %GNUTLS_E_SUCCESS on success, otherwise a negative error code.
Packit aea12f
 *
Packit aea12f
 * Since: 3.6.3
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_privkey_export_gost_raw2(gnutls_privkey_t key,
Packit aea12f
				       gnutls_ecc_curve_t * curve,
Packit aea12f
				       gnutls_digest_algorithm_t * digest,
Packit aea12f
				       gnutls_gost_paramset_t * paramset,
Packit aea12f
				       gnutls_datum_t * x,
Packit aea12f
				       gnutls_datum_t * y,
Packit aea12f
				       gnutls_datum_t * k,
Packit aea12f
				       unsigned int flags)
Packit aea12f
{
Packit aea12f
	gnutls_pk_params_st params;
Packit aea12f
	int ret;
Packit aea12f
Packit aea12f
	if (key == NULL) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		return GNUTLS_E_INVALID_REQUEST;
Packit aea12f
	}
Packit aea12f
Packit aea12f
	gnutls_pk_params_init(&params);
Packit aea12f
Packit aea12f
	ret = _gnutls_privkey_get_mpis(key, &params);
Packit aea12f
	if (ret < 0)
Packit aea12f
		return gnutls_assert_val(ret);
Packit aea12f
Packit aea12f
	ret = _gnutls_params_get_gost_raw(&params, curve, digest, paramset,
Packit aea12f
					  x, y, k, flags);
Packit aea12f
Packit aea12f
	gnutls_pk_params_release(&params);
Packit aea12f
Packit aea12f
	return ret;
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_privkey_import_rsa_raw:
Packit aea12f
 * @key: The structure to store the parsed key
Packit aea12f
 * @m: holds the modulus
Packit aea12f
 * @e: holds the public exponent
Packit aea12f
 * @d: holds the private exponent
Packit aea12f
 * @p: holds the first prime (p)
Packit aea12f
 * @q: holds the second prime (q)
Packit aea12f
 * @u: holds the coefficient (optional)
Packit aea12f
 * @e1: holds e1 = d mod (p-1) (optional)
Packit aea12f
 * @e2: holds e2 = d mod (q-1) (optional)
Packit aea12f
 *
Packit aea12f
 * This function will convert the given RSA raw parameters to the
Packit aea12f
 * native #gnutls_privkey_t format.  The output will be stored in
Packit aea12f
 * @key.
Packit aea12f
 *
Packit aea12f
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
Packit aea12f
 *   negative error value.
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_privkey_import_rsa_raw(gnutls_privkey_t key,
Packit aea12f
				    const gnutls_datum_t * m,
Packit aea12f
				    const gnutls_datum_t * e,
Packit aea12f
				    const gnutls_datum_t * d,
Packit aea12f
				    const gnutls_datum_t * p,
Packit aea12f
				    const gnutls_datum_t * q,
Packit aea12f
				    const gnutls_datum_t * u,
Packit aea12f
				    const gnutls_datum_t * e1,
Packit aea12f
				    const gnutls_datum_t * e2)
Packit aea12f
{
Packit aea12f
int ret;
Packit aea12f
gnutls_x509_privkey_t xkey;
Packit aea12f
Packit aea12f
	ret = gnutls_x509_privkey_init(&xkey);
Packit aea12f
	if (ret < 0)
Packit aea12f
		return gnutls_assert_val(ret);
Packit aea12f
Packit aea12f
	ret = gnutls_x509_privkey_import_rsa_raw2(xkey, m, e, d, p, q, u, e1, e1);
Packit aea12f
	if (ret < 0) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		goto error;
Packit aea12f
	}
Packit aea12f
	
Packit aea12f
	ret = gnutls_privkey_import_x509(key, xkey, GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE);
Packit aea12f
	if (ret < 0) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		goto error;
Packit aea12f
	}
Packit aea12f
	
Packit aea12f
	return 0;
Packit aea12f
Packit aea12f
error:
Packit aea12f
	gnutls_x509_privkey_deinit(xkey);
Packit aea12f
	return ret;
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_privkey_import_dsa_raw:
Packit aea12f
 * @key: The structure to store the parsed key
Packit aea12f
 * @p: holds the p
Packit aea12f
 * @q: holds the q
Packit aea12f
 * @g: holds the g
Packit aea12f
 * @y: holds the y
Packit aea12f
 * @x: holds the x
Packit aea12f
 *
Packit aea12f
 * This function will convert the given DSA raw parameters to the
Packit aea12f
 * native #gnutls_privkey_t format.  The output will be stored
Packit aea12f
 * in @key.
Packit aea12f
 *
Packit aea12f
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
Packit aea12f
 *   negative error value.
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_privkey_import_dsa_raw(gnutls_privkey_t key,
Packit aea12f
				   const gnutls_datum_t * p,
Packit aea12f
				   const gnutls_datum_t * q,
Packit aea12f
				   const gnutls_datum_t * g,
Packit aea12f
				   const gnutls_datum_t * y,
Packit aea12f
				   const gnutls_datum_t * x)
Packit aea12f
{
Packit aea12f
int ret;
Packit aea12f
gnutls_x509_privkey_t xkey;
Packit aea12f
Packit aea12f
	ret = gnutls_x509_privkey_init(&xkey);
Packit aea12f
	if (ret < 0)
Packit aea12f
		return gnutls_assert_val(ret);
Packit aea12f
Packit aea12f
	ret = gnutls_x509_privkey_import_dsa_raw(xkey, p, q, g, y, x);
Packit aea12f
	if (ret < 0) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		goto error;
Packit aea12f
	}
Packit aea12f
	
Packit aea12f
	ret = gnutls_privkey_import_x509(key, xkey, GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE);
Packit aea12f
	if (ret < 0) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		goto error;
Packit aea12f
	}
Packit aea12f
	
Packit aea12f
	return 0;
Packit aea12f
Packit aea12f
error:
Packit aea12f
	gnutls_x509_privkey_deinit(xkey);
Packit aea12f
	return ret;
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_privkey_import_ecc_raw:
Packit aea12f
 * @key: The key
Packit aea12f
 * @curve: holds the curve
Packit aea12f
 * @x: holds the x-coordinate
Packit aea12f
 * @y: holds the y-coordinate
Packit aea12f
 * @k: holds the k (private key)
Packit aea12f
 *
Packit aea12f
 * This function will convert the given elliptic curve parameters to the
Packit aea12f
 * native #gnutls_privkey_t format.  The output will be stored
Packit aea12f
 * in @key.
Packit aea12f
 *
Packit aea12f
 * In EdDSA curves the @y parameter should be %NULL and the @x and @k parameters
Packit aea12f
 * must be in the native format for the curve.
Packit aea12f
 *
Packit aea12f
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
Packit aea12f
 *   negative error value.
Packit aea12f
 *
Packit aea12f
 * Since: 3.0
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_privkey_import_ecc_raw(gnutls_privkey_t key,
Packit aea12f
			      gnutls_ecc_curve_t curve,
Packit aea12f
			      const gnutls_datum_t * x,
Packit aea12f
			      const gnutls_datum_t * y,
Packit aea12f
			      const gnutls_datum_t * k)
Packit aea12f
{
Packit aea12f
int ret;
Packit aea12f
gnutls_x509_privkey_t xkey;
Packit aea12f
Packit aea12f
	ret = gnutls_x509_privkey_init(&xkey);
Packit aea12f
	if (ret < 0)
Packit aea12f
		return gnutls_assert_val(ret);
Packit aea12f
Packit aea12f
	ret = gnutls_x509_privkey_import_ecc_raw(xkey, curve, x, y, k);
Packit aea12f
	if (ret < 0) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		goto error;
Packit aea12f
	}
Packit aea12f
	
Packit aea12f
	ret = gnutls_privkey_import_x509(key, xkey, GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE);
Packit aea12f
	if (ret < 0) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		goto error;
Packit aea12f
	}
Packit aea12f
	
Packit aea12f
	return 0;
Packit aea12f
Packit aea12f
error:
Packit aea12f
	gnutls_x509_privkey_deinit(xkey);
Packit aea12f
	return ret;
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_privkey_import_gost_raw:
Packit aea12f
 * @key: The key
Packit aea12f
 * @curve: holds the curve
Packit aea12f
 * @digest: holds the digest
Packit aea12f
 * @paramset: holds the GOST parameter set ID
Packit aea12f
 * @x: holds the x-coordinate
Packit aea12f
 * @y: holds the y-coordinate
Packit aea12f
 * @k: holds the k (private key)
Packit aea12f
 *
Packit aea12f
 * This function will convert the given GOST private key's parameters to the
Packit aea12f
 * native #gnutls_privkey_t format.  The output will be stored
Packit aea12f
 * in @key.  @digest should be one of GNUTLS_DIG_GOSR_94,
Packit aea12f
 * GNUTLS_DIG_STREEBOG_256 or GNUTLS_DIG_STREEBOG_512.  If @paramset is set to
Packit aea12f
 * GNUTLS_GOST_PARAMSET_UNKNOWN default one will be selected depending on
Packit aea12f
 * @digest.
Packit aea12f
 *
Packit aea12f
 * Note: parameters should be stored with least significant byte first. On
Packit aea12f
 * version 3.6.3 big-endian format was used incorrectly.
Packit aea12f
 *
Packit aea12f
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
Packit aea12f
 *   negative error value.
Packit aea12f
 *
Packit aea12f
 * Since: 3.6.3
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_privkey_import_gost_raw(gnutls_privkey_t key,
Packit aea12f
				   gnutls_ecc_curve_t curve,
Packit aea12f
				   gnutls_digest_algorithm_t digest,
Packit aea12f
				   gnutls_gost_paramset_t paramset,
Packit aea12f
				   const gnutls_datum_t * x,
Packit aea12f
				   const gnutls_datum_t * y,
Packit aea12f
				   const gnutls_datum_t * k)
Packit aea12f
{
Packit aea12f
	int ret;
Packit aea12f
	gnutls_x509_privkey_t xkey;
Packit aea12f
Packit aea12f
	ret = gnutls_x509_privkey_init(&xkey);
Packit aea12f
	if (ret < 0)
Packit aea12f
		return gnutls_assert_val(ret);
Packit aea12f
Packit aea12f
	ret = gnutls_x509_privkey_import_gost_raw(xkey, curve, digest, paramset, x, y, k);
Packit aea12f
	if (ret < 0) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		goto error;
Packit aea12f
	}
Packit aea12f
Packit aea12f
	ret = gnutls_privkey_import_x509(key, xkey, GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE);
Packit aea12f
	if (ret < 0) {
Packit aea12f
		gnutls_assert();
Packit aea12f
		goto error;
Packit aea12f
	}
Packit aea12f
Packit aea12f
	return 0;
Packit aea12f
Packit aea12f
error:
Packit aea12f
	gnutls_x509_privkey_deinit(xkey);
Packit aea12f
	return ret;
Packit aea12f
}