summaryrefslogtreecommitdiff
path: root/lib/x509/spki.c
blob: ea4814a4485184c80915f6883fbd9497c72618f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
 * Copyright (C) 2017 Red Hat, Inc.
 *
 * Authors: Daiki Ueno
 *
 * This file is part of GnuTLS.
 *
 * The GnuTLS is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

#include "gnutls_int.h"
#include "errors.h"
#include <common.h>
#include <x509.h>
#include <x509_int.h>

/**
 * gnutls_x509_spki_init:
 * @spki: A pointer to the type to be initialized
 *
 * This function will initialize a SubjectPublicKeyInfo structure used
 * in PKIX. The structure is used to set additional parameters
 * in the public key information field of a certificate.
 *
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
 *   negative error value.
 *
 * Since: 3.6.0
 *
 **/
int
gnutls_x509_spki_init(gnutls_x509_spki_t *spki)
{
	gnutls_x509_spki_t tmp;

	FAIL_IF_LIB_ERROR;

	tmp =
	    gnutls_calloc(1, sizeof(gnutls_x509_spki_st));

	if (!tmp)
		return GNUTLS_E_MEMORY_ERROR;

	*spki = tmp;

	return 0;		/* success */
}

/**
 * gnutls_x509_spki_deinit:
 * @spki: the SubjectPublicKeyInfo structure
 *
 * This function will deinitialize a SubjectPublicKeyInfo structure.
 *
 * Since: 3.6.0
 *
 **/
void
gnutls_x509_spki_deinit(gnutls_x509_spki_t spki)
{
	gnutls_free(spki);
}

/**
 * gnutls_x509_spki_set_pk_algorithm:
 * @spki: the SubjectPublicKeyInfo structure
 * @pk: the public key algorithm of type #gnutls_pk_algorithm_t
 *
 * This function will set the public key algorithm of a
 * SubjectPublicKeyInfo structure.
 *
 * Since: 3.6.0
 *
 **/
void
gnutls_x509_spki_set_pk_algorithm(gnutls_x509_spki_t spki,
				  gnutls_pk_algorithm_t pk)
{
	spki->pk = pk;
}

/**
 * gnutls_x509_spki_get_pk_algorithm:
 * @spki: the SubjectPublicKeyInfo structure
 *
 * This function will get the public key algorithm of a
 * SubjectPublicKeyInfo structure.
 *
 * Returns: a member of the #gnutls_pk_algorithm_t enumeration on
 * success, or %GNUTLS_PK_UNKNOWN on error.
 *
 * Since: 3.6.0
 *
 **/
int
gnutls_x509_spki_get_pk_algorithm(gnutls_x509_spki_t spki)
{
	return spki->pk;
}

/**
 * gnutls_x509_spki_set_digest_algorithm:
 * @spki: the SubjectPublicKeyInfo structure
 * @dig: a digest algorithm of type #gnutls_digest_algorithm_t
 *
 * This function will set the digest algorithm of a
 * SubjectPublicKeyInfo structure. This is relevant for
 * RSA-PSS signatures which store the digest algorithm
 * in the SubjectPublicKeyInfo.
 *
 * Since: 3.6.0
 *
 **/
void
gnutls_x509_spki_set_digest_algorithm(gnutls_x509_spki_t spki,
				      gnutls_digest_algorithm_t dig)
{
	spki->rsa_pss_dig = dig;
}

/**
 * gnutls_x509_spki_get_digest_algorithm:
 * @spki: the SubjectPublicKeyInfo structure
 *
 * This function will get the digest algorithm of a
 * SubjectPublicKeyInfo structure. This is relevant for
 * RSA-PSS signatures which store the digest algorithm
 * in the SubjectPublicKeyInfo.
 *
 * Returns: a member of the #gnutls_digest_algorithm_t enumeration on
 * success, or a %GNUTLS_DIG_UNKNOWN on error.
 *
 * Since: 3.6.0
 *
 **/
int
gnutls_x509_spki_get_digest_algorithm(gnutls_x509_spki_t spki)
{
	return spki->rsa_pss_dig;
}

/**
 * gnutls_x509_spki_set_salt_size:
 * @spki: the SubjectPublicKeyInfo structure
 * @salt_size: the size of salt string
 *
 * This function will set the salt size parameter of a
 * SubjectPublicKeyInfo structure.
 *
 * The salt is used in the RSA-PSS signature scheme.
 *
 * Since: 3.6.0
 *
 **/
void
gnutls_x509_spki_set_salt_size(gnutls_x509_spki_t spki,
			       unsigned int salt_size)
{
	spki->salt_size = salt_size;
}

/**
 * gnutls_x509_spki_get_salt_size:
 * @spki: the SubjectPublicKeyInfo structure
 *
 * This function will get the salt size parameter of a
 * SubjectPublicKeyInfo structure.
 *
 * The salt is used in the RSA-PSS signature scheme.
 *
 * Returns: salt size as a positive integer, or zero.
 *
 * Since: 3.6.0
 *
 **/
int
gnutls_x509_spki_get_salt_size(gnutls_x509_spki_t spki)
{
	return spki->salt_size;
}