| 1 |
// Copyright 2018-2022 The OpenSSL Project Authors. All Rights Reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
#ifndef OPENSSL_HEADER_SSHKDF_H |
| 5 |
#define OPENSSL_HEADER_SSHKDF_H |
| 6 |
|
| 7 |
#include <openssl/base.h> |
| 8 |
|
| 9 |
#if defined(__cplusplus) |
| 10 |
extern "C" { |
| 11 |
#endif |
| 12 |
|
| 13 |
|
| 14 |
// SSH-specific KDF |
| 15 |
// |
| 16 |
// This KDF should only be called from SSH client/server code; it's not a |
| 17 |
// general-purpose KDF and is only Approved for FIPS 140-3 use specifically |
| 18 |
// in SSH. |
| 19 |
|
| 20 |
|
| 21 |
// The following defines are the valid |type| values for SSHKDF(). |
| 22 |
|
| 23 |
#define EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV 65 |
| 24 |
#define EVP_KDF_SSHKDF_TYPE_INITIAL_IV_SRV_TO_CLI 66 |
| 25 |
#define EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_CLI_TO_SRV 67 |
| 26 |
#define EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_SRV_TO_CLI 68 |
| 27 |
#define EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_CLI_TO_SRV 69 |
| 28 |
#define EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_SRV_TO_CLI 70 |
| 29 |
|
| 30 |
// SSHKDF is a key derivation function used in the SSH Transport Layer Protocol |
| 31 |
// defined in Section 7.2 of RFC 4253. It calculates a derived key |out| of |
| 32 |
// length |out_len| bytes using |evp_md| hash algorithm from the supplied |
| 33 |
// shared secret |key|, hash value |xcghash| and session identifier |
| 34 |
// |session_id|. It returns one on success and zero on error. |
| 35 |
// |
| 36 |
// |xcghash| is produced during the SSH Diffie-Hellman exchange. |
| 37 |
// |
| 38 |
// SSHKDF is only FIPS 140-3 Approved for use in SSH. |
| 39 |
OPENSSL_EXPORT int SSHKDF(const EVP_MD *evp_md, |
| 40 |
const uint8_t *key, size_t key_len, |
| 41 |
const uint8_t *xcghash, size_t xcghash_len, |
| 42 |
const uint8_t *session_id, size_t session_id_len, |
| 43 |
char type, |
| 44 |
uint8_t *out, size_t out_len); |
| 45 |
|
| 46 |
|
| 47 |
#if defined(__cplusplus) |
| 48 |
} // extern C |
| 49 |
#endif |
| 50 |
|
| 51 |
#endif // OPENSSL_HEADER_SSHKDF_H |