EVP_KDF-KB.pod 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. =pod
  2. =head1 NAME
  3. EVP_KDF-KB - The Key-Based EVP_KDF implementation
  4. =head1 DESCRIPTION
  5. The EVP_KDF-KB algorithm implements the Key-Based key derivation function
  6. (KBKDF). KBKDF derives a key from repeated application of a keyed MAC to an
  7. input secret (and other optional values).
  8. =head2 Identity
  9. "KBKDF" is the name for this implementation; it can be used with the
  10. EVP_KDF_fetch() function.
  11. =head2 Supported parameters
  12. The supported parameters are:
  13. =over 4
  14. =item "mode" (B<OSSL_KDF_PARAM_MODE>) <UTF8 string>
  15. The mode parameter determines which flavor of KBKDF to use - currently the
  16. choices are "counter" and "feedback". "counter" is the default, and will be
  17. used if unspecified.
  18. =item "mac" (B<OSSL_KDF_PARAM_MAC>) <UTF8 string>
  19. The value is either CMAC, HMAC, KMAC128 or KMAC256.
  20. =item "digest" (B<OSSL_KDF_PARAM_DIGEST>) <UTF8 string>
  21. =item "cipher" (B<OSSL_KDF_PARAM_CIPHER>) <UTF8 string>
  22. =item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
  23. =item "key" (B<OSSL_KDF_PARAM_KEY>) <octet string>
  24. =item "salt" (B<OSSL_KDF_PARAM_SALT>) <octet string>
  25. =item "info (B<OSSL_KDF_PARAM_INFO>) <octet string>
  26. =item "seed" (B<OSSL_KDF_PARAM_SEED>) <octet string>
  27. The seed parameter is unused in counter mode.
  28. =item "use-l" (B<OSSL_KDF_PARAM_KBKDF_USE_L>) <integer>
  29. Set to B<0> to disable use of the optional Fixed Input data 'L' (see SP800-108).
  30. The default value of B<1> will be used if unspecified.
  31. =item "use-separator" (B<OSSL_KDF_PARAM_KBKDF_USE_SEPARATOR>) <integer>
  32. Set to B<0> to disable use of the optional Fixed Input data 'zero separator'
  33. (see SP800-108) that is placed between the Label and Context.
  34. The default value of B<1> will be used if unspecified.
  35. =item "r" (B<OSSL_KDF_PARAM_KBKDF_R>) <integer>
  36. Set the fixed value 'r', indicating the length of the counter in bits.
  37. Supported values are B<8>, B<16>, B<24>, and B<32>.
  38. The default value of B<32> will be used if unspecified.
  39. =back
  40. Depending on whether mac is CMAC or HMAC, either digest or cipher is required
  41. (respectively) and the other is unused. They are unused for KMAC128 and KMAC256.
  42. The parameters key, salt, info, and seed correspond to KI, Label, Context, and
  43. IV (respectively) in SP800-108. As in that document, salt, info, and seed are
  44. optional and may be omitted.
  45. "mac", "digest", cipher" and "properties" are described in
  46. L<EVP_KDF(3)/PARAMETERS>.
  47. =head1 NOTES
  48. A context for KBKDF can be obtained by calling:
  49. EVP_KDF *kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
  50. EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
  51. The output length of an KBKDF is specified via the C<keylen>
  52. parameter to the L<EVP_KDF_derive(3)> function.
  53. Note that currently OpenSSL only implements counter and feedback modes. Other
  54. variants may be supported in the future.
  55. =head1 EXAMPLES
  56. This example derives 10 bytes using COUNTER-HMAC-SHA256, with KI "secret",
  57. Label "label", and Context "context".
  58. EVP_KDF *kdf;
  59. EVP_KDF_CTX *kctx;
  60. unsigned char out[10];
  61. OSSL_PARAM params[6], *p = params;
  62. kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
  63. kctx = EVP_KDF_CTX_new(kdf);
  64. EVP_KDF_free(kdf);
  65. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
  66. "SHA2-256", 0);
  67. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC,
  68. "HMAC", 0);
  69. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
  70. "secret", strlen("secret"));
  71. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
  72. "label", strlen("label"));
  73. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
  74. "context", strlen("context"));
  75. *p = OSSL_PARAM_construct_end();
  76. if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0)
  77. error("EVP_KDF_derive");
  78. EVP_KDF_CTX_free(kctx);
  79. This example derives 10 bytes using FEEDBACK-CMAC-AES256, with KI "secret",
  80. Label "label", and IV "sixteen bytes iv".
  81. EVP_KDF *kdf;
  82. EVP_KDF_CTX *kctx;
  83. unsigned char out[10];
  84. OSSL_PARAM params[8], *p = params;
  85. unsigned char *iv = "sixteen bytes iv";
  86. kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
  87. kctx = EVP_KDF_CTX_new(kdf);
  88. EVP_KDF_free(kdf);
  89. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CIPHER, "AES256", 0);
  90. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC, "CMAC", 0);
  91. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MODE, "FEEDBACK", 0);
  92. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
  93. "secret", strlen("secret"));
  94. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
  95. "label", strlen("label"));
  96. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
  97. "context", strlen("context"));
  98. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
  99. iv, strlen(iv));
  100. *p = OSSL_PARAM_construct_end();
  101. if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0)
  102. error("EVP_KDF_derive");
  103. EVP_KDF_CTX_free(kctx);
  104. =head1 CONFORMING TO
  105. NIST SP800-108, IETF RFC 6803, IETF RFC 8009.
  106. =head1 SEE ALSO
  107. L<EVP_KDF(3)>,
  108. L<EVP_KDF_CTX_free(3)>,
  109. L<EVP_KDF_CTX_get_kdf_size(3)>,
  110. L<EVP_KDF_derive(3)>,
  111. L<EVP_KDF(3)/PARAMETERS>
  112. =head1 HISTORY
  113. This functionality was added in OpenSSL 3.0.
  114. Support for KMAC was added in OpenSSL 3.1.
  115. =head1 COPYRIGHT
  116. Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
  117. Copyright 2019 Red Hat, Inc.
  118. Licensed under the Apache License 2.0 (the "License"). You may not use
  119. this file except in compliance with the License. You can obtain a copy
  120. in the file LICENSE in the source distribution or at
  121. L<https://www.openssl.org/source/license.html>.
  122. =cut