26#ifndef WOLF_CRYPT_DH_H
27#define WOLF_CRYPT_DH_H
33#if defined(HAVE_FIPS) && \
34 defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
35 #include <wolfssl/wolfcrypt/fips.h>
38#include <wolfssl/wolfcrypt/integer.h>
45#ifdef WOLFSSL_ASYNC_CRYPT
46 #include <wolfssl/wolfcrypt/async.h>
48typedef struct DhParams {
62#if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_OPENSSH)
67#ifdef WOLFSSL_ASYNC_CRYPT
68 WC_ASYNC_DEV asyncDev;
72#ifndef WC_DH_TYPE_DEFINED
74 #define WC_DH_TYPE_DEFINED
94WOLFSSL_API
int wc_InitDhKey_ex(
DhKey* key,
void* heap,
int devId);
98 word32* privSz,
byte* pub, word32* pubSz);
100 const byte* priv, word32 privSz,
const byte* otherPub,
105WOLFSSL_API
int wc_DhSetKey(
DhKey* key,
const byte* p, word32 pSz,
const byte* g,
107WOLFSSL_API
int wc_DhSetKey_ex(
DhKey* key,
const byte* p, word32 pSz,
108 const byte* g, word32 gSz,
const byte* q, word32 qSz);
109#if defined(WOLFSSL_QT) || defined(OPENSSL_ALL)
110WOLFSSL_LOCAL
int wc_DhSetFullKeys(
DhKey* key,
const byte* priv_key,word32 privSz,
111 const byte* pub_key, word32 pubSz);
113WOLFSSL_API
int wc_DhSetCheckKey(
DhKey* key,
const byte* p, word32 pSz,
114 const byte* g, word32 gSz,
const byte* q, word32 qSz,
115 int trusted,
WC_RNG* rng);
116WOLFSSL_API
int wc_DhParamsLoad(
const byte* input, word32 inSz,
byte* p,
117 word32* pInOutSz,
byte* g, word32* gInOutSz);
118WOLFSSL_API
int wc_DhCheckPubKey(
DhKey* key,
const byte* pub, word32 pubSz);
119WOLFSSL_API
int wc_DhCheckPubKey_ex(
DhKey* key,
const byte* pub, word32 pubSz,
120 const byte* prime, word32 primeSz);
122 const byte* pub, word32 pubSz);
124WOLFSSL_API
int wc_DhCheckPrivKey_ex(
DhKey* key,
const byte* priv, word32 pubSz,
125 const byte* prime, word32 primeSz);
127 const byte* priv, word32 privSz);
128WOLFSSL_API
int wc_DhGenerateParams(
WC_RNG *rng,
int modSz,
DhKey *dh);
129WOLFSSL_API
int wc_DhExportParamsRaw(
DhKey* dh,
byte* p, word32* pSz,
130 byte* q, word32* qSz,
byte* g, word32* gSz);
WOLFSSL_API const DhParams * wc_Dh_ffdhe4096_Get(void)
This function returns ... and requires that HAVE_FFDHE_4096 be defined.
Definition dh.c:419
WOLFSSL_API const DhParams * wc_Dh_ffdhe8192_Get(void)
This function returns ... and requires that HAVE_FFDHE_8192 be defined.
Definition dh.c:911
WOLFSSL_API int wc_DhSetKey(DhKey *key, const byte *p, word32 pSz, const byte *g, word32 gSz)
This function sets the key for a DhKey structure using the input private key parameters....
Definition dh.c:2234
WOLFSSL_API int wc_DhGenerateKeyPair(DhKey *key, WC_RNG *rng, byte *priv, word32 *privSz, byte *pub, word32 *pubSz)
This function generates a public/private key pair based on the Diffie-Hellman public parameters,...
Definition dh.c:1814
WOLFSSL_API int wc_DhCheckPrivKey(DhKey *key, const byte *priv, word32 pubSz)
Check DH private key for invalid numbers.
Definition dh.c:1687
WOLFSSL_API int wc_DhKeyDecode(const byte *input, word32 *inOutIdx, DhKey *key, word32)
This function decodes a Diffie-Hellman key from the given input buffer containing the key in DER form...
Definition asn.c:4393
WOLFSSL_API void wc_FreeDhKey(DhKey *key)
This function frees a Diffie-Hellman key after it has been used to negotiate a secure secret key with...
Definition dh.c:957
WOLFSSL_API int wc_DhCheckKeyPair(DhKey *key, const byte *pub, word32 pubSz, const byte *priv, word32 privSz)
Checks DH keys for pair-wise consistency per process in SP 800-56Ar3, section 5.6....
Definition dh.c:1704
WOLFSSL_API const DhParams * wc_Dh_ffdhe6144_Get(void)
This function returns ... and requires that HAVE_FFDHE_6144 be defined.
Definition dh.c:633
WOLFSSL_API int wc_InitDhKey(DhKey *key)
This function initializes a Diffie-Hellman key for use in negotiating a secure secret key with the Di...
Definition dh.c:951
WOLFSSL_API int wc_DhParamsLoad(const byte *input, word32 inSz, byte *p, word32 *pInOutSz, byte *g, word32 *gInOutSz)
This function loads the Diffie-Hellman parameters, p (prime) and g (base) out of the given input buff...
Definition asn.c:4472
WOLFSSL_API const DhParams * wc_Dh_ffdhe3072_Get(void)
This function returns ... and requires that HAVE_FFDHE_3072 be defined.
Definition dh.c:269
WOLFSSL_API int wc_DhAgree(DhKey *key, byte *agree, word32 *agreeSz, const byte *priv, word32 privSz, const byte *otherPub, word32 pubSz)
This function generates an agreed upon secret key based on a local private key and a received public ...
Definition dh.c:2045
WOLFSSL_API const DhParams * wc_Dh_ffdhe2048_Get(void)
This function returns ... and requires that HAVE_FFDHE_2048 be defined.
Definition dh.c:151
WOLFSSL_API int wc_DhCheckPubValue(const byte *prime, word32 primeSz, const byte *pub, word32 pubSz)
Definition dh.c:1553