EVP_KDF-SS.pod 5.6 KB

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