<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CryptoKit",
  "identifier" : "/documentation/CryptoKit/HKDF",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Apple CryptoKit"
    ],
    "preciseIdentifier" : "s:9CryptoKit4HKDFV"
  },
  "title" : "HKDF"
}
-->

# HKDF

A standards-based implementation of an HMAC-based Key Derivation Function
(HKDF).

```
struct HKDF<H> where H : HashFunction
```

## Overview

The key derivation functions allow you to derive one or more secrets of the
size of your choice from a main key or passcode. The key derivation function
is compliant with IETF RFC 5869. Use one of the `deriveKey` functions, such
as [`deriveKey(inputKeyMaterial:outputByteCount:)`](/documentation/CryptoKit/HKDF/deriveKey(inputKeyMaterial:outputByteCount:)) or
[`deriveKey(inputKeyMaterial:salt:info:outputByteCount:)`](/documentation/CryptoKit/HKDF/deriveKey(inputKeyMaterial:salt:info:outputByteCount:)), to derive a key
from a main secret or passcode in a single function.

To derive a key with more fine-grained control, use
`extract(inputKeyMaterial:salt:)` to create cryptographically strong key
material in the form of a hashed authentication code, then call
[`expand(pseudoRandomKey:info:outputByteCount:)`](/documentation/CryptoKit/HKDF/expand(pseudoRandomKey:info:outputByteCount:)) using that key material to
generate a symmetric key of the length you specify.

## Topics

### Deriving a key

[`deriveKey(inputKeyMaterial:outputByteCount:)`](/documentation/CryptoKit/HKDF/deriveKey(inputKeyMaterial:outputByteCount:))

Derives a symmetric encryption key from a main key or passcode using
HKDF key derivation.

[`deriveKey(inputKeyMaterial:info:outputByteCount:)`](/documentation/CryptoKit/HKDF/deriveKey(inputKeyMaterial:info:outputByteCount:))

Derives a symmetric encryption key from a main key or passcode using
HKDF key derivation with information you specify.

[`deriveKey(inputKeyMaterial:salt:outputByteCount:)`](/documentation/CryptoKit/HKDF/deriveKey(inputKeyMaterial:salt:outputByteCount:))

Derives a symmetric encryption key from a main key or passcode using
HKDF key derivation with salt that you specify.

[`deriveKey(inputKeyMaterial:salt:info:outputByteCount:)`](/documentation/CryptoKit/HKDF/deriveKey(inputKeyMaterial:salt:info:outputByteCount:))

Derives a symmetric encryption key from a main key or passcode using
HKDF key derivation with information and salt you specify.

### Controlling key derivation

[`expand(pseudoRandomKey:info:outputByteCount:)`](/documentation/CryptoKit/HKDF/expand(pseudoRandomKey:info:outputByteCount:))

Expands cryptographically strong key material into a derived symmetric
key.

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)