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. =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_derive(kctx, out, sizeof(out), params) <= 0) {
  59. error("EVP_KDF_derive");
  60. }
  61. EVP_KDF_CTX_free(kctx);
  62. This example derives 10 bytes using H(x) = HMAC(SHA-256), with the secret key "secret",
  63. fixedinfo value "label" and salt "salt":
  64. EVP_KDF *kdf;
  65. EVP_KDF_CTX *kctx;
  66. unsigned char out[10];
  67. OSSL_PARAM params[6], *p = params;
  68. kdf = EVP_KDF_fetch(NULL, "SSKDF", NULL);
  69. kctx = EVP_KDF_CTX_new(kdf);
  70. EVP_KDF_free(kdf);
  71. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC,
  72. SN_hmac, strlen(SN_hmac));
  73. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
  74. SN_sha256, strlen(SN_sha256));
  75. *p++ = OSSL_PARAM_construct_octet_string(EVP_KDF_CTRL_SET_KEY,
  76. "secret", (size_t)6);
  77. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO,
  78. "label", (size_t)5);
  79. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
  80. "salt", (size_t)4);
  81. *p = OSSL_PARAM_construct_end();
  82. if (EVP_KDF_derive(kctx, out, sizeof(out), params) <= 0) {
  83. error("EVP_KDF_derive");
  84. }
  85. EVP_KDF_CTX_free(kctx);
  86. This example derives 10 bytes using H(x) = KMAC128(x,salt,outlen), with the secret key "secret"
  87. fixedinfo value "label", salt of "salt" and KMAC outlen of 20:
  88. EVP_KDF *kdf;
  89. EVP_KDF_CTX *kctx;
  90. unsigned char out[10];
  91. OSSL_PARAM params[7], *p = params;
  92. kdf = EVP_KDF_fetch(NULL, "SSKDF", NULL);
  93. kctx = EVP_KDF_CTX_new(kdf);
  94. EVP_KDF_free(kdf);
  95. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC,
  96. SN_kmac128, strlen(SN_kmac128));
  97. *p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
  98. SN_sha256, strlen(SN_sha256));
  99. *p++ = OSSL_PARAM_construct_octet_string(EVP_KDF_CTRL_SET_KEY,
  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 to OpenSSL 3.0.
  123. =head1 COPYRIGHT
  124. Copyright 2019-2021 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