EVP_KDF-X942-ASN1.pod 4.5 KB

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