]>
Commit | Line | Data |
---|---|---|
ece9304c | 1 | /* |
a28d06f3 | 2 | * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved. |
ece9304c RL |
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 | ||
c319b627 RL |
10 | #ifndef ENCODER_PROVIDER |
11 | # error Macro ENCODER_PROVIDER undefined | |
ece9304c RL |
12 | #endif |
13 | ||
c319b627 RL |
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" | |
6a2b8ff3 | 18 | #define ENCODER_STRUCTURE_PrivateKeyInfo "PrivateKeyInfo" |
c319b627 RL |
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) } | |
0cc0164d RL |
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) \ | |
c319b627 RL |
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), | |
f2db0528 RL |
63 | # ifndef OPENSSL_NO_SM2 |
64 | ENCODER_TEXT("SM2", sm2, yes), | |
65 | # endif | |
c319b627 RL |
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 = | |
fe75766c TM |
77 | * OSSL_ENCODER_CTX_new_for_pkey(pkey, selection, "DER", "type-specific", |
78 | * NULL, NULL); | |
c319b627 RL |
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 = | |
fe75766c TM |
85 | * OSSL_ENCODER_CTX_new_for_pkey(pkey, selection, "PEM", "type-specific", |
86 | * NULL, NULL); | |
c319b627 RL |
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 */ | |
0cc0164d RL |
93 | ENCODER_w_structure("RSA", rsa, yes, der, type_specific_keypair), |
94 | ENCODER_w_structure("RSA", rsa, yes, pem, type_specific_keypair), | |
c319b627 RL |
95 | #ifndef OPENSSL_NO_DH |
96 | /* DH and X9.42 DH only support key parameters output. */ | |
0cc0164d RL |
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), | |
c319b627 RL |
101 | #endif |
102 | #ifndef OPENSSL_NO_DSA | |
0cc0164d RL |
103 | ENCODER_w_structure("DSA", dsa, yes, der, type_specific), |
104 | ENCODER_w_structure("DSA", dsa, yes, pem, type_specific), | |
c319b627 RL |
105 | #endif |
106 | #ifndef OPENSSL_NO_EC | |
c8182743 | 107 | /* EC only supports keypair and parameters DER and PEM output. */ |
0cc0164d RL |
108 | ENCODER_w_structure("EC", ec, yes, der, type_specific_no_pub), |
109 | ENCODER_w_structure("EC", ec, yes, pem, type_specific_no_pub), | |
c8182743 RL |
110 | /* EC supports blob output for the public key */ |
111 | ENCODER("EC", ec, yes, blob), | |
f2db0528 RL |
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), | |
c8182743 | 115 | ENCODER("SM2", sm2, yes, blob), |
f2db0528 | 116 | # endif |
0cc0164d RL |
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), | |
c319b627 RL |
127 | #endif |
128 | ||
129 | /* | |
6a2b8ff3 | 130 | * Entries for PKCS#8 (PrivateKeyInfo) and SubjectPublicKeyInfo. |
c319b627 RL |
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 | */ | |
6a2b8ff3 RL |
136 | ENCODER_w_structure("RSA", rsa, yes, der, PrivateKeyInfo), |
137 | ENCODER_w_structure("RSA", rsa, yes, pem, PrivateKeyInfo), | |
0cc0164d RL |
138 | ENCODER_w_structure("RSA", rsa, yes, der, SubjectPublicKeyInfo), |
139 | ENCODER_w_structure("RSA", rsa, yes, pem, SubjectPublicKeyInfo), | |
c319b627 | 140 | |
6a2b8ff3 RL |
141 | ENCODER_w_structure("RSA-PSS", rsapss, yes, der, PrivateKeyInfo), |
142 | ENCODER_w_structure("RSA-PSS", rsapss, yes, pem, PrivateKeyInfo), | |
0cc0164d RL |
143 | ENCODER_w_structure("RSA-PSS", rsapss, yes, der, SubjectPublicKeyInfo), |
144 | ENCODER_w_structure("RSA-PSS", rsapss, yes, pem, SubjectPublicKeyInfo), | |
ece9304c RL |
145 | |
146 | #ifndef OPENSSL_NO_DH | |
6a2b8ff3 RL |
147 | ENCODER_w_structure("DH", dh, yes, der, PrivateKeyInfo), |
148 | ENCODER_w_structure("DH", dh, yes, pem, PrivateKeyInfo), | |
0cc0164d RL |
149 | ENCODER_w_structure("DH", dh, yes, der, SubjectPublicKeyInfo), |
150 | ENCODER_w_structure("DH", dh, yes, pem, SubjectPublicKeyInfo), | |
151 | ||
6a2b8ff3 RL |
152 | ENCODER_w_structure("DHX", dhx, yes, der, PrivateKeyInfo), |
153 | ENCODER_w_structure("DHX", dhx, yes, pem, PrivateKeyInfo), | |
0cc0164d RL |
154 | ENCODER_w_structure("DHX", dhx, yes, der, SubjectPublicKeyInfo), |
155 | ENCODER_w_structure("DHX", dhx, yes, pem, SubjectPublicKeyInfo), | |
ece9304c RL |
156 | #endif |
157 | ||
158 | #ifndef OPENSSL_NO_DSA | |
6a2b8ff3 RL |
159 | ENCODER_w_structure("DSA", dsa, yes, der, PrivateKeyInfo), |
160 | ENCODER_w_structure("DSA", dsa, yes, pem, PrivateKeyInfo), | |
0cc0164d RL |
161 | ENCODER_w_structure("DSA", dsa, yes, der, SubjectPublicKeyInfo), |
162 | ENCODER_w_structure("DSA", dsa, yes, pem, SubjectPublicKeyInfo), | |
ece9304c RL |
163 | #endif |
164 | ||
165 | #ifndef OPENSSL_NO_EC | |
6a2b8ff3 RL |
166 | ENCODER_w_structure("EC", ec, yes, der, PrivateKeyInfo), |
167 | ENCODER_w_structure("EC", ec, yes, pem, PrivateKeyInfo), | |
0cc0164d RL |
168 | ENCODER_w_structure("EC", ec, yes, der, SubjectPublicKeyInfo), |
169 | ENCODER_w_structure("EC", ec, yes, pem, SubjectPublicKeyInfo), | |
170 | ||
6a2b8ff3 RL |
171 | ENCODER_w_structure("X25519", x25519, yes, der, PrivateKeyInfo), |
172 | ENCODER_w_structure("X25519", x25519, yes, pem, PrivateKeyInfo), | |
0cc0164d RL |
173 | ENCODER_w_structure("X25519", x25519, yes, der, SubjectPublicKeyInfo), |
174 | ENCODER_w_structure("X25519", x25519, yes, pem, SubjectPublicKeyInfo), | |
175 | ||
6a2b8ff3 RL |
176 | ENCODER_w_structure("X448", x448, yes, der, PrivateKeyInfo), |
177 | ENCODER_w_structure("X448", x448, yes, pem, PrivateKeyInfo), | |
0cc0164d RL |
178 | ENCODER_w_structure("X448", x448, yes, der, SubjectPublicKeyInfo), |
179 | ENCODER_w_structure("X448", x448, yes, pem, SubjectPublicKeyInfo), | |
180 | ||
6a2b8ff3 RL |
181 | ENCODER_w_structure("ED25519", ed25519, yes, der, PrivateKeyInfo), |
182 | ENCODER_w_structure("ED25519", ed25519, yes, pem, PrivateKeyInfo), | |
0cc0164d RL |
183 | ENCODER_w_structure("ED25519", ed25519, yes, der, SubjectPublicKeyInfo), |
184 | ENCODER_w_structure("ED25519", ed25519, yes, pem, SubjectPublicKeyInfo), | |
185 | ||
6a2b8ff3 RL |
186 | ENCODER_w_structure("ED448", ed448, yes, der, PrivateKeyInfo), |
187 | ENCODER_w_structure("ED448", ed448, yes, pem, PrivateKeyInfo), | |
0cc0164d RL |
188 | ENCODER_w_structure("ED448", ed448, yes, der, SubjectPublicKeyInfo), |
189 | ENCODER_w_structure("ED448", ed448, yes, pem, SubjectPublicKeyInfo), | |
f2db0528 RL |
190 | |
191 | # ifndef OPENSSL_NO_SM2 | |
6a2b8ff3 RL |
192 | ENCODER_w_structure("SM2", sm2, yes, der, PrivateKeyInfo), |
193 | ENCODER_w_structure("SM2", sm2, yes, pem, PrivateKeyInfo), | |
f2db0528 RL |
194 | ENCODER_w_structure("SM2", sm2, yes, der, SubjectPublicKeyInfo), |
195 | ENCODER_w_structure("SM2", sm2, yes, pem, SubjectPublicKeyInfo), | |
196 | # endif | |
c319b627 RL |
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 | |
fe75766c | 203 | * OSSL_ENCODER_CTX_new_for_pkey(). |
c319b627 RL |
204 | */ |
205 | ||
206 | /* The RSA encoders only support private key and public key output */ | |
0cc0164d RL |
207 | ENCODER_w_structure("RSA", rsa, yes, der, RSA), |
208 | ENCODER_w_structure("RSA", rsa, yes, pem, RSA), | |
c319b627 RL |
209 | #ifndef OPENSSL_NO_DH |
210 | /* DH and X9.42 DH only support key parameters output. */ | |
0cc0164d RL |
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), | |
c319b627 RL |
215 | #endif |
216 | #ifndef OPENSSL_NO_DSA | |
0cc0164d RL |
217 | ENCODER_w_structure("DSA", dsa, yes, der, DSA), |
218 | ENCODER_w_structure("DSA", dsa, yes, pem, DSA), | |
c319b627 RL |
219 | #endif |
220 | #ifndef OPENSSL_NO_EC | |
0cc0164d RL |
221 | ENCODER_w_structure("EC", ec, yes, der, EC), |
222 | ENCODER_w_structure("EC", ec, yes, pem, EC), | |
c319b627 RL |
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 */ | |
0cc0164d RL |
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), | |
c319b627 RL |
236 | #ifndef OPENSSL_NO_DH |
237 | /* PKCS#3 defines the format for DH parameters */ | |
0cc0164d RL |
238 | ENCODER_w_structure("DH", dh, yes, der, PKCS3), |
239 | ENCODER_w_structure("DH", dh, yes, pem, PKCS3), | |
c319b627 | 240 | /* X9.42 defines the format for DHX parameters */ |
0cc0164d RL |
241 | ENCODER_w_structure("DHX", dhx, yes, der, X9_42), |
242 | ENCODER_w_structure("DHX", dhx, yes, pem, X9_42), | |
c319b627 RL |
243 | #endif |
244 | #ifndef OPENSSL_NO_EC | |
245 | /* RFC 5915 defines the format for EC keys and parameters */ | |
0cc0164d RL |
246 | ENCODER_w_structure("EC", ec, yes, der, X9_62), |
247 | ENCODER_w_structure("EC", ec, yes, pem, X9_62), | |
ece9304c | 248 | #endif |