xref: /freebsd/crypto/openssl/providers/decoders.inc (revision e7be843b4a162e68651d3911f0357ed464915629)
1/*
2 * Copyright 2020-2025 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 DECODER_PROVIDER
11# error Macro DECODER_PROVIDER undefined
12#endif
13
14#define DECODER_STRUCTURE_type_specific_keypair         "type-specific"
15#define DECODER_STRUCTURE_type_specific_params          "type-specific"
16#define DECODER_STRUCTURE_type_specific                 "type-specific"
17#define DECODER_STRUCTURE_type_specific_no_pub          "type-specific"
18#define DECODER_STRUCTURE_EncryptedPrivateKeyInfo       "EncryptedPrivateKeyInfo"
19#define DECODER_STRUCTURE_PrivateKeyInfo                "PrivateKeyInfo"
20#define DECODER_STRUCTURE_SubjectPublicKeyInfo          "SubjectPublicKeyInfo"
21#define DECODER_STRUCTURE_DH                            "dh"
22#define DECODER_STRUCTURE_DHX                           "dhx"
23#define DECODER_STRUCTURE_DSA                           "dsa"
24#define DECODER_STRUCTURE_EC                            "ec"
25#define DECODER_STRUCTURE_RSA                           "rsa"
26
27/* Arguments are prefixed with '_' to avoid build breaks on certain platforms */
28#define DECODER(_name, _input, _output, _fips)                          \
29    { _name,                                                            \
30      "provider=" DECODER_PROVIDER ",fips=" #_fips ",input=" #_input,   \
31      (ossl_##_input##_to_##_output##_decoder_functions) }
32#define DECODER_w_structure(_name, _input, _structure, _output, _fips)  \
33    { _name,                                                            \
34      "provider=" DECODER_PROVIDER ",fips=" #_fips ",input=" #_input    \
35      ",structure=" DECODER_STRUCTURE_##_structure,                     \
36      (ossl_##_structure##_##_input##_to_##_output##_decoder_functions) }
37
38#ifndef OPENSSL_NO_DH
39DECODER_w_structure("DH", der, PrivateKeyInfo, dh, yes),
40DECODER_w_structure("DH", der, SubjectPublicKeyInfo, dh, yes),
41DECODER_w_structure("DH", der, type_specific_params, dh, yes),
42DECODER_w_structure("DH", der, DH, dh, yes),
43DECODER_w_structure("DHX", der, PrivateKeyInfo, dhx, yes),
44DECODER_w_structure("DHX", der, SubjectPublicKeyInfo, dhx, yes),
45DECODER_w_structure("DHX", der, type_specific_params, dhx, yes),
46DECODER_w_structure("DHX", der, DHX, dhx, yes),
47#endif
48#ifndef OPENSSL_NO_DSA
49DECODER_w_structure("DSA", der, PrivateKeyInfo, dsa, yes),
50DECODER_w_structure("DSA", der, SubjectPublicKeyInfo, dsa, yes),
51DECODER_w_structure("DSA", der, type_specific, dsa, yes),
52DECODER_w_structure("DSA", der, DSA, dsa, yes),
53DECODER("DSA", msblob, dsa, yes),
54DECODER("DSA", pvk, dsa, yes),
55#endif
56#ifndef OPENSSL_NO_EC
57DECODER_w_structure("EC", der, PrivateKeyInfo, ec, yes),
58DECODER_w_structure("EC", der, SubjectPublicKeyInfo, ec, yes),
59DECODER_w_structure("EC", der, type_specific_no_pub, ec, yes),
60DECODER_w_structure("EC", der, EC, ec, yes),
61# ifndef OPENSSL_NO_ECX
62DECODER_w_structure("ED25519", der, PrivateKeyInfo, ed25519, yes),
63DECODER_w_structure("ED25519", der, SubjectPublicKeyInfo, ed25519, yes),
64DECODER_w_structure("ED448", der, PrivateKeyInfo, ed448, yes),
65DECODER_w_structure("ED448", der, SubjectPublicKeyInfo, ed448, yes),
66DECODER_w_structure("X25519", der, PrivateKeyInfo, x25519, yes),
67DECODER_w_structure("X25519", der, SubjectPublicKeyInfo, x25519, yes),
68DECODER_w_structure("X448", der, PrivateKeyInfo, x448, yes),
69DECODER_w_structure("X448", der, SubjectPublicKeyInfo, x448, yes),
70# endif
71# ifndef OPENSSL_NO_SM2
72DECODER_w_structure("SM2", der, PrivateKeyInfo, sm2, no),
73DECODER_w_structure("SM2", der, SubjectPublicKeyInfo, sm2, no),
74DECODER_w_structure("SM2", der, type_specific_no_pub, sm2, no),
75# endif
76#endif
77#ifndef OPENSSL_NO_ML_KEM
78DECODER_w_structure("ML-KEM-512", der, PrivateKeyInfo, ml_kem_512, yes),
79DECODER_w_structure("ML-KEM-512", der, SubjectPublicKeyInfo, ml_kem_512, yes),
80DECODER_w_structure("ML-KEM-768", der, PrivateKeyInfo, ml_kem_768, yes),
81DECODER_w_structure("ML-KEM-768", der, SubjectPublicKeyInfo, ml_kem_768, yes),
82DECODER_w_structure("ML-KEM-1024", der, PrivateKeyInfo, ml_kem_1024, yes),
83DECODER_w_structure("ML-KEM-1024", der, SubjectPublicKeyInfo, ml_kem_1024, yes),
84#endif
85#ifndef OPENSSL_NO_SLH_DSA
86DECODER_w_structure( "SLH-DSA-SHA2-128s", der, PrivateKeyInfo, slh_dsa_sha2_128s, yes),
87DECODER_w_structure( "SLH-DSA-SHA2-128f", der, PrivateKeyInfo, slh_dsa_sha2_128f, yes),
88DECODER_w_structure( "SLH-DSA-SHA2-192s", der, PrivateKeyInfo, slh_dsa_sha2_192s, yes),
89DECODER_w_structure( "SLH-DSA-SHA2-192f", der, PrivateKeyInfo, slh_dsa_sha2_192f, yes),
90DECODER_w_structure( "SLH-DSA-SHA2-256s", der, PrivateKeyInfo, slh_dsa_sha2_256s, yes),
91DECODER_w_structure( "SLH-DSA-SHA2-256f", der, PrivateKeyInfo, slh_dsa_sha2_256f, yes),
92DECODER_w_structure("SLH-DSA-SHAKE-128s", der, PrivateKeyInfo, slh_dsa_shake_128s, yes),
93DECODER_w_structure("SLH-DSA-SHAKE-128f", der, PrivateKeyInfo, slh_dsa_shake_128f, yes),
94DECODER_w_structure("SLH-DSA-SHAKE-192s", der, PrivateKeyInfo, slh_dsa_shake_192s, yes),
95DECODER_w_structure("SLH-DSA-SHAKE-192f", der, PrivateKeyInfo, slh_dsa_shake_192f, yes),
96DECODER_w_structure("SLH-DSA-SHAKE-256s", der, PrivateKeyInfo, slh_dsa_shake_256s, yes),
97DECODER_w_structure("SLH-DSA-SHAKE-256f", der, PrivateKeyInfo, slh_dsa_shake_256f, yes),
98DECODER_w_structure( "SLH-DSA-SHA2-128s", der, SubjectPublicKeyInfo, slh_dsa_sha2_128s, yes),
99DECODER_w_structure( "SLH-DSA-SHA2-128f", der, SubjectPublicKeyInfo, slh_dsa_sha2_128f, yes),
100DECODER_w_structure( "SLH-DSA-SHA2-192s", der, SubjectPublicKeyInfo, slh_dsa_sha2_192s, yes),
101DECODER_w_structure( "SLH-DSA-SHA2-192f", der, SubjectPublicKeyInfo, slh_dsa_sha2_192f, yes),
102DECODER_w_structure( "SLH-DSA-SHA2-256s", der, SubjectPublicKeyInfo, slh_dsa_sha2_256s, yes),
103DECODER_w_structure( "SLH-DSA-SHA2-256f", der, SubjectPublicKeyInfo, slh_dsa_sha2_256f, yes),
104DECODER_w_structure("SLH-DSA-SHAKE-128s", der, SubjectPublicKeyInfo, slh_dsa_shake_128s, yes),
105DECODER_w_structure("SLH-DSA-SHAKE-128f", der, SubjectPublicKeyInfo, slh_dsa_shake_128f, yes),
106DECODER_w_structure("SLH-DSA-SHAKE-192s", der, SubjectPublicKeyInfo, slh_dsa_shake_192s, yes),
107DECODER_w_structure("SLH-DSA-SHAKE-192f", der, SubjectPublicKeyInfo, slh_dsa_shake_192f, yes),
108DECODER_w_structure("SLH-DSA-SHAKE-256s", der, SubjectPublicKeyInfo, slh_dsa_shake_256s, yes),
109DECODER_w_structure("SLH-DSA-SHAKE-256f", der, SubjectPublicKeyInfo, slh_dsa_shake_256f, yes),
110#endif /* OPENSSL_NO_SLH_DSA */
111DECODER_w_structure("RSA", der, PrivateKeyInfo, rsa, yes),
112DECODER_w_structure("RSA", der, SubjectPublicKeyInfo, rsa, yes),
113DECODER_w_structure("RSA", der, type_specific_keypair, rsa, yes),
114DECODER_w_structure("RSA", der, RSA, rsa, yes),
115DECODER_w_structure("RSA-PSS", der, PrivateKeyInfo, rsapss, yes),
116DECODER_w_structure("RSA-PSS", der, SubjectPublicKeyInfo, rsapss, yes),
117DECODER("RSA", msblob, rsa, yes),
118DECODER("RSA", pvk, rsa, yes),
119#ifndef OPENSSL_NO_ML_DSA
120DECODER_w_structure("ML-DSA-44", der, PrivateKeyInfo, ml_dsa_44, yes),
121DECODER_w_structure("ML-DSA-65", der, PrivateKeyInfo, ml_dsa_65, yes),
122DECODER_w_structure("ML-DSA-87", der, PrivateKeyInfo, ml_dsa_87, yes),
123DECODER_w_structure("ML-DSA-44", der, SubjectPublicKeyInfo, ml_dsa_44, yes),
124DECODER_w_structure("ML-DSA-65", der, SubjectPublicKeyInfo, ml_dsa_65, yes),
125DECODER_w_structure("ML-DSA-87", der, SubjectPublicKeyInfo, ml_dsa_87, yes),
126#endif /* OPENSSL_NO_ML_DSA */
127
128/*
129 * A decoder that takes a SubjectPublicKeyInfo and figures out the types of key
130 * that it contains. The output is the same SubjectPublicKeyInfo.
131 */
132DECODER_w_structure("DER", der, SubjectPublicKeyInfo, der, yes),
133/*
134 * General-purpose PEM to DER decoder.  When the user-specified data structure
135 * is a possibly encrypted PKCS#8 PrivateKeyInfo or a SubjectPublicKeyInfo
136 * public key, or interest in such a key is indicated via the "selection", and
137 * the current object is of that type, decodes the PKCS#8 or SPKI identifying
138 * algorithm name or OID, and delegates further decoding in DER form to the
139 * identified algorithm.
140 */
141DECODER("DER", pem, der, yes),
142/*
143 * A decoder that recognises PKCS#8 EncryptedPrivateKeyInfo structure and
144 * decrypts it, obtaining the algorithm name or OID, and delegates the
145 * unencrypted PrivateKeyInfo in DER form to the identified algorithm.
146 */
147DECODER_w_structure("DER", der, EncryptedPrivateKeyInfo, der, yes),
148