EVP_KDF-X942-ASN1.pod 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. =pod
  2. =head1 NAME
  3. EVP_KDF-X942-ASN1 - The X9.42-2003 asn1 EVP_KDF implementation
  4. =head1 DESCRIPTION
  5. The EVP_KDF-X942-ASN1 algorithm implements the key derivation function
  6. X942KDF-ASN1. It is used by DH KeyAgreement, to derive a key using input such as
  7. a shared secret key and other info. The other info is DER encoded data that
  8. contains a 32 bit counter as well as optional fields for "partyu-info",
  9. "partyv-info", "supp-pubinfo" and "supp-privinfo".
  10. This kdf is used by Cryptographic Message Syntax (CMS).
  11. The output is considered to be keying material.
  12. =head2 Identity
  13. "X942KDF-ASN1" or "X942KDF" is the name for this implementation; it
  14. can be used with the EVP_KDF_fetch() function.
  15. =head2 Supported parameters
  16. The supported parameters are:
  17. =over 4
  18. =item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
  19. =item "digest" (B<OSSL_KDF_PARAM_DIGEST>) <UTF8 string>
  20. These parameters work as described in L<EVP_KDF(3)/PARAMETERS>.
  21. =item "secret" (B<OSSL_KDF_PARAM_SECRET>) <octet string>
  22. The shared secret used for key derivation. This parameter sets the secret.
  23. =item "acvp-info" (B<OSSL_KDF_PARAM_X942_ACVPINFO>) <octet string>
  24. This value should not be used in production and should only be used for ACVP
  25. testing. It is an optional octet string containing a combined DER encoded blob
  26. of any of the optional fields related to "partyu-info", "partyv-info",
  27. "supp-pubinfo" and "supp-privinfo". If it is specified then none of these other
  28. fields should be used.
  29. =item "partyu-info" (B<OSSL_KDF_PARAM_X942_PARTYUINFO>) <octet string>
  30. An optional octet string containing public info contributed by the initiator.
  31. =item "ukm" (B<OSSL_KDF_PARAM_UKM>) <octet string>
  32. An alias for "partyu-info".
  33. In CMS this is the user keying material.
  34. =item "partyv-info" (B<OSSL_KDF_PARAM_X942_PARTYVINFO>) <octet string>
  35. An optional octet string containing public info contributed by the responder.
  36. =item "supp-pubinfo" (B<OSSL_KDF_PARAM_X942_SUPP_PUBINFO>) <octet string>
  37. An optional octet string containing some additional, mutually-known public
  38. information. Setting this value also sets "use-keybits" to 0.
  39. =item "use-keybits" (B<OSSL_KDF_PARAM_X942_USE_KEYBITS>) <integer>
  40. The default value of 1 will use the KEK key length (in bits) as the
  41. "supp-pubinfo". A value of 0 disables setting the "supp-pubinfo".
  42. =item "supp-privinfo" (B<OSSL_KDF_PARAM_X942_SUPP_PRIVINFO>) <octet string>
  43. An optional octet string containing some additional, mutually-known private
  44. information.
  45. =item "cekalg" (B<OSSL_KDF_PARAM_CEK_ALG>) <UTF8 string>
  46. This parameter sets the CEK wrapping algorithm name.
  47. Valid values are "AES-128-WRAP", "AES-192-WRAP", "AES-256-WRAP" and "DES3-WRAP".
  48. =back
  49. =head1 NOTES
  50. A context for X942KDF can be obtained by calling:
  51. EVP_KDF *kdf = EVP_KDF_fetch(NULL, "X942KDF", NULL);
  52. EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
  53. The output length of an X942KDF is specified via the I<keylen>
  54. parameter to the L<EVP_KDF_derive(3)> function.
  55. =head1 EXAMPLES
  56. This example derives 24 bytes, with the secret key "secret" and random user
  57. keying material:
  58. EVP_KDF_CTX *kctx;
  59. EVP_KDF_CTX *kctx;
  60. unsigned char out[192/8];
  61. unsignred char ukm[64];
  62. OSSL_PARAM params[5], *p = params;
  63. if (RAND_bytes(ukm, sizeof(ukm)) <= 0)
  64. error("RAND_bytes");
  65. kdf = EVP_KDF_fetch(NULL, "X942KDF", NULL);
  66. if (kctx == NULL)
  67. error("EVP_KDF_fetch");
  68. kctx = EVP_KDF_CTX_new(kdf);
  69. EVP_KDF_free(kdf);
  70. if (kctx == NULL)
  71. error("EVP_KDF_CTX_new");
  72. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", 0);
  73. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
  74. "secret", (size_t)6);
  75. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_UKM, ukm, sizeof(ukm));
  76. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CEK_ALG, "AES-256-WRAP, 0);
  77. *p = OSSL_PARAM_construct_end();
  78. if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0)
  79. error("EVP_KDF_derive");
  80. EVP_KDF_CTX_free(kctx);
  81. =head1 CONFORMING TO
  82. ANS1 X9.42-2003
  83. RFC 2631
  84. =head1 SEE ALSO
  85. L<EVP_KDF(3)>,
  86. L<EVP_KDF_CTX_new(3)>,
  87. L<EVP_KDF_CTX_free(3)>,
  88. L<EVP_KDF_CTX_set_params(3)>,
  89. L<EVP_KDF_CTX_get_kdf_size(3)>,
  90. L<EVP_KDF_derive(3)>,
  91. L<EVP_KDF(3)/PARAMETERS>
  92. =head1 HISTORY
  93. This functionality was added in OpenSSL 3.0.
  94. =head1 COPYRIGHT
  95. Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  96. Licensed under the Apache License 2.0 (the "License"). You may not use
  97. this file except in compliance with the License. You can obtain a copy
  98. in the file LICENSE in the source distribution or at
  99. L<https://www.openssl.org/source/license.html>.
  100. =cut