1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci#ifndef DECODER_PROVIDER
11e1051a39Sopenharmony_ci# error Macro DECODER_PROVIDER undefined
12e1051a39Sopenharmony_ci#endif
13e1051a39Sopenharmony_ci
14e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_type_specific_keypair         "type-specific"
15e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_type_specific_params          "type-specific"
16e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_type_specific                 "type-specific"
17e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_type_specific_no_pub          "type-specific"
18e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_EncryptedPrivateKeyInfo       "EncryptedPrivateKeyInfo"
19e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_PrivateKeyInfo                "PrivateKeyInfo"
20e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_SubjectPublicKeyInfo          "SubjectPublicKeyInfo"
21e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_DH                            "dh"
22e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_DHX                           "dhx"
23e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_DSA                           "dsa"
24e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_EC                            "ec"
25e1051a39Sopenharmony_ci#define DECODER_STRUCTURE_RSA                           "rsa"
26e1051a39Sopenharmony_ci
27e1051a39Sopenharmony_ci/* Arguments are prefixed with '_' to avoid build breaks on certain platforms */
28e1051a39Sopenharmony_ci#define DECODER(_name, _input, _output, _fips)                          \
29e1051a39Sopenharmony_ci    { _name,                                                            \
30e1051a39Sopenharmony_ci      "provider=" DECODER_PROVIDER ",fips=" #_fips ",input=" #_input,   \
31e1051a39Sopenharmony_ci      (ossl_##_input##_to_##_output##_decoder_functions) }
32e1051a39Sopenharmony_ci#define DECODER_w_structure(_name, _input, _structure, _output, _fips)  \
33e1051a39Sopenharmony_ci    { _name,                                                            \
34e1051a39Sopenharmony_ci      "provider=" DECODER_PROVIDER ",fips=" #_fips ",input=" #_input    \
35e1051a39Sopenharmony_ci      ",structure=" DECODER_STRUCTURE_##_structure,                     \
36e1051a39Sopenharmony_ci      (ossl_##_structure##_##_input##_to_##_output##_decoder_functions) }
37e1051a39Sopenharmony_ci
38e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DH
39e1051a39Sopenharmony_ciDECODER_w_structure("DH", der, PrivateKeyInfo, dh, yes),
40e1051a39Sopenharmony_ciDECODER_w_structure("DH", der, SubjectPublicKeyInfo, dh, yes),
41e1051a39Sopenharmony_ciDECODER_w_structure("DH", der, type_specific_params, dh, yes),
42e1051a39Sopenharmony_ciDECODER_w_structure("DH", der, DH, dh, yes),
43e1051a39Sopenharmony_ciDECODER_w_structure("DHX", der, PrivateKeyInfo, dhx, yes),
44e1051a39Sopenharmony_ciDECODER_w_structure("DHX", der, SubjectPublicKeyInfo, dhx, yes),
45e1051a39Sopenharmony_ciDECODER_w_structure("DHX", der, type_specific_params, dhx, yes),
46e1051a39Sopenharmony_ciDECODER_w_structure("DHX", der, DHX, dhx, yes),
47e1051a39Sopenharmony_ci#endif
48e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DSA
49e1051a39Sopenharmony_ciDECODER_w_structure("DSA", der, PrivateKeyInfo, dsa, yes),
50e1051a39Sopenharmony_ciDECODER_w_structure("DSA", der, SubjectPublicKeyInfo, dsa, yes),
51e1051a39Sopenharmony_ciDECODER_w_structure("DSA", der, type_specific, dsa, yes),
52e1051a39Sopenharmony_ciDECODER_w_structure("DSA", der, DSA, dsa, yes),
53e1051a39Sopenharmony_ciDECODER("DSA", msblob, dsa, yes),
54e1051a39Sopenharmony_ciDECODER("DSA", pvk, dsa, yes),
55e1051a39Sopenharmony_ci#endif
56e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_EC
57e1051a39Sopenharmony_ciDECODER_w_structure("EC", der, PrivateKeyInfo, ec, yes),
58e1051a39Sopenharmony_ciDECODER_w_structure("EC", der, SubjectPublicKeyInfo, ec, yes),
59e1051a39Sopenharmony_ciDECODER_w_structure("EC", der, type_specific_no_pub, ec, yes),
60e1051a39Sopenharmony_ciDECODER_w_structure("EC", der, EC, ec, yes),
61e1051a39Sopenharmony_ciDECODER_w_structure("ED25519", der, PrivateKeyInfo, ed25519, yes),
62e1051a39Sopenharmony_ciDECODER_w_structure("ED25519", der, SubjectPublicKeyInfo, ed25519, yes),
63e1051a39Sopenharmony_ciDECODER_w_structure("ED448", der, PrivateKeyInfo, ed448, yes),
64e1051a39Sopenharmony_ciDECODER_w_structure("ED448", der, SubjectPublicKeyInfo, ed448, yes),
65e1051a39Sopenharmony_ciDECODER_w_structure("X25519", der, PrivateKeyInfo, x25519, yes),
66e1051a39Sopenharmony_ciDECODER_w_structure("X25519", der, SubjectPublicKeyInfo, x25519, yes),
67e1051a39Sopenharmony_ciDECODER_w_structure("X448", der, PrivateKeyInfo, x448, yes),
68e1051a39Sopenharmony_ciDECODER_w_structure("X448", der, SubjectPublicKeyInfo, x448, yes),
69e1051a39Sopenharmony_ci# ifndef OPENSSL_NO_SM2
70e1051a39Sopenharmony_ciDECODER_w_structure("SM2", der, PrivateKeyInfo, sm2, no),
71e1051a39Sopenharmony_ciDECODER_w_structure("SM2", der, SubjectPublicKeyInfo, sm2, no),
72e1051a39Sopenharmony_ci# endif
73e1051a39Sopenharmony_ci#endif
74e1051a39Sopenharmony_ciDECODER_w_structure("RSA", der, PrivateKeyInfo, rsa, yes),
75e1051a39Sopenharmony_ciDECODER_w_structure("RSA", der, SubjectPublicKeyInfo, rsa, yes),
76e1051a39Sopenharmony_ciDECODER_w_structure("RSA", der, type_specific_keypair, rsa, yes),
77e1051a39Sopenharmony_ciDECODER_w_structure("RSA", der, RSA, rsa, yes),
78e1051a39Sopenharmony_ciDECODER_w_structure("RSA-PSS", der, PrivateKeyInfo, rsapss, yes),
79e1051a39Sopenharmony_ciDECODER_w_structure("RSA-PSS", der, SubjectPublicKeyInfo, rsapss, yes),
80e1051a39Sopenharmony_ciDECODER("RSA", msblob, rsa, yes),
81e1051a39Sopenharmony_ciDECODER("RSA", pvk, rsa, yes),
82e1051a39Sopenharmony_ci
83e1051a39Sopenharmony_ci/*
84e1051a39Sopenharmony_ci * A decoder that takes a SubjectPublicKeyInfo and figures out the types of key
85e1051a39Sopenharmony_ci * that it contains. The output is the same SubjectPublicKeyInfo
86e1051a39Sopenharmony_ci */
87e1051a39Sopenharmony_ciDECODER_w_structure("DER", der, SubjectPublicKeyInfo, der, yes),
88e1051a39Sopenharmony_ciDECODER("DER", pem, der, yes),
89e1051a39Sopenharmony_ci/*
90e1051a39Sopenharmony_ci * A decoder that recognises PKCS#8 EncryptedPrivateKeyInfo structure
91e1051a39Sopenharmony_ci * and decrypts it, passing on the unencrypted PrivateKeyInfo in DER
92e1051a39Sopenharmony_ci * form to the next decoder.
93e1051a39Sopenharmony_ci */
94e1051a39Sopenharmony_ciDECODER_w_structure("DER", der, EncryptedPrivateKeyInfo, der, yes),
95