# info > EVP_KDF-SSHKDF

---
type: CommandReference
command: EVP_KDF-SSHKDF
mode: man
section: 7SSL
source: man-pages
---

## Quick Reference

- `EVP_KDF *kdf = EVP_KDF_fetch(NULL, "SSHKDF", NULL)` — obtain a KDF context for the SSHKDF implementation
- `EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf)` — create a new KDF context
- `EVP_KDF_derive(kctx, out, &outlen, params)` — derive key material with specified params
- Inputs: digest (hash function), key (initial key), xcghash (exchange hash), session_id, type (key derivation type)
- Type constants (single ASCII characters):
  - `EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV` — 'A' (65)
  - `EVP_KDF_SSHKDF_TYPE_INITIAL_IV_SRV_TO_CLI` — 'B' (66)
  - `EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_CLI_TO_SRV` — 'C' (67)
  - `EVP_KDF_SSHKDF_TYPE_ENCRYPTION_KEY_SRV_TO_CLI` — 'D' (68)
  - `EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_CLI_TO_SRV` — 'E' (69)
  - `EVP_KDF_SSHKDF_TYPE_INTEGRITY_KEY_SRV_TO_CLI` — 'F' (70)

## Name

EVP_KDF-SSHKDF — The SSHKDF EVP_KDF implementation, defined in RFC 4253 section 7.2.  Supports SSH key derivation for IVs, encryption keys, and integrity keys using SHA-256 or other hash functions.

## Synopsis

c
EVP_KDF *kdf = EVP_KDF_fetch(NULL, "SSHKDF", NULL);
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
EVP_KDF_free(kdf);

// Set params: digest, key, xcghash, session_id, type
OSSL_PARAM params[6], *p = params;
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, "SHA256", ...);
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, key, keylen);
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SSHKDF_XCGHASH, xcghash, len);
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SSHKDF_SESSION_ID, session_id, len);
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_SSHKDF_TYPE, &type, 1);
*p = OSSL_PARAM_construct_end();

if (EVP_KDF_derive(kctx, out, &outlen, params) <= 0) /* error */
## Options

- `"properties"` (OSSL_KDF_PARAM_PROPERTIES) — UTF8 string; implementation properties per EVP_KDF(3)
- `"digest"` (OSSL_KDF_PARAM_DIGEST) — UTF8 string; hash algorithm (e.g., `"SHA256"`)
- `"key"` (OSSL_KDF_PARAM_KEY) — octet string; initial key material
- `"xcghash"` (OSSL_KDF_PARAM_SSHKDF_XCGHASH) — octet string; exchange hash (from SSH key exchange)
- `"session_id"` (OSSL_KDF_PARAM_SSHKDF_SESSION_ID) — octet string; session identifier
- `"type"` (OSSL_KDF_PARAM_SSHKDF_TYPE) — UTF8 string; one of the six type constants (single character 'A'–'F' as described above)

Setting any of `xcghash`, `session_id`, or `type` replaces the previous value.

## Examples

Derive an 8‑byte IV using SHA‑256 with a 1K key, appropriate exchange hash and session ID:

c
EVP_KDF *kdf;
EVP_KDF_CTX *kctx;
const char type = EVP_KDF_SSHKDF_TYPE_INITIAL_IV_CLI_TO_SRV;
unsigned char key[1024] = "01234...";
unsigned char xcghash[32] = "012345...";
unsigned char session_id[32] = "012345...";
unsigned char out[8];
size_t outlen = sizeof(out);
OSSL_PARAM params[6], *p = params;

kdf = EVP_KDF_fetch(NULL, "SSHKDF", NULL);
kctx = EVP_KDF_CTX_new(kdf);
EVP_KDF_free(kdf);

*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
                                        SN_sha256, strlen(SN_sha256));
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY,
                                         key, (size_t)1024);
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SSHKDF_XCGHASH,
                                         xcghash, (size_t)32);
*p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SSHKDF_SESSION_ID,
                                         session_id, (size_t)32);
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_SSHKDF_TYPE,
                                        &type, sizeof(type));
*p = OSSL_PARAM_construct_end();
if (EVP_KDF_derive(kctx, out, &outlen, params) <= 0)
    /* Error */
## See Also

- [EVP_KDF(3)](http://localhost/phpMan.php/man/EVPKDF/3/markdown)
- [EVP_KDF_CTX_new(3)](http://localhost/phpMan.php/man/EVPKDFCTXnew/3/markdown)
- [EVP_KDF_CTX_free(3)](http://localhost/phpMan.php/man/EVPKDFCTXfree/3/markdown)
- [EVP_KDF_CTX_set_params(3)](http://localhost/phpMan.php/man/EVPKDFCTXsetparams/3/markdown)
- [EVP_KDF_CTX_get_kdf_size(3)](http://localhost/phpMan.php/man/EVPKDFCTXgetkdfsize/3/markdown)
- [EVP_KDF_derive(3)](http://localhost/phpMan.php/man/EVPKDFderive/3/markdown)
- RFC 4253 section 7.2

## Exit Codes

Not documented.