]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man3/EVP_PKEY_ASN1_METHOD.pod
Update copyright year
[thirdparty/openssl.git] / doc / man3 / EVP_PKEY_ASN1_METHOD.pod
CommitLineData
751148e2
RL
1=pod
2
3=head1 NAME
4
5EVP_PKEY_ASN1_METHOD,
287f5551
RL
6EVP_PKEY_asn1_new,
7EVP_PKEY_asn1_copy,
8EVP_PKEY_asn1_free,
9EVP_PKEY_asn1_add0,
10EVP_PKEY_asn1_add_alias,
11EVP_PKEY_asn1_set_public,
12EVP_PKEY_asn1_set_private,
13EVP_PKEY_asn1_set_param,
14EVP_PKEY_asn1_set_free,
15EVP_PKEY_asn1_set_ctrl,
16EVP_PKEY_asn1_set_item,
17EVP_PKEY_asn1_set_siginf,
18EVP_PKEY_asn1_set_check,
b0004708
PY
19EVP_PKEY_asn1_set_public_check,
20EVP_PKEY_asn1_set_param_check,
287f5551 21EVP_PKEY_asn1_set_security_bits,
e8f9f08f
MC
22EVP_PKEY_asn1_set_set_priv_key,
23EVP_PKEY_asn1_set_set_pub_key,
287f5551 24EVP_PKEY_get0_asn1
751148e2
RL
25- manipulating and registering EVP_PKEY_ASN1_METHOD structure
26
27=head1 SYNOPSIS
28
29 #include <openssl/evp.h>
30
31 typedef struct evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD;
32
33 EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
34 const char *pem_str,
35 const char *info);
36 void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst,
37 const EVP_PKEY_ASN1_METHOD *src);
38 void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth);
39 int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth);
40 int EVP_PKEY_asn1_add_alias(int to, int from);
41
42 void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
43 int (*pub_decode) (EVP_PKEY *pk,
44 X509_PUBKEY *pub),
45 int (*pub_encode) (X509_PUBKEY *pub,
46 const EVP_PKEY *pk),
47 int (*pub_cmp) (const EVP_PKEY *a,
48 const EVP_PKEY *b),
49 int (*pub_print) (BIO *out,
50 const EVP_PKEY *pkey,
51 int indent, ASN1_PCTX *pctx),
52 int (*pkey_size) (const EVP_PKEY *pk),
53 int (*pkey_bits) (const EVP_PKEY *pk));
54 void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
55 int (*priv_decode) (EVP_PKEY *pk,
56 const PKCS8_PRIV_KEY_INFO
57 *p8inf),
58 int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8,
59 const EVP_PKEY *pk),
60 int (*priv_print) (BIO *out,
61 const EVP_PKEY *pkey,
62 int indent,
63 ASN1_PCTX *pctx));
64 void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
65 int (*param_decode) (EVP_PKEY *pkey,
66 const unsigned char **pder,
67 int derlen),
68 int (*param_encode) (const EVP_PKEY *pkey,
69 unsigned char **pder),
70 int (*param_missing) (const EVP_PKEY *pk),
71 int (*param_copy) (EVP_PKEY *to,
72 const EVP_PKEY *from),
73 int (*param_cmp) (const EVP_PKEY *a,
74 const EVP_PKEY *b),
75 int (*param_print) (BIO *out,
76 const EVP_PKEY *pkey,
77 int indent,
78 ASN1_PCTX *pctx));
79
80 void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth,
81 void (*pkey_free) (EVP_PKEY *pkey));
82 void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
83 int (*pkey_ctrl) (EVP_PKEY *pkey, int op,
84 long arg1, void *arg2));
85 void EVP_PKEY_asn1_set_item(EVP_PKEY_ASN1_METHOD *ameth,
86 int (*item_verify) (EVP_MD_CTX *ctx,
87 const ASN1_ITEM *it,
88 void *asn,
89 X509_ALGOR *a,
90 ASN1_BIT_STRING *sig,
91 EVP_PKEY *pkey),
92 int (*item_sign) (EVP_MD_CTX *ctx,
93 const ASN1_ITEM *it,
94 void *asn,
95 X509_ALGOR *alg1,
96 X509_ALGOR *alg2,
97 ASN1_BIT_STRING *sig));
98
99 void EVP_PKEY_asn1_set_siginf(EVP_PKEY_ASN1_METHOD *ameth,
100 int (*siginf_set) (X509_SIG_INFO *siginf,
101 const X509_ALGOR *alg,
102 const ASN1_STRING *sig));
103
104 void EVP_PKEY_asn1_set_check(EVP_PKEY_ASN1_METHOD *ameth,
105 int (*pkey_check) (const EVP_PKEY *pk));
106
b0004708
PY
107 void EVP_PKEY_asn1_set_public_check(EVP_PKEY_ASN1_METHOD *ameth,
108 int (*pkey_pub_check) (const EVP_PKEY *pk));
109
110 void EVP_PKEY_asn1_set_param_check(EVP_PKEY_ASN1_METHOD *ameth,
111 int (*pkey_param_check) (const EVP_PKEY *pk));
112
751148e2
RL
113 void EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth,
114 int (*pkey_security_bits) (const EVP_PKEY
115 *pk));
116
e8f9f08f
MC
117 void EVP_PKEY_asn1_set_set_priv_key(EVP_PKEY_ASN1_METHOD *ameth,
118 int (*set_priv_key) (EVP_PKEY *pk,
119 const unsigned char
120 *priv,
121 size_t len));
122
123 void EVP_PKEY_asn1_set_set_pub_key(EVP_PKEY_ASN1_METHOD *ameth,
124 int (*set_pub_key) (EVP_PKEY *pk,
125 const unsigned char *pub,
126 size_t len));
127
751148e2
RL
128 const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(const EVP_PKEY *pkey);
129
130=head1 DESCRIPTION
131
132B<EVP_PKEY_ASN1_METHOD> is a structure which holds a set of ASN.1
133conversion, printing and information methods for a specific public key
134algorithm.
135
136There are two places where the B<EVP_PKEY_ASN1_METHOD> objects are
137stored: one is a built-in array representing the standard methods for
138different algorithms, and the other one is a stack of user-defined
139application-specific methods, which can be manipulated by using
140L<EVP_PKEY_asn1_add0(3)>.
141
142=head2 Methods
143
144The methods are the underlying implementations of a particular public
145key algorithm present by the B<EVP_PKEY> object.
146
147 int (*pub_decode) (EVP_PKEY *pk, X509_PUBKEY *pub);
148 int (*pub_encode) (X509_PUBKEY *pub, const EVP_PKEY *pk);
149 int (*pub_cmp) (const EVP_PKEY *a, const EVP_PKEY *b);
150 int (*pub_print) (BIO *out, const EVP_PKEY *pkey, int indent,
151 ASN1_PCTX *pctx);
152
153The pub_decode() and pub_encode() methods are called to decode /
154encode B<X509_PUBKEY> ASN.1 parameters to / from B<pk>.
155They MUST return 0 on error, 1 on success.
156They're called by L<X509_PUBKEY_get0(3)> and L<X509_PUBKEY_set(3)>.
157
158The pub_cmp() method is called when two public keys are to be
159compared.
160It MUST return 1 when the keys are equal, 0 otherwise.
161It's called by L<EVP_PKEY_cmp(3)>.
162
163The pub_print() method is called to print a public key in humanly
164readable text to B<out>, indented B<indent> spaces.
165It MUST return 0 on error, 1 on success.
166It's called by L<EVP_PKEY_print_public(3)>.
167
168 int (*priv_decode) (EVP_PKEY *pk, const PKCS8_PRIV_KEY_INFO *p8inf);
169 int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk);
170 int (*priv_print) (BIO *out, const EVP_PKEY *pkey, int indent,
171 ASN1_PCTX *pctx);
172
173The priv_decode() and priv_encode() methods are called to decode /
174encode B<PKCS8_PRIV_KEY_INFO> form private key to / from B<pk>.
175They MUST return 0 on error, 1 on success.
176They're called by L<EVP_PKCS82PKEY(3)> and L<EVP_PKEY2PKCS8(3)>.
177
178The priv_print() method is called to print a private key in humanly
179readable text to B<out>, indented B<indent> spaces.
180It MUST return 0 on error, 1 on success.
181It's called by L<EVP_PKEY_print_private(3)>.
182
183 int (*pkey_size) (const EVP_PKEY *pk);
184 int (*pkey_bits) (const EVP_PKEY *pk);
185 int (*pkey_security_bits) (const EVP_PKEY *pk);
186
187The pkey_size() method returns the key size in bytes.
188It's called by L<EVP_PKEY_size(3)>.
189
190The pkey_bits() method returns the key size in bits.
191It's called by L<EVP_PKEY_bits(3)>.
192
193 int (*param_decode) (EVP_PKEY *pkey,
194 const unsigned char **pder, int derlen);
195 int (*param_encode) (const EVP_PKEY *pkey, unsigned char **pder);
196 int (*param_missing) (const EVP_PKEY *pk);
197 int (*param_copy) (EVP_PKEY *to, const EVP_PKEY *from);
198 int (*param_cmp) (const EVP_PKEY *a, const EVP_PKEY *b);
199 int (*param_print) (BIO *out, const EVP_PKEY *pkey, int indent,
200 ASN1_PCTX *pctx);
201
202The param_decode() and param_encode() methods are called to decode /
203encode DER formatted parameters to / from B<pk>.
204They MUST return 0 on error, 1 on success.
205They're called by L<PEM_read_bio_Parameters(3)> and the B<file:>
206L<OSSL_STORE_LOADER(3)>.
207
208The param_missing() method returns 0 if a key parameter is missing,
209otherwise 1.
210It's called by L<EVP_PKEY_missing_parameters(3)>.
211
212The param_copy() method copies key parameters from B<from> to B<to>.
213It MUST return 0 on error, 1 on success.
214It's called by L<EVP_PKEY_copy_parameters(3)>.
215
216The param_cmp() method compares the parameters of keys B<a> and B<b>.
217It MUST return 1 when the keys are equal, 0 when not equal, or a
218negative number on error.
219It's called by L<EVP_PKEY_cmp_parameters(3)>.
220
221The param_print() method prints the private key parameters in humanly
222readable text to B<out>, indented B<indent> spaces.
223It MUST return 0 on error, 1 on success.
224It's called by L<EVP_PKEY_print_params(3)>.
225
226 int (*sig_print) (BIO *out,
227 const X509_ALGOR *sigalg, const ASN1_STRING *sig,
228 int indent, ASN1_PCTX *pctx);
229
230The sig_print() method prints a signature in humanly readable text to
231B<out>, indented B<indent> spaces.
232B<sigalg> contains the exact signature algorithm.
233If the signature in B<sig> doesn't correspond to what this method
234expects, X509_signature_dump() must be used as a last resort.
235It MUST return 0 on error, 1 on success.
236It's called by L<X509_signature_print(3)>.
237
238 void (*pkey_free) (EVP_PKEY *pkey);
239
240The pkey_free() method helps freeing the internals of B<pkey>.
241It's called by L<EVP_PKEY_free(3)>, L<EVP_PKEY_set_type(3)>,
242L<EVP_PKEY_set_type_str(3)>, and L<EVP_PKEY_assign(3)>.
243
244 int (*pkey_ctrl) (EVP_PKEY *pkey, int op, long arg1, void *arg2);
245
246The pkey_ctrl() method adds extra algorithm specific control.
247It's called by L<EVP_PKEY_get_default_digest_nid(3)>,
248L<EVP_PKEY_set1_tls_encodedpoint(3)>,
249L<EVP_PKEY_get1_tls_encodedpoint(3)>, L<PKCS7_SIGNER_INFO_set(3)>,
250L<PKCS7_RECIP_INFO_set(3)>, ...
251
252 int (*old_priv_decode) (EVP_PKEY *pkey,
253 const unsigned char **pder, int derlen);
254 int (*old_priv_encode) (const EVP_PKEY *pkey, unsigned char **pder);
255
256The old_priv_decode() and old_priv_encode() methods decode / encode
257they private key B<pkey> from / to a DER formatted array.
258These are exclusively used to help decoding / encoding older (pre
259PKCS#8) PEM formatted encrypted private keys.
260old_priv_decode() MUST return 0 on error, 1 on success.
261old_priv_encode() MUST the return same kind of values as
262i2d_PrivateKey().
263They're called by L<d2i_PrivateKey(3)> and L<i2d_PrivateKey(3)>.
264
265 int (*item_verify) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
266 X509_ALGOR *a, ASN1_BIT_STRING *sig, EVP_PKEY *pkey);
267 int (*item_sign) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
268 X509_ALGOR *alg1, X509_ALGOR *alg2,
269 ASN1_BIT_STRING *sig);
270
271The item_sign() and item_verify() methods make it possible to have
272algorithm specific signatures and verification of them.
273
274item_sign() MUST return one of:
275
276=over 4
277
278=item <=0
279
280error
281
287f5551 282=item Z<>1
751148e2
RL
283
284item_sign() did everything, OpenSSL internals just needs to pass the
285signature length back.
286
287f5551 287=item Z<>2
751148e2
RL
288
289item_sign() did nothing, OpenSSL internal standard routines are
290expected to continue with the default signature production.
291
287f5551 292=item Z<>3
751148e2
RL
293
294item_sign() set the algorithm identifier B<algor1> and B<algor2>,
295OpenSSL internals should just sign using those algorithms.
296
297=back
298
299item_verify() MUST return one of:
300
301=over 4
302
303=item <=0
304
305error
306
287f5551 307=item Z<>1
751148e2
RL
308
309item_sign() did everything, OpenSSL internals just needs to pass the
310signature length back.
311
287f5551 312=item Z<>2
751148e2
RL
313
314item_sign() did nothing, OpenSSL internal standard routines are
315expected to continue with the default signature production.
316
317=back
318
319item_verify() and item_sign() are called by L<ASN1_item_verify(3)> and
320L<ASN1_item_sign(3)>, and by extension, L<X509_verify(3)>,
321L<X509_REQ_verify(3)>, L<X509_sign(3)>, L<X509_REQ_sign(3)>, ...
322
323 int (*siginf_set) (X509_SIG_INFO *siginf, const X509_ALGOR *alg,
324 const ASN1_STRING *sig);
325
326The siginf_set() method is used to set custom B<X509_SIG_INFO>
327parameters.
328It MUST return 0 on error, or 1 on success.
329It's called as part of L<X509_check_purpose(3)>, L<X509_check_ca(3)>
330and L<X509_check_issued(3)>.
331
332 int (*pkey_check) (const EVP_PKEY *pk);
b0004708
PY
333 int (*pkey_public_check) (const EVP_PKEY *pk);
334 int (*pkey_param_check) (const EVP_PKEY *pk);
751148e2 335
b0004708
PY
336The pkey_check(), pkey_public_check() and pkey_param_check() methods are used
337to check the validity of B<pk> for key-pair, public component and parameters,
338respectively.
339They MUST return 0 for an invalid key, or 1 for a valid key.
340They are called by L<EVP_PKEY_check(3)>, L<EVP_PKEY_public_check(3)> and
341L<EVP_PKEY_param_check(3)> respectively.
751148e2 342
e8f9f08f
MC
343 int (*set_priv_key) (EVP_PKEY *pk, const unsigned char *priv, size_t len);
344 int (*set_pub_key) (EVP_PKEY *pk, const unsigned char *pub, size_t len);
345
346The set_priv_key() and set_pub_key() methods are used to set the raw private and
347public key data for an EVP_PKEY. They MUST return 0 on error, or 1 on success.
f929439f
MC
348They are called by L<EVP_PKEY_new_raw_private_key(3)>, and
349L<EVP_PKEY_new_raw_public_key(3)> respectively.
e8f9f08f 350
751148e2
RL
351=head2 Functions
352
353EVP_PKEY_asn1_new() creates and returns a new B<EVP_PKEY_ASN1_METHOD>
354object, and associates the given B<id>, B<flags>, B<pem_str> and
355B<info>.
356B<id> is a NID, B<pem_str> is the PEM type string, B<info> is a
357descriptive string.
358The following B<flags> are supported:
359
360 ASN1_PKEY_SIGPARAM_NULL
361
362If B<ASN1_PKEY_SIGPARAM_NULL> is set, then the signature algorithm
363parameters are given the type B<V_ASN1_NULL> by default, otherwise
364they will be given the type B<V_ASN1_UNDEF> (i.e. the parameter is
365omitted).
366See L<X509_ALGOR_set0(3)> for more information.
367
368EVP_PKEY_asn1_copy() copies an B<EVP_PKEY_ASN1_METHOD> object from
369B<src> to B<dst>.
370This function is not thread safe, it's recommended to only use this
371when initializing the application.
372
373EVP_PKEY_asn1_free() frees an existing B<EVP_PKEY_ASN1_METHOD> pointed
374by B<ameth>.
375
376EVP_PKEY_asn1_add0() adds B<ameth> to the user defined stack of
377methods unless another B<EVP_PKEY_ASN1_METHOD> with the same NID is
378already there.
379This function is not thread safe, it's recommended to only use this
380when initializing the application.
381
382EVP_PKEY_asn1_add_alias() creates an alias with the NID B<to> for the
383B<EVP_PKEY_ASN1_METHOD> with NID B<from> unless another
384B<EVP_PKEY_ASN1_METHOD> with the same NID is already added.
385This function is not thread safe, it's recommended to only use this
386when initializing the application.
387
388EVP_PKEY_asn1_set_public(), EVP_PKEY_asn1_set_private(),
389EVP_PKEY_asn1_set_param(), EVP_PKEY_asn1_set_free(),
390EVP_PKEY_asn1_set_ctrl(), EVP_PKEY_asn1_set_item(),
b0004708 391EVP_PKEY_asn1_set_siginf(), EVP_PKEY_asn1_set_check(),
e8f9f08f
MC
392EVP_PKEY_asn1_set_public_check(), EVP_PKEY_asn1_set_param_check(),
393EVP_PKEY_asn1_set_security_bits(), EVP_PKEY_asn1_set_set_priv_key() and
394EVP_PKEY_asn1_set_set_pub_key() set the diverse methods of the given
751148e2
RL
395B<EVP_PKEY_ASN1_METHOD> object.
396
397EVP_PKEY_get0_asn1() finds the B<EVP_PKEY_ASN1_METHOD> associated
398with the key B<pkey>.
399
400=head1 RETURN VALUES
401
402EVP_PKEY_asn1_new() returns NULL on error, or a pointer to an
403B<EVP_PKEY_ASN1_METHOD> object otherwise.
404
405EVP_PKEY_asn1_add0() and EVP_PKEY_asn1_add_alias() return 0 on error,
406or 1 on success.
407
408EVP_PKEY_get0_asn1() returns NULL on error, or a pointer to a constant
409B<EVP_PKEY_ASN1_METHOD> object otherwise.
410
411=head1 COPYRIGHT
412
b0edda11 413Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
751148e2
RL
414
415Licensed under the OpenSSL license (the "License"). You may not use
416this file except in compliance with the License. You can obtain a copy
417in the file LICENSE in the source distribution or at
418L<https://www.openssl.org/source/license.html>.
419
420=cut