5 EVP_KDF-X942-ASN1 - The X9.42-2003 asn1 EVP_KDF implementation
9 The EVP_KDF-X942-ASN1 algorithm implements the key derivation function
10 X942KDF-ASN1. It is used by DH KeyAgreement, to derive a key using input such as
11 a shared secret key and other info. The other info is DER encoded data that
12 contains a 32 bit counter as well as optional fields for "partyu-info",
13 "partyv-info", "supp-pubinfo" and "supp-privinfo".
14 This kdf is used by Cryptographic Message Syntax (CMS).
18 "X942KDF-ASN1" or "X942KDF" is the name for this implementation; it
19 can be used with the EVP_KDF_fetch() function.
21 =head2 Supported parameters
23 The supported parameters are:
27 =item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
29 =item "digest" (B<OSSL_KDF_PARAM_DIGEST>) <UTF8 string>
31 These parameters work as described in L<EVP_KDF(3)/PARAMETERS>.
33 =item "key" (B<OSSL_KDF_PARAM_KEY>) <octet string>
35 The shared secret used for key derivation. This parameter sets the secret.
37 =item "partyu-info" (B<OSSL_KDF_PARAM_X942_PARTYUINFO>) <octet string>
39 An optional octet string containing public info contributed by the initiator.
41 =item "ukm" (B<OSSL_KDF_PARAM_UKM>) <octet string>
43 An alias for "partyu-info".
44 In CMS this is the user keying material.
46 =item "partyv-info" (B<OSSL_KDF_PARAM_X942_PARTYVINFO>) <octet string>
48 An optional octet string containing public info contributed by the responder.
50 =item "supp-pubinfo" (B<OSSL_KDF_PARAM_X942_SUPP_PUBINFO>) <octet string>
52 An optional octet string containing some additional, mutually-known public
53 information. Setting this value also sets "use-keybits" to 0.
55 =item "use-keybits" (B<OSSL_KDF_PARAM_X942_SUPP_PRIVINFO>) <integer>
57 The default value of 1 will use the KEK key length (in bits) as the
58 "supp-pubinfo". A value of 0 disables setting the "supp-pubinfo".
60 =item "supp-privinfo" (B<OSSL_KDF_PARAM_X942_SUPP_PRIVINFO>) <octet string>
62 An optional octet string containing some additional, mutually-known private
65 =item "cekalg" (B<OSSL_KDF_PARAM_CEK_ALG>) <UTF8 string>
67 This parameter sets the CEK wrapping algorithm name.
68 Valid values are "AES-128-WRAP", "AES-192-WRAP", "AES-256-WRAP" and "DES3-WRAP".
74 A context for X942KDF can be obtained by calling:
76 EVP_KDF *kdf = EVP_KDF_fetch(NULL, "X942KDF", NULL);
77 EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
79 The output length of an X942KDF is specified via the I<keylen>
80 parameter to the L<EVP_KDF_derive(3)> function.
84 This example derives 24 bytes, with the secret key "secret" and random user
89 unsigned char out[192/8];
90 unsignred char ukm[64];
91 OSSL_PARAM params[5], *p = params;
93 if (RAND_bytes(ukm, sizeof(ukm)) <= 0)
96 kdf = EVP_KDF_fetch(NULL, "X942KDF", NULL);
98 error("EVP_KDF_fetch");
99 kctx = EVP_KDF_CTX_new(kdf);
102 error("EVP_KDF_CTX_new");
104 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
105 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
106 "secret", (size_t)6);
107 *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_UKM, ukm, sizeof(ukm));
108 *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CEK_ALG, "AES-256-WRAP, 0);
109 *p = OSSL_PARAM_construct_end();
110 if (EVP_KDF_CTX_set_params(kctx, params) <= 0)
111 error("EVP_KDF_CTX_set_params");
113 if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0)
114 error("EVP_KDF_derive");
116 EVP_KDF_CTX_free(kctx);
126 L<EVP_KDF_CTX_new(3)>,
127 L<EVP_KDF_CTX_free(3)>,
128 L<EVP_KDF_CTX_set_params(3)>,
129 L<EVP_KDF_CTX_get_kdf_size(3)>,
130 L<EVP_KDF_derive(3)>,
131 L<EVP_KDF(3)/PARAMETERS>
135 This functionality was added to OpenSSL 3.0.
139 Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
141 Licensed under the Apache License 2.0 (the "License"). You may not use
142 this file except in compliance with the License. You can obtain a copy
143 in the file LICENSE in the source distribution or at
144 L<https://www.openssl.org/source/license.html>.