EVP_KDF-SS.pod 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. =pod
  2. =head1 NAME
  3. EVP_KDF-SS - The Single Step / One Step EVP_KDF implementation
  4. =head1 DESCRIPTION
  5. The EVP_KDF-SS algorithm implements the Single Step key derivation function (SSKDF).
  6. SSKDF derives a key using input such as a shared secret key (that was generated
  7. during the execution of a key establishment scheme) and fixedinfo.
  8. SSKDF is also informally referred to as 'Concat KDF'.
  9. The output is considered to be keying material.
  10. =head2 Auxiliary function
  11. The implementation uses a selectable auxiliary function H, which can be one of:
  12. =over 4
  13. =item B<H(x) = hash(x, digest=md)>
  14. =item B<H(x) = HMAC_hash(x, key=salt, digest=md)>
  15. =item B<H(x) = KMACxxx(x, key=salt, custom="KDF", outlen=mac_size)>
  16. =back
  17. Both the HMAC and KMAC implementations set the key using the 'salt' value.
  18. The hash and HMAC also require the digest to be set.
  19. =head2 Identity
  20. "SSKDF" is the name for this implementation; it
  21. can be used with the EVP_KDF_fetch() function.
  22. =head2 Supported parameters
  23. The supported parameters are:
  24. =over 4
  25. =item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
  26. =item "digest" (B<OSSL_KDF_PARAM_DIGEST>) <UTF8 string>
  27. This parameter is ignored for KMAC.
  28. =item "mac" (B<OSSL_KDF_PARAM_MAC>) <UTF8 string>
  29. =item "maclen" (B<OSSL_KDF_PARAM_MAC_SIZE>) <unsigned integer>
  30. =item "salt" (B<OSSL_KDF_PARAM_SALT>) <octet string>
  31. These parameters work as described in L<EVP_KDF(3)/PARAMETERS>.
  32. =item "key" (B<OSSL_KDF_PARAM_SECRET>) <octet string>
  33. This parameter set the shared secret that is used for key derivation.
  34. =item "info" (B<OSSL_KDF_PARAM_INFO>) <octet string>
  35. This parameter sets an optional value for fixedinfo, also known as otherinfo.
  36. =back
  37. =head1 NOTES
  38. A context for SSKDF can be obtained by calling:
  39. EVP_KDF *kdf = EVP_KDF_fetch(NULL, "SSKDF", NULL);
  40. EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
  41. The output length of an SSKDF is specified via the I<keylen>
  42. parameter to the L<EVP_KDF_derive(3)> function.
  43. =head1 EXAMPLES
  44. This example derives 10 bytes using H(x) = SHA-256, with the secret key "secret"
  45. and fixedinfo value "label":
  46. EVP_KDF *kdf;
  47. EVP_KDF_CTX *kctx;
  48. unsigned char out[10];
  49. OSSL_PARAM params[4], *p = params;
  50. kdf = EVP_KDF_fetch(NULL, "SSKDF", NULL);
  51. kctx = EVP_KDF_CTX_new(kdf);
  52. EVP_KDF_free(kdf);
  53. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
  54. SN_sha256, strlen(SN_sha256));
  55. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
  56. "secret", (size_t)6);
  57. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
  58. "label", (size_t)5);
  59. *p = OSSL_PARAM_construct_end();
  60. if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0) {
  61. error("EVP_KDF_derive");
  62. }
  63. EVP_KDF_CTX_free(kctx);
  64. This example derives 10 bytes using H(x) = HMAC(SHA-256), with the secret key "secret",
  65. fixedinfo value "label" and salt "salt":
  66. EVP_KDF *kdf;
  67. EVP_KDF_CTX *kctx;
  68. unsigned char out[10];
  69. OSSL_PARAM params[6], *p = params;
  70. kdf = EVP_KDF_fetch(NULL, "SSKDF", NULL);
  71. kctx = EVP_KDF_CTX_new(kdf);
  72. EVP_KDF_free(kdf);
  73. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC,
  74. SN_hmac, strlen(SN_hmac));
  75. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
  76. SN_sha256, strlen(SN_sha256));
  77. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
  78. "secret", (size_t)6);
  79. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
  80. "label", (size_t)5);
  81. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
  82. "salt", (size_t)4);
  83. *p = OSSL_PARAM_construct_end();
  84. if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0) {
  85. error("EVP_KDF_derive");
  86. }
  87. EVP_KDF_CTX_free(kctx);
  88. This example derives 10 bytes using H(x) = KMAC128(x,salt,outlen), with the secret key "secret"
  89. fixedinfo value "label", salt of "salt" and KMAC outlen of 20:
  90. EVP_KDF *kdf;
  91. EVP_KDF_CTX *kctx;
  92. unsigned char out[10];
  93. OSSL_PARAM params[6], *p = params;
  94. kdf = EVP_KDF_fetch(NULL, "SSKDF", NULL);
  95. kctx = EVP_KDF_CTX_new(kdf);
  96. EVP_KDF_free(kdf);
  97. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC,
  98. SN_kmac128, strlen(SN_kmac128));
  99. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET,
  100. "secret", (size_t)6);
  101. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
  102. "label", (size_t)5);
  103. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
  104. "salt", (size_t)4);
  105. *p++ = OSSL_PARAM_construct_size_t(OSSL_KDF_PARAM_MAC_SIZE, (size_t)20);
  106. *p = OSSL_PARAM_construct_end();
  107. if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0) {
  108. error("EVP_KDF_derive");
  109. }
  110. EVP_KDF_CTX_free(kctx);
  111. =head1 CONFORMING TO
  112. NIST SP800-56Cr1.
  113. =head1 SEE ALSO
  114. L<EVP_KDF(3)>,
  115. L<EVP_KDF_CTX_new(3)>,
  116. L<EVP_KDF_CTX_free(3)>,
  117. L<EVP_KDF_CTX_set_params(3)>,
  118. L<EVP_KDF_CTX_get_kdf_size(3)>,
  119. L<EVP_KDF_derive(3)>,
  120. L<EVP_KDF(3)/PARAMETERS>
  121. =head1 HISTORY
  122. This functionality was added in OpenSSL 3.0.
  123. =head1 COPYRIGHT
  124. Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved. Copyright
  125. (c) 2019, Oracle and/or its affiliates. All rights reserved.
  126. Licensed under the Apache License 2.0 (the "License"). You may not use
  127. this file except in compliance with the License. You can obtain a copy
  128. in the file LICENSE in the source distribution or at
  129. L<https://www.openssl.org/source/license.html>.
  130. =cut