prov: use new MAC_init arguments in signature legacy code
[openssl.git] / providers / encoders.inc
1 /*
2  * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 #ifndef ENCODER_PROVIDER
11 # error Macro ENCODER_PROVIDER undefined
12 #endif
13
14 #define ENCODER_STRUCTURE_type_specific_keypair         "type-specific"
15 #define ENCODER_STRUCTURE_type_specific_params          "type-specific"
16 #define ENCODER_STRUCTURE_type_specific                 "type-specific"
17 #define ENCODER_STRUCTURE_type_specific_no_pub          "type-specific"
18 #define ENCODER_STRUCTURE_PKCS8                         "pkcs8"
19 #define ENCODER_STRUCTURE_SubjectPublicKeyInfo          "SubjectPublicKeyInfo"
20 #define ENCODER_STRUCTURE_DH                            "dh"
21 #define ENCODER_STRUCTURE_DHX                           "dhx"
22 #define ENCODER_STRUCTURE_DSA                           "dsa"
23 #define ENCODER_STRUCTURE_EC                            "ec"
24 #define ENCODER_STRUCTURE_RSA                           "rsa"
25 #define ENCODER_STRUCTURE_PKCS1                         "pkcs1"
26 #define ENCODER_STRUCTURE_PKCS3                         "pkcs3"
27 #define ENCODER_STRUCTURE_X9_42                         "X9.42"
28 #define ENCODER_STRUCTURE_X9_62                         "X9.62"
29
30 /* Arguments are prefixed with '_' to avoid build breaks on certain platforms */
31 #define ENCODER_TEXT(_name, _sym, _fips)                                \
32     { _name,                                                            \
33       "provider=" ENCODER_PROVIDER ",fips=" #_fips ",output=text",      \
34       (ossl_##_sym##_to_text_encoder_functions) }
35 #define ENCODER(_name, _sym, _fips, _output)                            \
36     { _name,                                                            \
37       "provider=" ENCODER_PROVIDER ",fips=" #_fips ",output=" #_output, \
38       (ossl_##_sym##_to_##_output##_encoder_functions) }
39 #define ENCODER_w_structure(_name, _sym, _fips, _output, _structure)    \
40     { _name,                                                            \
41       "provider=" ENCODER_PROVIDER ",fips=" #_fips ",output=" #_output  \
42       ",structure=" ENCODER_STRUCTURE_##_structure,                     \
43       (ossl_##_sym##_to_##_structure##_##_output##_encoder_functions) }
44
45 /*
46  * Entries for human text "encoders"
47  */
48 ENCODER_TEXT("RSA", rsa, yes),
49 ENCODER_TEXT("RSA-PSS", rsapss, yes),
50 #ifndef OPENSSL_NO_DH
51 ENCODER_TEXT("DH", dh, yes),
52 ENCODER_TEXT("DHX", dhx, yes),
53 #endif
54 #ifndef OPENSSL_NO_DSA
55 ENCODER_TEXT("DSA", dsa, yes),
56 #endif
57 #ifndef OPENSSL_NO_EC
58 ENCODER_TEXT("EC", ec, yes),
59 ENCODER_TEXT("ED25519", ed25519, yes),
60 ENCODER_TEXT("ED448", ed448, yes),
61 ENCODER_TEXT("X25519", x25519, yes),
62 ENCODER_TEXT("X448", x448, yes),
63 # ifndef OPENSSL_NO_SM2
64 ENCODER_TEXT("SM2", sm2, yes),
65 # endif
66 #endif
67
68 /*
69  * Entries for key type specific output formats.  The structure name on these
70  * is the same as the key type name.  This allows us to say something like:
71  *
72  * To replace i2d_{TYPE}PrivateKey(), i2d_{TYPE}PublicKey() and
73  * i2d_{TYPE}Params(), use OSSL_ENCODER functions with an OSSL_ENCODER_CTX
74  * created like this:
75  *
76  * OSSL_ENCODER_CTX *ctx =
77  *     OSSL_ENCODER_CTX_new_for_pkey(pkey, selection, "DER", "type-specific",
78  *                                   NULL, NULL);
79  *
80  * To replace PEM_write_bio_{TYPE}PrivateKey(), PEM_write_bio_{TYPE}PublicKey()
81  * and PEM_write_bio_{TYPE}Params(), use OSSL_ENCODER functions with an
82  * OSSL_ENCODER_CTX created like this:
83  *
84  * OSSL_ENCODER_CTX *ctx =
85  *     OSSL_ENCODER_CTX_new_for_pkey(pkey, selection, "PEM", "type-specific",
86  *                                   NULL, NULL);
87  *
88  * We only implement those for which there are current i2d_ and PEM_write_bio
89  * implementations.
90  */
91
92 /* The RSA encoders only support private key and public key output */
93 ENCODER_w_structure("RSA", rsa, yes, der, type_specific_keypair),
94 ENCODER_w_structure("RSA", rsa, yes, pem, type_specific_keypair),
95 #ifndef OPENSSL_NO_DH
96 /* DH and X9.42 DH only support key parameters output. */
97 ENCODER_w_structure("DH", dh, yes, der, type_specific_params),
98 ENCODER_w_structure("DH", dh, yes, pem, type_specific_params),
99 ENCODER_w_structure("DHX", dhx, yes, der, type_specific_params),
100 ENCODER_w_structure("DHX", dhx, yes, pem, type_specific_params),
101 #endif
102 #ifndef OPENSSL_NO_DSA
103 ENCODER_w_structure("DSA", dsa, yes, der, type_specific),
104 ENCODER_w_structure("DSA", dsa, yes, pem, type_specific),
105 #endif
106 #ifndef OPENSSL_NO_EC
107 /* EC only supports keypair and parameters DER and PEM output. */
108 ENCODER_w_structure("EC", ec, yes, der, type_specific_no_pub),
109 ENCODER_w_structure("EC", ec, yes, pem, type_specific_no_pub),
110 /* EC supports blob output for the public key */
111 ENCODER("EC", ec, yes, blob),
112 # ifndef OPENSSL_NO_SM2
113 ENCODER_w_structure("SM2", sm2, yes, der, type_specific_no_pub),
114 ENCODER_w_structure("SM2", sm2, yes, pem, type_specific_no_pub),
115 ENCODER("SM2", sm2, yes, blob),
116 # endif
117 #endif
118
119 /*
120  * Entries for the output formats MSBLOB and PVK
121  */
122 ENCODER("RSA", rsa, yes, msblob),
123 ENCODER("RSA", rsa, yes, pvk),
124 #ifndef OPENSSL_NO_DSA
125 ENCODER("DSA", dsa, yes, msblob),
126 ENCODER("DSA", dsa, yes, pvk),
127 #endif
128
129 /*
130  * Entries for PKCS#8 and SubjectPublicKeyInfo.
131  * The "der" ones are added convenience for any user that wants to use
132  * OSSL_ENCODER directly.
133  * The "pem" ones also support PEM_write_bio_PrivateKey() and
134  * PEM_write_bio_PUBKEY().
135  */
136 ENCODER_w_structure("RSA", rsa, yes, der, PKCS8),
137 ENCODER_w_structure("RSA", rsa, yes, pem, PKCS8),
138 ENCODER_w_structure("RSA", rsa, yes, der, SubjectPublicKeyInfo),
139 ENCODER_w_structure("RSA", rsa, yes, pem, SubjectPublicKeyInfo),
140
141 ENCODER_w_structure("RSA-PSS", rsapss, yes, der, PKCS8),
142 ENCODER_w_structure("RSA-PSS", rsapss, yes, pem, PKCS8),
143 ENCODER_w_structure("RSA-PSS", rsapss, yes, der, SubjectPublicKeyInfo),
144 ENCODER_w_structure("RSA-PSS", rsapss, yes, pem, SubjectPublicKeyInfo),
145
146 #ifndef OPENSSL_NO_DH
147 ENCODER_w_structure("DH", dh, yes, der, PKCS8),
148 ENCODER_w_structure("DH", dh, yes, pem, PKCS8),
149 ENCODER_w_structure("DH", dh, yes, der, SubjectPublicKeyInfo),
150 ENCODER_w_structure("DH", dh, yes, pem, SubjectPublicKeyInfo),
151
152 ENCODER_w_structure("DHX", dhx, yes, der, PKCS8),
153 ENCODER_w_structure("DHX", dhx, yes, pem, PKCS8),
154 ENCODER_w_structure("DHX", dhx, yes, der, SubjectPublicKeyInfo),
155 ENCODER_w_structure("DHX", dhx, yes, pem, SubjectPublicKeyInfo),
156 #endif
157
158 #ifndef OPENSSL_NO_DSA
159 ENCODER_w_structure("DSA", dsa, yes, der, PKCS8),
160 ENCODER_w_structure("DSA", dsa, yes, pem, PKCS8),
161 ENCODER_w_structure("DSA", dsa, yes, der, SubjectPublicKeyInfo),
162 ENCODER_w_structure("DSA", dsa, yes, pem, SubjectPublicKeyInfo),
163 #endif
164
165 #ifndef OPENSSL_NO_EC
166 ENCODER_w_structure("EC", ec, yes, der, PKCS8),
167 ENCODER_w_structure("EC", ec, yes, pem, PKCS8),
168 ENCODER_w_structure("EC", ec, yes, der, SubjectPublicKeyInfo),
169 ENCODER_w_structure("EC", ec, yes, pem, SubjectPublicKeyInfo),
170
171 ENCODER_w_structure("X25519", x25519, yes, der, PKCS8),
172 ENCODER_w_structure("X25519", x25519, yes, pem, PKCS8),
173 ENCODER_w_structure("X25519", x25519, yes, der, SubjectPublicKeyInfo),
174 ENCODER_w_structure("X25519", x25519, yes, pem, SubjectPublicKeyInfo),
175
176 ENCODER_w_structure("X448", x448, yes, der, PKCS8),
177 ENCODER_w_structure("X448", x448, yes, pem, PKCS8),
178 ENCODER_w_structure("X448", x448, yes, der, SubjectPublicKeyInfo),
179 ENCODER_w_structure("X448", x448, yes, pem, SubjectPublicKeyInfo),
180
181 ENCODER_w_structure("ED25519", ed25519, yes, der, PKCS8),
182 ENCODER_w_structure("ED25519", ed25519, yes, pem, PKCS8),
183 ENCODER_w_structure("ED25519", ed25519, yes, der, SubjectPublicKeyInfo),
184 ENCODER_w_structure("ED25519", ed25519, yes, pem, SubjectPublicKeyInfo),
185
186 ENCODER_w_structure("ED448", ed448, yes, der, PKCS8),
187 ENCODER_w_structure("ED448", ed448, yes, pem, PKCS8),
188 ENCODER_w_structure("ED448", ed448, yes, der, SubjectPublicKeyInfo),
189 ENCODER_w_structure("ED448", ed448, yes, pem, SubjectPublicKeyInfo),
190
191 # ifndef OPENSSL_NO_SM2
192 ENCODER_w_structure("SM2", sm2, yes, der, PKCS8),
193 ENCODER_w_structure("SM2", sm2, yes, pem, PKCS8),
194 ENCODER_w_structure("SM2", sm2, yes, der, SubjectPublicKeyInfo),
195 ENCODER_w_structure("SM2", sm2, yes, pem, SubjectPublicKeyInfo),
196 # endif
197 #endif
198
199 /*
200  * Entries for key type specific output formats.  These are exactly the
201  * same as the type specific above, except that they use the key type
202  * name as structure name instead of "type-specific", in the call on
203  * OSSL_ENCODER_CTX_new_for_pkey().
204  */
205
206 /* The RSA encoders only support private key and public key output */
207 ENCODER_w_structure("RSA", rsa, yes, der, RSA),
208 ENCODER_w_structure("RSA", rsa, yes, pem, RSA),
209 #ifndef OPENSSL_NO_DH
210 /* DH and X9.42 DH only support key parameters output. */
211 ENCODER_w_structure("DH", dh, yes, der, DH),
212 ENCODER_w_structure("DH", dh, yes, pem, DH),
213 ENCODER_w_structure("DHX", dhx, yes, der, DHX),
214 ENCODER_w_structure("DHX", dhx, yes, pem, DHX),
215 #endif
216 #ifndef OPENSSL_NO_DSA
217 ENCODER_w_structure("DSA", dsa, yes, der, DSA),
218 ENCODER_w_structure("DSA", dsa, yes, pem, DSA),
219 #endif
220 #ifndef OPENSSL_NO_EC
221 ENCODER_w_structure("EC", ec, yes, der, EC),
222 ENCODER_w_structure("EC", ec, yes, pem, EC),
223 #endif
224
225 /*
226  * Additional entries with structure names being the standard name.
227  * This is entirely for the convenience of the user that wants to use
228  * OSSL_ENCODER directly with names they may fancy.  These do not impact
229  * on libcrypto functionality in any way.
230  */
231 /* PKCS#1 is a well known for plain RSA keys, so we add that too */
232 ENCODER_w_structure("RSA", rsa, yes, der, PKCS1),
233 ENCODER_w_structure("RSA", rsa, yes, pem, PKCS1),
234 ENCODER_w_structure("RSA-PSS", rsapss, yes, der, PKCS1),
235 ENCODER_w_structure("RSA-PSS", rsapss, yes, pem, PKCS1),
236 #ifndef OPENSSL_NO_DH
237 /* PKCS#3 defines the format for DH parameters */
238 ENCODER_w_structure("DH", dh, yes, der, PKCS3),
239 ENCODER_w_structure("DH", dh, yes, pem, PKCS3),
240 /* X9.42 defines the format for DHX parameters */
241 ENCODER_w_structure("DHX", dhx, yes, der, X9_42),
242 ENCODER_w_structure("DHX", dhx, yes, pem, X9_42),
243 #endif
244 #ifndef OPENSSL_NO_EC
245 /* RFC 5915 defines the format for EC keys and parameters */
246 ENCODER_w_structure("EC", ec, yes, der, X9_62),
247 ENCODER_w_structure("EC", ec, yes, pem, X9_62),
248 #endif