1
0

EVP_KDF-KB.pod 5.7 KB

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