EVP_KDF-KB.pod 5.0 KB

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