10 EVP_PKEY_asn1_add_alias,
11 EVP_PKEY_asn1_set_public,
12 EVP_PKEY_asn1_set_private,
13 EVP_PKEY_asn1_set_param,
14 EVP_PKEY_asn1_set_free,
15 EVP_PKEY_asn1_set_ctrl,
16 EVP_PKEY_asn1_set_item,
17 EVP_PKEY_asn1_set_siginf,
18 EVP_PKEY_asn1_set_check,
19 EVP_PKEY_asn1_set_security_bits,
21 - manipulating and registering EVP_PKEY_ASN1_METHOD structure
25 #include <openssl/evp.h>
27 typedef struct evp_pkey_asn1_method_st EVP_PKEY_ASN1_METHOD;
29 EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_new(int id, int flags,
32 void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst,
33 const EVP_PKEY_ASN1_METHOD *src);
34 void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth);
35 int EVP_PKEY_asn1_add0(const EVP_PKEY_ASN1_METHOD *ameth);
36 int EVP_PKEY_asn1_add_alias(int to, int from);
38 void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
39 int (*pub_decode) (EVP_PKEY *pk,
41 int (*pub_encode) (X509_PUBKEY *pub,
43 int (*pub_cmp) (const EVP_PKEY *a,
45 int (*pub_print) (BIO *out,
47 int indent, ASN1_PCTX *pctx),
48 int (*pkey_size) (const EVP_PKEY *pk),
49 int (*pkey_bits) (const EVP_PKEY *pk));
50 void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
51 int (*priv_decode) (EVP_PKEY *pk,
52 const PKCS8_PRIV_KEY_INFO
54 int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8,
56 int (*priv_print) (BIO *out,
60 void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
61 int (*param_decode) (EVP_PKEY *pkey,
62 const unsigned char **pder,
64 int (*param_encode) (const EVP_PKEY *pkey,
65 unsigned char **pder),
66 int (*param_missing) (const EVP_PKEY *pk),
67 int (*param_copy) (EVP_PKEY *to,
68 const EVP_PKEY *from),
69 int (*param_cmp) (const EVP_PKEY *a,
71 int (*param_print) (BIO *out,
76 void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth,
77 void (*pkey_free) (EVP_PKEY *pkey));
78 void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
79 int (*pkey_ctrl) (EVP_PKEY *pkey, int op,
80 long arg1, void *arg2));
81 void EVP_PKEY_asn1_set_item(EVP_PKEY_ASN1_METHOD *ameth,
82 int (*item_verify) (EVP_MD_CTX *ctx,
88 int (*item_sign) (EVP_MD_CTX *ctx,
93 ASN1_BIT_STRING *sig));
95 void EVP_PKEY_asn1_set_siginf(EVP_PKEY_ASN1_METHOD *ameth,
96 int (*siginf_set) (X509_SIG_INFO *siginf,
97 const X509_ALGOR *alg,
98 const ASN1_STRING *sig));
100 void EVP_PKEY_asn1_set_check(EVP_PKEY_ASN1_METHOD *ameth,
101 int (*pkey_check) (const EVP_PKEY *pk));
103 void EVP_PKEY_asn1_set_security_bits(EVP_PKEY_ASN1_METHOD *ameth,
104 int (*pkey_security_bits) (const EVP_PKEY
107 const EVP_PKEY_ASN1_METHOD *EVP_PKEY_get0_asn1(const EVP_PKEY *pkey);
111 B<EVP_PKEY_ASN1_METHOD> is a structure which holds a set of ASN.1
112 conversion, printing and information methods for a specific public key
115 There are two places where the B<EVP_PKEY_ASN1_METHOD> objects are
116 stored: one is a built-in array representing the standard methods for
117 different algorithms, and the other one is a stack of user-defined
118 application-specific methods, which can be manipulated by using
119 L<EVP_PKEY_asn1_add0(3)>.
123 The methods are the underlying implementations of a particular public
124 key algorithm present by the B<EVP_PKEY> object.
126 int (*pub_decode) (EVP_PKEY *pk, X509_PUBKEY *pub);
127 int (*pub_encode) (X509_PUBKEY *pub, const EVP_PKEY *pk);
128 int (*pub_cmp) (const EVP_PKEY *a, const EVP_PKEY *b);
129 int (*pub_print) (BIO *out, const EVP_PKEY *pkey, int indent,
132 The pub_decode() and pub_encode() methods are called to decode /
133 encode B<X509_PUBKEY> ASN.1 parameters to / from B<pk>.
134 They MUST return 0 on error, 1 on success.
135 They're called by L<X509_PUBKEY_get0(3)> and L<X509_PUBKEY_set(3)>.
137 The pub_cmp() method is called when two public keys are to be
139 It MUST return 1 when the keys are equal, 0 otherwise.
140 It's called by L<EVP_PKEY_cmp(3)>.
142 The pub_print() method is called to print a public key in humanly
143 readable text to B<out>, indented B<indent> spaces.
144 It MUST return 0 on error, 1 on success.
145 It's called by L<EVP_PKEY_print_public(3)>.
147 int (*priv_decode) (EVP_PKEY *pk, const PKCS8_PRIV_KEY_INFO *p8inf);
148 int (*priv_encode) (PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk);
149 int (*priv_print) (BIO *out, const EVP_PKEY *pkey, int indent,
152 The priv_decode() and priv_encode() methods are called to decode /
153 encode B<PKCS8_PRIV_KEY_INFO> form private key to / from B<pk>.
154 They MUST return 0 on error, 1 on success.
155 They're called by L<EVP_PKCS82PKEY(3)> and L<EVP_PKEY2PKCS8(3)>.
157 The priv_print() method is called to print a private key in humanly
158 readable text to B<out>, indented B<indent> spaces.
159 It MUST return 0 on error, 1 on success.
160 It's called by L<EVP_PKEY_print_private(3)>.
162 int (*pkey_size) (const EVP_PKEY *pk);
163 int (*pkey_bits) (const EVP_PKEY *pk);
164 int (*pkey_security_bits) (const EVP_PKEY *pk);
166 The pkey_size() method returns the key size in bytes.
167 It's called by L<EVP_PKEY_size(3)>.
169 The pkey_bits() method returns the key size in bits.
170 It's called by L<EVP_PKEY_bits(3)>.
172 int (*param_decode) (EVP_PKEY *pkey,
173 const unsigned char **pder, int derlen);
174 int (*param_encode) (const EVP_PKEY *pkey, unsigned char **pder);
175 int (*param_missing) (const EVP_PKEY *pk);
176 int (*param_copy) (EVP_PKEY *to, const EVP_PKEY *from);
177 int (*param_cmp) (const EVP_PKEY *a, const EVP_PKEY *b);
178 int (*param_print) (BIO *out, const EVP_PKEY *pkey, int indent,
181 The param_decode() and param_encode() methods are called to decode /
182 encode DER formatted parameters to / from B<pk>.
183 They MUST return 0 on error, 1 on success.
184 They're called by L<PEM_read_bio_Parameters(3)> and the B<file:>
185 L<OSSL_STORE_LOADER(3)>.
187 The param_missing() method returns 0 if a key parameter is missing,
189 It's called by L<EVP_PKEY_missing_parameters(3)>.
191 The param_copy() method copies key parameters from B<from> to B<to>.
192 It MUST return 0 on error, 1 on success.
193 It's called by L<EVP_PKEY_copy_parameters(3)>.
195 The param_cmp() method compares the parameters of keys B<a> and B<b>.
196 It MUST return 1 when the keys are equal, 0 when not equal, or a
197 negative number on error.
198 It's called by L<EVP_PKEY_cmp_parameters(3)>.
200 The param_print() method prints the private key parameters in humanly
201 readable text to B<out>, indented B<indent> spaces.
202 It MUST return 0 on error, 1 on success.
203 It's called by L<EVP_PKEY_print_params(3)>.
205 int (*sig_print) (BIO *out,
206 const X509_ALGOR *sigalg, const ASN1_STRING *sig,
207 int indent, ASN1_PCTX *pctx);
209 The sig_print() method prints a signature in humanly readable text to
210 B<out>, indented B<indent> spaces.
211 B<sigalg> contains the exact signature algorithm.
212 If the signature in B<sig> doesn't correspond to what this method
213 expects, X509_signature_dump() must be used as a last resort.
214 It MUST return 0 on error, 1 on success.
215 It's called by L<X509_signature_print(3)>.
217 void (*pkey_free) (EVP_PKEY *pkey);
219 The pkey_free() method helps freeing the internals of B<pkey>.
220 It's called by L<EVP_PKEY_free(3)>, L<EVP_PKEY_set_type(3)>,
221 L<EVP_PKEY_set_type_str(3)>, and L<EVP_PKEY_assign(3)>.
223 int (*pkey_ctrl) (EVP_PKEY *pkey, int op, long arg1, void *arg2);
225 The pkey_ctrl() method adds extra algorithm specific control.
226 It's called by L<EVP_PKEY_get_default_digest_nid(3)>,
227 L<EVP_PKEY_set1_tls_encodedpoint(3)>,
228 L<EVP_PKEY_get1_tls_encodedpoint(3)>, L<PKCS7_SIGNER_INFO_set(3)>,
229 L<PKCS7_RECIP_INFO_set(3)>, ...
231 int (*old_priv_decode) (EVP_PKEY *pkey,
232 const unsigned char **pder, int derlen);
233 int (*old_priv_encode) (const EVP_PKEY *pkey, unsigned char **pder);
235 The old_priv_decode() and old_priv_encode() methods decode / encode
236 they private key B<pkey> from / to a DER formatted array.
237 These are exclusively used to help decoding / encoding older (pre
238 PKCS#8) PEM formatted encrypted private keys.
239 old_priv_decode() MUST return 0 on error, 1 on success.
240 old_priv_encode() MUST the return same kind of values as
242 They're called by L<d2i_PrivateKey(3)> and L<i2d_PrivateKey(3)>.
244 int (*item_verify) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
245 X509_ALGOR *a, ASN1_BIT_STRING *sig, EVP_PKEY *pkey);
246 int (*item_sign) (EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
247 X509_ALGOR *alg1, X509_ALGOR *alg2,
248 ASN1_BIT_STRING *sig);
250 The item_sign() and item_verify() methods make it possible to have
251 algorithm specific signatures and verification of them.
253 item_sign() MUST return one of:
263 item_sign() did everything, OpenSSL internals just needs to pass the
264 signature length back.
268 item_sign() did nothing, OpenSSL internal standard routines are
269 expected to continue with the default signature production.
273 item_sign() set the algorithm identifier B<algor1> and B<algor2>,
274 OpenSSL internals should just sign using those algorithms.
278 item_verify() MUST return one of:
288 item_sign() did everything, OpenSSL internals just needs to pass the
289 signature length back.
293 item_sign() did nothing, OpenSSL internal standard routines are
294 expected to continue with the default signature production.
298 item_verify() and item_sign() are called by L<ASN1_item_verify(3)> and
299 L<ASN1_item_sign(3)>, and by extension, L<X509_verify(3)>,
300 L<X509_REQ_verify(3)>, L<X509_sign(3)>, L<X509_REQ_sign(3)>, ...
302 int (*siginf_set) (X509_SIG_INFO *siginf, const X509_ALGOR *alg,
303 const ASN1_STRING *sig);
305 The siginf_set() method is used to set custom B<X509_SIG_INFO>
307 It MUST return 0 on error, or 1 on success.
308 It's called as part of L<X509_check_purpose(3)>, L<X509_check_ca(3)>
309 and L<X509_check_issued(3)>.
311 int (*pkey_check) (const EVP_PKEY *pk);
313 The pkey_check() method is used to check the validity of B<pk>.
314 It MUST return 0 for an invalid key, or 1 for a valid key.
315 It's called by L<EVP_PKEY_check(3)>.
319 EVP_PKEY_asn1_new() creates and returns a new B<EVP_PKEY_ASN1_METHOD>
320 object, and associates the given B<id>, B<flags>, B<pem_str> and
322 B<id> is a NID, B<pem_str> is the PEM type string, B<info> is a
324 The following B<flags> are supported:
326 ASN1_PKEY_SIGPARAM_NULL
328 If B<ASN1_PKEY_SIGPARAM_NULL> is set, then the signature algorithm
329 parameters are given the type B<V_ASN1_NULL> by default, otherwise
330 they will be given the type B<V_ASN1_UNDEF> (i.e. the parameter is
332 See L<X509_ALGOR_set0(3)> for more information.
334 EVP_PKEY_asn1_copy() copies an B<EVP_PKEY_ASN1_METHOD> object from
336 This function is not thread safe, it's recommended to only use this
337 when initializing the application.
339 EVP_PKEY_asn1_free() frees an existing B<EVP_PKEY_ASN1_METHOD> pointed
342 EVP_PKEY_asn1_add0() adds B<ameth> to the user defined stack of
343 methods unless another B<EVP_PKEY_ASN1_METHOD> with the same NID is
345 This function is not thread safe, it's recommended to only use this
346 when initializing the application.
348 EVP_PKEY_asn1_add_alias() creates an alias with the NID B<to> for the
349 B<EVP_PKEY_ASN1_METHOD> with NID B<from> unless another
350 B<EVP_PKEY_ASN1_METHOD> with the same NID is already added.
351 This function is not thread safe, it's recommended to only use this
352 when initializing the application.
354 EVP_PKEY_asn1_set_public(), EVP_PKEY_asn1_set_private(),
355 EVP_PKEY_asn1_set_param(), EVP_PKEY_asn1_set_free(),
356 EVP_PKEY_asn1_set_ctrl(), EVP_PKEY_asn1_set_item(),
357 EVP_PKEY_asn1_set_siginf(), EVP_PKEY_asn1_set_check(), and
358 EVP_PKEY_asn1_set_security_bits() set the diverse methods of the given
359 B<EVP_PKEY_ASN1_METHOD> object.
361 EVP_PKEY_get0_asn1() finds the B<EVP_PKEY_ASN1_METHOD> associated
362 with the key B<pkey>.
366 EVP_PKEY_asn1_new() returns NULL on error, or a pointer to an
367 B<EVP_PKEY_ASN1_METHOD> object otherwise.
369 EVP_PKEY_asn1_add0() and EVP_PKEY_asn1_add_alias() return 0 on error,
372 EVP_PKEY_get0_asn1() returns NULL on error, or a pointer to a constant
373 B<EVP_PKEY_ASN1_METHOD> object otherwise.
377 Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
379 Licensed under the OpenSSL license (the "License"). You may not use
380 this file except in compliance with the License. You can obtain a copy
381 in the file LICENSE in the source distribution or at
382 L<https://www.openssl.org/source/license.html>.