EVP_KDF-KB.pod 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 or HMAC.
  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. =back
  36. Depending on whether mac is CMAC or HMAC, either digest or cipher is required
  37. (respectively) and the other is unused.
  38. The parameters key, salt, info, and seed correspond to KI, Label, Context, and
  39. IV (respectively) in SP800-108. As in that document, salt, info, and seed are
  40. optional and may be omitted.
  41. "mac", "digest", cipher" and "properties" are described in
  42. L<EVP_KDF(3)/PARAMETERS>.
  43. =head1 NOTES
  44. A context for KBKDF can be obtained by calling:
  45. EVP_KDF *kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
  46. EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
  47. The output length of an KBKDF is specified via the C<keylen>
  48. parameter to the L<EVP_KDF_derive(3)> function.
  49. Note that currently OpenSSL only implements counter and feedback modes. Other
  50. variants may be supported in the future.
  51. =head1 EXAMPLES
  52. This example derives 10 bytes using COUNTER-HMAC-SHA256, with KI "secret",
  53. Label "label", and Context "context".
  54. EVP_KDF *kdf;
  55. EVP_KDF_CTX *kctx;
  56. unsigned char out[10];
  57. OSSL_PARAM params[6], *p = params;
  58. kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
  59. kctx = EVP_KDF_CTX_new(kdf);
  60. EVP_KDF_free(kdf);
  61. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
  62. "SHA2-256", 0);
  63. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC,
  64. "HMAC", 0);
  65. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
  66. "secret", strlen("secret"));
  67. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
  68. "label", strlen("label"));
  69. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
  70. "context", strlen("context"));
  71. *p = OSSL_PARAM_construct_end();
  72. if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0)
  73. error("EVP_KDF_derive");
  74. EVP_KDF_CTX_free(kctx);
  75. This example derives 10 bytes using FEEDBACK-CMAC-AES256, with KI "secret",
  76. Label "label", and IV "sixteen bytes iv".
  77. EVP_KDF *kdf;
  78. EVP_KDF_CTX *kctx;
  79. unsigned char out[10];
  80. OSSL_PARAM params[8], *p = params;
  81. unsigned char *iv = "sixteen bytes iv";
  82. kdf = EVP_KDF_fetch(NULL, "KBKDF", NULL);
  83. kctx = EVP_KDF_CTX_new(kdf);
  84. EVP_KDF_free(kdf);
  85. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_CIPHER, "AES256", 0);
  86. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC, "CMAC", 0);
  87. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MODE, "FEEDBACK", 0);
  88. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
  89. "secret", strlen("secret"));
  90. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
  91. "label", strlen("label"));
  92. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
  93. "context", strlen("context"));
  94. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SEED,
  95. iv, strlen(iv));
  96. *p = OSSL_PARAM_construct_end();
  97. if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0)
  98. error("EVP_KDF_derive");
  99. EVP_KDF_CTX_free(kctx);
  100. =head1 CONFORMING TO
  101. NIST SP800-108, IETF RFC 6803, IETF RFC 8009.
  102. =head1 SEE ALSO
  103. L<EVP_KDF(3)>,
  104. L<EVP_KDF_CTX_free(3)>,
  105. L<EVP_KDF_CTX_get_kdf_size(3)>,
  106. L<EVP_KDF_derive(3)>,
  107. L<EVP_KDF(3)/PARAMETERS>
  108. =head1 HISTORY
  109. This functionality was added to OpenSSL 3.0.
  110. =head1 COPYRIGHT
  111. Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  112. Copyright 2019 Red Hat, Inc.
  113. Licensed under the Apache License 2.0 (the "License"). You may not use
  114. this file except in compliance with the License. You can obtain a copy
  115. in the file LICENSE in the source distribution or at
  116. L<https://www.openssl.org/source/license.html>.
  117. =cut