1 | Passing AlgorithmIdentifier parameters to operations
|
---|
2 | ====================================================
|
---|
3 |
|
---|
4 | Quick background
|
---|
5 | ----------------
|
---|
6 |
|
---|
7 | We currently only support passing the AlgorithmIdentifier (`X509_ALGOR`)
|
---|
8 | parameter field to symmetric cipher provider implementations.
|
---|
9 |
|
---|
10 | We do support passing them to legacy implementations of other types of
|
---|
11 | operation algorithms as well, but it's done in a way that can't be supported
|
---|
12 | with providers, because it involves sharing specific structures between
|
---|
13 | libcrypto and the backend implementation.
|
---|
14 |
|
---|
15 | For a longer background and explanation, see
|
---|
16 | [Background / tl;dr](#background-tldr) at the end of this design.
|
---|
17 |
|
---|
18 | Establish an OSSL_PARAM key that any algorithms may become aware of
|
---|
19 | -------------------------------------------------------------------
|
---|
20 |
|
---|
21 | We already have a parameter key, but it's currently only specified for
|
---|
22 | `EVP_CIPHER`, in support of `EVP_CIPHER_param_to_asn1()` and
|
---|
23 | `EVP_CIPHER_asn1_to_param()`.
|
---|
24 |
|
---|
25 | "alg_id_param", also known as the macro `OSSL_CIPHER_PARAM_ALGORITHM_ID_PARAMS`
|
---|
26 |
|
---|
27 | This parameter can be used in the exact same manner with other operations,
|
---|
28 | with the value of the AlgorithmIdentifier parameter as an octet string, to
|
---|
29 | be interpreted by the implementations in whatever way they see fit.
|
---|
30 |
|
---|
31 | Applications can choose to add these in an `OSSL_PARAM` array, to be passed
|
---|
32 | with the multitude of initialization functions that take such an array, or
|
---|
33 | using specific operation `OSSL_PARAM` setters and getters (such as
|
---|
34 | `EVP_PKEY_CTX_set_params`), or using other available convenience functions
|
---|
35 | (see below).
|
---|
36 |
|
---|
37 | This parameter will have to be documented in the following files:
|
---|
38 |
|
---|
39 | - `doc/man7/provider-asym_cipher.pod`
|
---|
40 | - `doc/man7/provider-cipher.pod`
|
---|
41 | - `doc/man7/provider-digest.pod`
|
---|
42 | - `doc/man7/provider-kdf.pod`
|
---|
43 | - `doc/man7/provider-kem.pod`
|
---|
44 | - `doc/man7/provider-keyexch.pod`
|
---|
45 | - `doc/man7/provider-mac.pod`
|
---|
46 | - `doc/man7/provider-signature.pod`
|
---|
47 |
|
---|
48 | That should cover all algorithms that are, or should be possible to fetch by
|
---|
49 | AlgorithmIdentifier.algorithm, and for which there's potentially a relevant
|
---|
50 | AlgorithmIdentifier.parameters field.
|
---|
51 |
|
---|
52 | We may arguably want to consider `doc/man7/provider-keymgmt.pod` too, but
|
---|
53 | an AlgorithmIdentifier that's attached directly to a key is usually part of
|
---|
54 | a PrivKeyInfo or SubjectPublicKeyInfo structure, and those are handled by
|
---|
55 | encoders and decoders as those see fit, and there's no tangible reason why
|
---|
56 | that would have to change.
|
---|
57 |
|
---|
58 | Public convenience API
|
---|
59 | ----------------------
|
---|
60 |
|
---|
61 | For convenience, the following set of functions would be added to pass the
|
---|
62 | AlgorithmIdentifier parameter data to diverse operations, or to retrieve
|
---|
63 | such parameter data from them.
|
---|
64 |
|
---|
65 | ``` C
|
---|
66 | /*
|
---|
67 | * These two would essentially be aliases for EVP_CIPHER_param_to_asn1()
|
---|
68 | * and EVP_CIPHER_asn1_to_param().
|
---|
69 | */
|
---|
70 | EVP_CIPHER_CTX_set_algor_param(EVP_PKEY_CTX *ctx, X509_ALGOR *alg);
|
---|
71 | EVP_CIPHER_CTX_get_algor_param(EVP_PKEY_CTX *ctx, X509_ALGOR *alg);
|
---|
72 |
|
---|
73 | EVP_MD_CTX_set_algor_param(EVP_PKEY_CTX *ctx, X509_ALGOR *alg);
|
---|
74 | EVP_MD_CTX_get_algor_param(EVP_PKEY_CTX *ctx, X509_ALGOR *alg);
|
---|
75 |
|
---|
76 | EVP_MAC_CTX_set_algor_param(EVP_PKEY_CTX *ctx, X509_ALGOR *alg);
|
---|
77 | EVP_MAC_CTX_get_algor_param(EVP_PKEY_CTX *ctx, X509_ALGOR *alg);
|
---|
78 |
|
---|
79 | EVP_KDF_CTX_set_algor_param(EVP_PKEY_CTX *ctx, X509_ALGOR *alg);
|
---|
80 | EVP_KDF_CTX_get_algor_param(EVP_PKEY_CTX *ctx, X509_ALGOR *alg);
|
---|
81 |
|
---|
82 | EVP_PKEY_CTX_set_algor_param(EVP_PKEY_CTX *ctx, X509_ALGOR *alg);
|
---|
83 | EVP_PKEY_CTX_get_algor_param(EVP_PKEY_CTX *ctx, X509_ALGOR *alg);
|
---|
84 | ```
|
---|
85 |
|
---|
86 | Note that all might not need to be added immediately, depending on if they
|
---|
87 | are considered useful or not. For future proofing, however, they should
|
---|
88 | probably all be added.
|
---|
89 |
|
---|
90 | Requirements on the providers
|
---|
91 | -----------------------------
|
---|
92 |
|
---|
93 | Providers that implement ciphers or any operation that uses asymmetric keys
|
---|
94 | will have to implement support for passing AlgorithmIdentifier parameter
|
---|
95 | data, and will have to process that data in whatever manner that's necessary
|
---|
96 | to meet the standards for that operation.
|
---|
97 |
|
---|
98 | Fallback strategies
|
---|
99 | -------------------
|
---|
100 |
|
---|
101 | There are no possible fallback strategies, which is fine, considering that
|
---|
102 | current provider functionality doesn't support passing AlgorithmIdentifier
|
---|
103 | parameter data at all (except for `EVP_CIPHER`), and therefore do not work
|
---|
104 | at all when such parameter data needs to be passed.
|
---|
105 |
|
---|
106 | -----
|
---|
107 |
|
---|
108 | -----
|
---|
109 |
|
---|
110 | Background / tl;dr
|
---|
111 | ------------------
|
---|
112 |
|
---|
113 | ### AlgorithmIdenfier parameter and how it's used
|
---|
114 |
|
---|
115 | OpenSSL has historically done a few tricks to not have to pass
|
---|
116 | AlgorithmIdenfier parameter data to the backend implementations of
|
---|
117 | cryptographic operations:
|
---|
118 |
|
---|
119 | - In some cases, they were passed as part of the lower level key structure
|
---|
120 | (for example, the `RSA` structure can also carry RSA-PSS parameters).
|
---|
121 | - In the `EVP_CIPHER` case, there is functionality to pass the parameter
|
---|
122 | data specifically.
|
---|
123 | - For asymmetric key operations, PKCS#7 and CMS support was added as
|
---|
124 | `EVP_PKEY` ctrls.
|
---|
125 |
|
---|
126 | With providers, some of that support was retained, but not others. Most
|
---|
127 | crucially, the `EVP_PKEY` ctrls for PKCS#7 and CMS were not retained,
|
---|
128 | because the way they were implemented violated the principle that provider
|
---|
129 | implementations *MUST NOT* share complex OpenSSL specific structures with
|
---|
130 | libcrypto.
|
---|
131 |
|
---|
132 | ### Usage examples
|
---|
133 |
|
---|
134 | Quite a lot of the available examples today revolve around CMS, with a
|
---|
135 | number of RFCs that specify what parameters should be passed with certain
|
---|
136 | operations / algorithms. This list is not exhaustive, the reader is
|
---|
137 | encouraged to research further usages.
|
---|
138 |
|
---|
139 | - [DSA](https://www.rfc-editor.org/rfc/rfc3370#section-3.1) signatures
|
---|
140 | typically have the domain parameters *p*, *q* and *g*.
|
---|
141 | - [RC2 key wrap](https://www.rfc-editor.org/rfc/rfc3370#section-4.3.2)
|
---|
142 | - [PBKDF2](https://www.rfc-editor.org/rfc/rfc3370#section-4.4.1)
|
---|
143 | - [3DES-CBC](https://www.rfc-editor.org/rfc/rfc3370#section-5.1)
|
---|
144 | - [RC2-CBC](https://www.rfc-editor.org/rfc/rfc3370#section-5.2)
|
---|
145 |
|
---|
146 | - [GOST 28147-89](https://www.rfc-editor.org/rfc/rfc4490.html#section-5.1)
|
---|
147 |
|
---|
148 | - [RSA-OAEP](https://www.rfc-editor.org/rfc/rfc8017#appendix-A.2.1)
|
---|
149 | - [RSA-PSS](https://www.rfc-editor.org/rfc/rfc8017#appendix-A.2.3)
|
---|
150 |
|
---|
151 | - [XOR-MD5](https://www.rfc-editor.org/rfc/rfc6210.html) is experimental,
|
---|
152 | but it does demonstrate the possibility of a parametrized hash algorithm.
|
---|
153 |
|
---|
154 | Some of it can be claimed to already have support in OpenSSL. However, this
|
---|
155 | is with old libcrypto code that has special knowledge of the algorithms that
|
---|
156 | are involved.
|
---|