#ifndef NO_KDF
#ifndef WOLF_CRYPT_KDF_H
#define WOLF_CRYPT_KDF_H
#if defined(HAVE_FIPS) && \
defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 5)
#include <wolfssl/wolfcrypt/fips.h>
#endif
#include <wolfssl/wolfcrypt/hmac.h>
#ifdef HAVE_CMAC_KDF
#include <wolfssl/wolfcrypt/cmac.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if FIPS_VERSION3_GE(6,0,0)
extern const unsigned int wolfCrypt_FIPS_kdf_ro_sanity[2];
WOLFSSL_LOCAL int wolfCrypt_FIPS_KDF_sanity(void);
#endif
enum max_prf {
#ifdef HAVE_FFDHE_8192
MAX_PRF_HALF = 516,
#elif defined(HAVE_FFDHE_6144)
MAX_PRF_HALF = 388,
#else
MAX_PRF_HALF = 260,
#endif
MAX_PRF_LABSEED = 128,
MAX_PRF_DIG = 224
};
#ifdef WOLFSSL_HAVE_PRF
WOLFSSL_API int wc_PRF(byte* result, word32 resLen, const byte* secret,
word32 secLen, const byte* seed, word32 seedLen, int hash,
void* heap, int devId);
WOLFSSL_API int wc_PRF_TLSv1(byte* digest, word32 digLen, const byte* secret,
word32 secLen, const byte* label, word32 labLen,
const byte* seed, word32 seedLen, void* heap, int devId);
WOLFSSL_API int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret,
word32 secLen, const byte* label, word32 labLen,
const byte* seed, word32 seedLen, int useAtLeastSha256,
int hash_type, void* heap, int devId);
#endif
#ifdef HAVE_HKDF
enum {
MAX_TLS13_HKDF_LABEL_SZ = 47 + WC_MAX_DIGEST_SIZE
};
WOLFSSL_API int wc_Tls13_HKDF_Extract_ex(byte* prk, const byte* salt,
word32 saltLen, byte* ikm, word32 ikmLen, int digest,
void* heap, int devId);
WOLFSSL_API int wc_Tls13_HKDF_Extract(byte* prk, const byte* salt,
word32 saltLen, byte* ikm, word32 ikmLen, int digest);
WOLFSSL_API int wc_Tls13_HKDF_Expand_Label_ex(byte* okm, word32 okmLen,
const byte* prk, word32 prkLen,
const byte* protocol, word32 protocolLen,
const byte* label, word32 labelLen,
const byte* info, word32 infoLen,
int digest, void* heap, int devId);
WOLFSSL_API int wc_Tls13_HKDF_Expand_Label(byte* okm, word32 okmLen,
const byte* prk, word32 prkLen,
const byte* protocol, word32 protocolLen,
const byte* label, word32 labelLen,
const byte* info, word32 infoLen,
int digest);
#if defined(WOLFSSL_TICKET_NONCE_MALLOC) && \
(!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
WOLFSSL_API int wc_Tls13_HKDF_Expand_Label_Alloc(byte* okm, word32 okmLen,
const byte* prk, word32 prkLen, const byte* protocol, word32 protocolLen,
const byte* label, word32 labelLen, const byte* info, word32 infoLen,
int digest, void* heap);
#endif
#endif
#ifdef WOLFSSL_WOLFSSH
WOLFSSL_API int wc_SSH_KDF(byte hashId, byte keyId,
byte* key, word32 keySz,
const byte* k, word32 kSz,
const byte* h, word32 hSz,
const byte* sessionId, word32 sessionIdSz);
#endif
#ifdef WC_SRTP_KDF
#define WC_SRTP_LABEL_ENCRYPTION 0x00
#define WC_SRTP_LABEL_MSG_AUTH 0x01
#define WC_SRTP_LABEL_SALT 0x02
#define WC_SRTCP_LABEL_ENCRYPTION 0x03
#define WC_SRTCP_LABEL_MSG_AUTH 0x04
#define WC_SRTCP_LABEL_SALT 0x05
#define WC_SRTP_LABEL_HDR_ENCRYPTION 0x06
#define WC_SRTP_LABEL_HDR_SALT 0x07
#define WC_SRTP_INDEX_LEN 6
#define WC_SRTCP_INDEX_LEN 4
enum {
WC_SRTCP_32BIT_IDX = 0,
WC_SRTCP_48BIT_IDX = 1
};
#define WC_SRTP_MAX_SALT 14
WOLFSSL_API int wc_SRTP_KDF(const byte* key, word32 keySz, const byte* salt,
word32 saltSz, int kdrIdx, const byte* idx, byte* key1, word32 key1Sz,
byte* key2, word32 key2Sz, byte* key3, word32 key3Sz);
WOLFSSL_API int wc_SRTCP_KDF(const byte* key, word32 keySz, const byte* salt,
word32 saltSz, int kdrIdx, const byte* idx, byte* key1, word32 key1Sz,
byte* key2, word32 key2Sz, byte* key3, word32 key3Sz);
WOLFSSL_API int wc_SRTCP_KDF_ex(const byte* key, word32 keySz, const byte* salt,
word32 saltSz, int kdrIdx, const byte* idx, byte* key1, word32 key1Sz,
byte* key2, word32 key2Sz, byte* key3, word32 key3Sz, int idxLenIndicator);
WOLFSSL_API int wc_SRTP_KDF_label(const byte* key, word32 keySz,
const byte* salt, word32 saltSz, int kdrIdx, const byte* idx, byte label,
byte* outKey, word32 outKeySz);
WOLFSSL_API int wc_SRTCP_KDF_label(const byte* key, word32 keySz,
const byte* salt, word32 saltSz, int kdrIdx, const byte* idx, byte label,
byte* outKey, word32 outKeySz);
WOLFSSL_API int wc_SRTP_KDF_kdr_to_idx(word32 kdr);
#endif
#ifdef WC_KDF_NIST_SP_800_56C
WOLFSSL_API int wc_KDA_KDF_onestep(const byte* z, word32 zSz,
const byte* fixedInfo, word32 fixedInfoSz, word32 derivedSecretSz,
enum wc_HashType hashType, byte* output, word32 outputSz);
#endif
#ifdef HAVE_CMAC_KDF
WOLFSSL_API int wc_KDA_KDF_twostep_cmac(const byte * salt, word32 salt_len,
const byte* z, word32 zSz,
const byte* fixedInfo,
word32 fixedInfoSz,
byte* output, word32 outputSz,
void* heap, int devId);
WOLFSSL_API int wc_KDA_KDF_PRF_cmac(const byte* Kin, word32 KinSz,
const byte* fixedInfo, word32 fixedInfoSz,
byte* Kout, word32 KoutSz, CmacType type,
void* heap, int devId);
#endif
#ifdef __cplusplus
}
#endif
#endif
#endif