EVP_KDF-SS.pod 5.9 KB

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