Blame lib/x509/spki.c

Packit aea12f
/*
Packit aea12f
 * Copyright (C) 2017 Red Hat, Inc.
Packit aea12f
 *
Packit aea12f
 * Authors: Daiki Ueno
Packit aea12f
 *
Packit aea12f
 * This file is part of GnuTLS.
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
Packit aea12f
#include "gnutls_int.h"
Packit aea12f
#include "errors.h"
Packit aea12f
#include <common.h>
Packit aea12f
#include <x509.h>
Packit aea12f
#include <x509_int.h>
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_x509_spki_init:
Packit aea12f
 * @spki: A pointer to the type to be initialized
Packit aea12f
 *
Packit aea12f
 * This function will initialize a SubjectPublicKeyInfo structure used
Packit aea12f
 * in PKIX. The structure is used to set additional parameters
Packit aea12f
 * in the public key information field of a certificate.
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.0
Packit aea12f
 *
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_x509_spki_init(gnutls_x509_spki_t *spki)
Packit aea12f
{
Packit aea12f
	gnutls_x509_spki_t tmp;
Packit aea12f
Packit aea12f
	FAIL_IF_LIB_ERROR;
Packit aea12f
Packit aea12f
	tmp =
Packit aea12f
	    gnutls_calloc(1, sizeof(gnutls_x509_spki_st));
Packit aea12f
Packit aea12f
	if (!tmp)
Packit aea12f
		return GNUTLS_E_MEMORY_ERROR;
Packit aea12f
Packit aea12f
	*spki = tmp;
Packit aea12f
Packit aea12f
	return 0;		/* success */
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_x509_spki_deinit:
Packit aea12f
 * @spki: the SubjectPublicKeyInfo structure
Packit aea12f
 *
Packit aea12f
 * This function will deinitialize a SubjectPublicKeyInfo structure.
Packit aea12f
 *
Packit aea12f
 * Since: 3.6.0
Packit aea12f
 *
Packit aea12f
 **/
Packit aea12f
void
Packit aea12f
gnutls_x509_spki_deinit(gnutls_x509_spki_t spki)
Packit aea12f
{
Packit aea12f
	gnutls_free(spki);
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_x509_spki_set_rsa_pss_params:
Packit aea12f
 * @spki: the SubjectPublicKeyInfo structure
Packit aea12f
 * @dig: a digest algorithm of type #gnutls_digest_algorithm_t
Packit aea12f
 * @salt_size: the size of salt string
Packit aea12f
 *
Packit aea12f
 * This function will set the public key parameters for
Packit aea12f
 * an RSA-PSS algorithm, in the SubjectPublicKeyInfo structure.
Packit aea12f
 *
Packit aea12f
 * Since: 3.6.0
Packit aea12f
 *
Packit aea12f
 **/
Packit aea12f
void
Packit aea12f
gnutls_x509_spki_set_rsa_pss_params(gnutls_x509_spki_t spki,
Packit aea12f
				    gnutls_digest_algorithm_t dig,
Packit aea12f
				    unsigned int salt_size)
Packit aea12f
{
Packit aea12f
	spki->pk = GNUTLS_PK_RSA_PSS;
Packit aea12f
	spki->rsa_pss_dig = dig;
Packit aea12f
	spki->salt_size = salt_size;
Packit aea12f
}
Packit aea12f
Packit aea12f
/**
Packit aea12f
 * gnutls_x509_spki_get_rsa_pss_params:
Packit aea12f
 * @spki: the SubjectPublicKeyInfo structure
Packit aea12f
 * @dig: if non-NULL, it will hold the digest algorithm
Packit aea12f
 * @salt_size: if non-NULL, it will hold the salt size
Packit aea12f
 *
Packit aea12f
 * This function will get the public key algorithm parameters
Packit aea12f
 * of RSA-PSS type.
Packit aea12f
 *
Packit aea12f
 * Returns: zero if the parameters are present or a negative
Packit aea12f
 *     value on error.
Packit aea12f
 *
Packit aea12f
 * Since: 3.6.0
Packit aea12f
 *
Packit aea12f
 **/
Packit aea12f
int
Packit aea12f
gnutls_x509_spki_get_rsa_pss_params(gnutls_x509_spki_t spki,
Packit aea12f
				    gnutls_digest_algorithm_t *dig,
Packit aea12f
				    unsigned int *salt_size)
Packit aea12f
{
Packit aea12f
	if (spki->pk == 0)
Packit aea12f
		return gnutls_assert_val(GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE);
Packit aea12f
Packit aea12f
	if (spki->pk != GNUTLS_PK_RSA_PSS)
Packit aea12f
		return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
Packit aea12f
Packit aea12f
	if (dig)
Packit aea12f
		*dig = spki->rsa_pss_dig;
Packit aea12f
	if (salt_size)
Packit aea12f
		*salt_size = spki->salt_size;
Packit aea12f
Packit aea12f
	return 0;
Packit aea12f
}