2
0

EVP_KDF-SSHKDF.pod 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. =pod
  2. =head1 NAME
  3. EVP_KDF-SSHKDF - The SSHKDF EVP_KDF implementation
  4. =head1 DESCRIPTION
  5. Support for computing the B<SSHKDF> KDF through the B<EVP_KDF> API.
  6. The EVP_KDF-SSHKDF algorithm implements the SSHKDF key derivation function.
  7. It is defined in RFC 4253, section 7.2 and is used by SSH to derive IVs,
  8. encryption keys and integrity keys.
  9. Five inputs are required to perform key derivation: The hashing function
  10. (for example SHA256), the Initial Key, the Exchange Hash, the Session ID,
  11. and the derivation key type.
  12. =head2 Identity
  13. "SSHKDF" is the name for this implementation; it
  14. can be used with the EVP_KDF_fetch() function.
  15. =head2 Supported parameters
  16. The supported parameters are:
  17. =over 4
  18. =item "properties" (B<OSSL_KDF_PARAM_PROPERTIES>) <UTF8 string>
  19. =item "digest" (B<OSSL_KDF_PARAM_DIGEST>) <UTF8 string>
  20. =item "key" (B<OSSL_KDF_PARAM_KEY>) <octet string>
  21. These parameters work as described in L<EVP_KDF(3)/PARAMETERS>.
  22. =item "xcghash" (B<OSSL_KDF_PARAM_SSHKDF_XCGHASH>) <octet string>
  23. =item "session_id" (B<OSSL_KDF_PARAM_SSHKDF_SESSION_ID>) <octet string>
  24. These parameters set the respective values for the KDF.
  25. If a value is already set, the contents are replaced.
  26. =item "type" (B<OSSL_KDF_PARAM_SSHKDF_TYPE>) <integer>
  27. This parameter sets the type for the SSHHKDF operation.
  28. There are six supported types:
  29. =over 4
  30. =item EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV
  31. The Initial IV from client to server.
  32. A single char of value 65 (ASCII char 'A').
  33. =item EVP_KDF_SSHKDF_TYPE_INITIAL_IV_SRV_TO_CLI
  34. The Initial IV from server to client
  35. A single char of value 66 (ASCII char 'B').
  36. =item EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_CLI_TO_SRV
  37. The Encryption Key from client to server
  38. A single char of value 67 (ASCII char 'C').
  39. =item EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_SRV_TO_CLI
  40. The Encryption Key from server to client
  41. A single char of value 68 (ASCII char 'D').
  42. =item EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_CLI_TO_SRV
  43. The Integrity Key from client to server
  44. A single char of value 69 (ASCII char 'E').
  45. =item EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_SRV_TO_CLI
  46. The Integrity Key from client to server
  47. A single char of value 70 (ASCII char 'F').
  48. =back
  49. =back
  50. =head1 NOTES
  51. A context for SSHKDF can be obtained by calling:
  52. EVP_KDF *kdf = EVP_KDF_fetch(NULL, "SSHKDF", NULL);
  53. EVP_KDF_CTX *kctx = EVP_KDF_new_ctx(kdf);
  54. The output length of the SSHKDF derivation is specified via the I<keylen>
  55. parameter to the L<EVP_KDF_derive(3)> function.
  56. Since the SSHKDF output length is variable, calling L<EVP_KDF_size(3)>
  57. to obtain the requisite length is not meaningful. The caller must
  58. allocate a buffer of the desired length, and pass that buffer to the
  59. L<EVP_KDF_derive(3)> function along with the desired length.
  60. =head1 EXAMPLES
  61. This example derives an 8 byte IV using SHA-256 with a 1K "key" and appropriate
  62. "xcghash" and "session_id" values:
  63. EVP_KDF *kdf;
  64. EVP_KDF_CTX *kctx;
  65. unsigned char key[1024] = "01234...";
  66. unsigned char xcghash[32] = "012345...";
  67. unsigned char session_id[32] = "012345...";
  68. unsigned char out[8];
  69. size_t outlen = sizeof(out);
  70. OSSL_PARAM params[6], *p = params;
  71. kdf = EVP_KDF_fetch(NULL, "SSHKDF", NULL);
  72. kctx = EVP_KDF_new_ctx(kdf);
  73. EVP_KDF_free(kdf);
  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_KEY,
  77. key, (size_t)1024);
  78. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SSHKDF_XCGHASH,
  79. xcghash, (size_t)32);
  80. *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT,
  81. session_id, (size_t)32);
  82. *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_SSHKDF_TYPE,
  83. EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV);
  84. *p = OSSL_PARAM_construct_end();
  85. if (EVP_KDF_set_ctx_params(kctx, params) <= 0)
  86. /* Error */
  87. if (EVP_KDF_derive(kctx, out, &outlen) <= 0)
  88. /* Error */
  89. =head1 CONFORMING TO
  90. RFC 4253
  91. =head1 SEE ALSO
  92. L<EVP_KDF(3)>,
  93. L<EVP_KDF_new_ctx(3)>,
  94. L<EVP_KDF_free_ctx(3)>,
  95. L<EVP_KDF_set_ctx_params(3)>,
  96. L<EVP_KDF_size(3)>,
  97. L<EVP_KDF_derive(3)>,
  98. L<EVP_KDF(3)/PARAMETERS>
  99. =head1 COPYRIGHT
  100. Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
  101. Licensed under the Apache License 2.0 (the "License"). You may not use
  102. this file except in compliance with the License. You can obtain a copy
  103. in the file LICENSE in the source distribution or at
  104. L<https://www.openssl.org/source/license.html>.
  105. =cut