1OSSL_ENCODER_CTX_NEW_FOR_PKEY(3ossl)OpenSSLOSSL_ENCODER_CTX_NEW_FOR_PKEY(3ossl)
2
3
4

NAME

6       OSSL_ENCODER_CTX_new_for_pkey, OSSL_ENCODER_CTX_set_cipher,
7       OSSL_ENCODER_CTX_set_passphrase, OSSL_ENCODER_CTX_set_pem_password_cb,
8       OSSL_ENCODER_CTX_set_passphrase_cb, OSSL_ENCODER_CTX_set_passphrase_ui
9       - Encoder routines to encode EVP_PKEYs
10

SYNOPSIS

12        #include <openssl/encoder.h>
13
14        OSSL_ENCODER_CTX *
15        OSSL_ENCODER_CTX_new_for_pkey(const EVP_PKEY *pkey, int selection,
16                                      const char *output_type,
17                                      const char *output_structure,
18                                      const char *propquery);
19
20        int OSSL_ENCODER_CTX_set_cipher(OSSL_ENCODER_CTX *ctx,
21                                        const char *cipher_name,
22                                        const char *propquery);
23        int OSSL_ENCODER_CTX_set_passphrase(OSSL_ENCODER_CTX *ctx,
24                                            const unsigned char *kstr,
25                                            size_t klen);
26        int OSSL_ENCODER_CTX_set_pem_password_cb(OSSL_ENCODER_CTX *ctx,
27                                                 pem_password_cb *cb, void *cbarg);
28        int OSSL_ENCODER_CTX_set_passphrase_ui(OSSL_ENCODER_CTX *ctx,
29                                               const UI_METHOD *ui_method,
30                                               void *ui_data);
31        int OSSL_ENCODER_CTX_set_passphrase_cb(OSSL_ENCODER_CTX *ctx,
32                                               OSSL_PASSPHRASE_CALLBACK *cb,
33                                               void *cbarg);
34

DESCRIPTION

36       OSSL_ENCODER_CTX_new_for_pkey() is a utility function that creates a
37       OSSL_ENCODER_CTX, finds all applicable encoder implementations and sets
38       them up, so almost all the caller has to do next is call functions like
39       OSSL_ENCODER_to_bio(3).  output_type determines the final output
40       encoding, and selection can be used to select what parts of the pkey
41       should be included in the output.  output_type is further discussed in
42       "Output types" below, and selection is further described in
43       "Selections".
44
45       Internally, OSSL_ENCODER_CTX_new_for_pkey() uses the names from the
46       EVP_KEYMGMT(3) implementation associated with pkey to build a list of
47       applicable encoder implementations that are used to process the pkey
48       into the encoding named by output_type, with the outermost structure
49       named by output_structure if that's relevant.  All these
50       implementations are implicitly fetched, with propquery for finer
51       selection.
52
53       If no suitable encoder implementation is found,
54       OSSL_ENCODER_CTX_new_for_pkey() still creates a OSSL_ENCODER_CTX, but
55       with no associated encoder (OSSL_ENCODER_CTX_get_num_encoders(3)
56       returns zero).  This helps the caller to distinguish between an error
57       when creating the OSSL_ENCODER_CTX and missing encoder implementation,
58       and allows it to act accordingly.
59
60       OSSL_ENCODER_CTX_set_cipher() tells the implementation what cipher
61       should be used to encrypt encoded keys.  The cipher is given by name
62       cipher_name.  The interpretation of that cipher_name is implementation
63       dependent.  The implementation may implement the cipher directly itself
64       or by other implementations, or it may choose to fetch it.  If the
65       implementation supports fetching the cipher, then it may use propquery
66       as properties to be queried for when fetching.  cipher_name may also be
67       NULL, which will result in unencrypted encoding.
68
69       OSSL_ENCODER_CTX_set_passphrase() gives the implementation a pass
70       phrase to use when encrypting the encoded private key.  Alternatively,
71       a pass phrase callback may be specified with the following functions.
72
73       OSSL_ENCODER_CTX_set_pem_password_cb(),
74       OSSL_ENCODER_CTX_set_passphrase_ui() and
75       OSSL_ENCODER_CTX_set_passphrase_cb() sets up a callback method that the
76       implementation can use to prompt for a pass phrase, giving the caller
77       the choice of prefered pass phrase callback form.  These are called
78       indirectly, through an internal OSSL_PASSPHRASE_CALLBACK function.
79
80   Output types
81       The possible EVP_PKEY output types depends on the available
82       implementations.
83
84       OpenSSL has built in implementations for the following output types:
85
86       "TEXT"
87           The output is a human readable description of the key.
88           EVP_PKEY_print_private(3), EVP_PKEY_print_public(3) and
89           EVP_PKEY_print_params(3) use this for their output.
90
91       "DER"
92           The output is the DER encoding of the selection of the pkey.
93
94       "PEM"
95           The output is the selection of the pkey in PEM format.
96
97   Selections
98       selection can be any one of the values described in "Selections" in
99       EVP_PKEY_fromdata(3).
100
101       These are only 'hints' since the encoder implementations are free to
102       determine what makes sense to include in the output, and this may
103       depend on the desired output.  For example, an EC key in a PKCS#8
104       structure doesn't usually include the public key.
105

RETURN VALUES

107       OSSL_ENCODER_CTX_new_for_pkey() returns a pointer to an
108       OSSL_ENCODER_CTX, or NULL if it couldn't be created.
109
110       OSSL_ENCODER_CTX_set_cipher(), OSSL_ENCODER_CTX_set_passphrase(),
111       OSSL_ENCODER_CTX_set_pem_password_cb(),
112       OSSL_ENCODER_CTX_set_passphrase_ui() and
113       OSSL_ENCODER_CTX_set_passphrase_cb() all return 1 on success, or 0 on
114       failure.
115

SEE ALSO

117       provider(7), OSSL_ENCODER(3), OSSL_ENCODER_CTX(3)
118

HISTORY

120       The functions described here were added in OpenSSL 3.0.
121
123       Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
124
125       Licensed under the Apache License 2.0 (the "License").  You may not use
126       this file except in compliance with the License.  You can obtain a copy
127       in the file LICENSE in the source distribution or at
128       <https://www.openssl.org/source/license.html>.
129
130
131
1323.0.5                             2022-11-0O1SSL_ENCODER_CTX_NEW_FOR_PKEY(3ossl)
Impressum