EVP_KDF-X942-ASN1.pod 4.2 KB

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