EVP_KDF-X942.pod 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. =pod
  2. =head1 NAME
  3. EVP_KDF-X942 - The X9.42-2001 asn1 EVP_KDF implementation
  4. =head1 DESCRIPTION
  5. The EVP_KDF-X942 algorithm implements the key derivation function (X942KDF).
  6. X942KDF is used by Cryptographic Message Syntax (CMS) for DH KeyAgreement, to
  7. derive a key using input such as a shared secret key and other info. The other
  8. info is DER encoded data that contains a 32 bit counter.
  9. =head2 Identity
  10. "X942KDF" is the name for this implementation; it
  11. can be used with the EVP_KDF_fetch() function.
  12. =head2 Supported parameters
  13. The supported parameters are:
  14. =over 4
  15. =item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
  16. =item "digest" (B<OSSL_KDF_PARAM_DIGEST>) <UTF8 string>
  17. These parameters work as described in L<EVP_KDF(3)/PARAMETERS>.
  18. =item "key" (B<OSSL_KDF_PARAM_KEY>) <octet string>
  19. The shared secret used for key derivation. This parameter sets the secret.
  20. =item "ukm" (B<OSSL_KDF_PARAM_UKM>) <octet string>
  21. This parameter is an optional random string that is provided
  22. by the sender called "partyAInfo".
  23. In CMS this is the user keying material.
  24. =item "cekalg" (B<OSSL_KDF_PARAM_CEK_ALG>) <UTF8 string>
  25. This parameter sets the CEK wrapping algorithm name.
  26. =back
  27. =head1 NOTES
  28. A context for X942KDF can be obtained by calling:
  29. EVP_KDF *kdf = EVP_KDF_fetch(NULL, "X942KDF", NULL);
  30. EVP_KDF_CTX *kctx = EVP_KDF_new_ctx(kdf);
  31. The output length of an X942KDF is specified via the I<keylen>
  32. parameter to the L<EVP_KDF_derive(3)> function.
  33. =head1 EXAMPLES
  34. This example derives 24 bytes, with the secret key "secret" and a random user
  35. keying material:
  36. EVP_KDF_CTX *kctx;
  37. EVP_KDF_CTX *kctx;
  38. unsigned char out[192/8];
  39. unsignred char ukm[64];
  40. OSSL_PARAM params[5], *p = params;
  41. if (RAND_bytes(ukm, sizeof(ukm)) <= 0)
  42. error("RAND_bytes");
  43. kdf = EVP_KDF_fetch(NULL, "X942KDF", NULL);
  44. if (kctx == NULL)
  45. error("EVP_KDF_fetch");
  46. kctx = EVP_KDF_new_ctx(kdf);
  47. if (kctx == NULL)
  48. error("EVP_KDF_new_ctx");
  49. EVP_KDF_free(kdf);
  50. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
  51. SN_sha256, strlen(SN_sha256));
  52. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
  53. "secret", (size_t)6);
  54. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_UKM, ukm, sizeof(ukm));
  55. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CEK_ALG,
  56. SN_id_smime_alg_CMS3DESwrap,
  57. strlen(SN_id_smime_alg_CMS3DESwrap));
  58. *p = OSSL_PARAM_construct_end();
  59. if (EVP_KDF_set_ctx_params(kctx, params) <= 0)
  60. error("EVP_KDF_set_ctx_params");
  61. if (EVP_KDF_derive(kctx, out, sizeof(out)) <= 0)
  62. error("EVP_KDF_derive");
  63. EVP_KDF_free_ctx(kctx);
  64. =head1 CONFORMING TO
  65. RFC 2631
  66. =head1 SEE ALSO
  67. L<EVP_KDF(3)>,
  68. L<EVP_KDF_new_ctx(3)>,
  69. L<EVP_KDF_free_ctx(3)>,
  70. L<EVP_KDF_set_ctx_params(3)>,
  71. L<EVP_KDF_size(3)>,
  72. L<EVP_KDF_derive(3)>,
  73. L<EVP_KDF(3)/PARAMETERS>
  74. =head1 HISTORY
  75. This functionality was added to OpenSSL 3.0.
  76. =head1 COPYRIGHT
  77. Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  78. Licensed under the Apache License 2.0 (the "License"). You may not use
  79. this file except in compliance with the License. You can obtain a copy
  80. in the file LICENSE in the source distribution or at
  81. L<https://www.openssl.org/source/license.html>.
  82. =cut