28 #ifndef __KEYEX_DH_HEADER__ 29 #define __KEYEX_DH_HEADER__ 31 #include "../cap/capdecl.h" 33 #ifdef __ENABLE_MOCANA_CRYPTO_INTERFACE__ 34 #include "../crypto_interface/crypto_interface_dh_priv.h" 37 #include "../cap/capasym.h" 38 #include "../crypto/ffc.h" 44 #define DH_GROUP_TBD 0 48 #define DH_GROUP_14 14 49 #define DH_GROUP_15 15 50 #define DH_GROUP_16 16 51 #define DH_GROUP_17 17 52 #define DH_GROUP_18 18 53 #define DH_GROUP_24 24 55 #define DH_GROUP_19 19 56 #define DH_GROUP_20 20 57 #define DH_GROUP_21 21 58 #define DH_GROUP_25 25 59 #define DH_GROUP_26 26 60 #define DH_GROUP_31 31 61 #define DH_GROUP_32 32 63 #define DH_GROUP_FFDHE2048 0x100 64 #define DH_GROUP_FFDHE3072 0x101 65 #define DH_GROUP_FFDHE4096 0x102 66 #define DH_GROUP_FFDHE6144 0x103 67 #define DH_GROUP_FFDHE8192 0x104 69 #define COMPUTED_VLONG_G(X) (X)->dh_g 70 #define COMPUTED_VLONG_Y(X) (X)->dh_y 71 #define COMPUTED_VLONG_F(X) (X)->dh_f 72 #define COMPUTED_VLONG_E(X) (X)->dh_e 73 #define COMPUTED_VLONG_K(X) (X)->dh_k 74 #define COMPUTED_VLONG_P(X) (X)->dh_p 75 #define COMPUTED_VLONG_Q(X) (X)->dh_q 77 #ifndef __DISABLE_MOCANA_DH_BLINDING__ 78 #define COMPUTED_VLONG_VF(X) (X)->dh_vf 79 #define COMPUTED_VLONG_VI(X) (X)->dh_vi 80 #define COMPUTED_VLONG_PY(X) (X)->dh_py 84 #define DIFFIEHELLMAN_CONTEXT(X) (X)->p_dhContext 136 MocAsymKey pPrivateKey;
137 MocAsymKey pPublicKey;
140 #ifndef __DISABLE_MOCANA_DH_BLINDING__ 195 MOC_EXTERN MSTATUS
DH_getG(ubyte4 groupNum, vlong **ppRetG);
242 MOC_EXTERN MSTATUS
DH_getP(ubyte4 groupNum, vlong **ppRetP);
273 MOC_EXTERN MSTATUS
DH_getPByteString(ubyte4 groupNum,
const ubyte** ppBytes, sbyte4* pLen);
609 MOC_EXTERN MSTATUS
DH_setPG(MOC_DH(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, ubyte4 lengthY,
diffieHellmanContext *p_dhContext,
const vlong *P,
const vlong *G);
688 MOC_EXTERN MSTATUS
DH_setPGQ(MOC_DH(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, ubyte4 lengthY,
diffieHellmanContext *p_dhContext,
const vlong *P,
const vlong *G,
const vlong *Q);
902 ubyte **ppSharedSecret, ubyte4 *pSharedSecretLen);
908 #define DH_EPHEMERAL 2 909 #define DH_HYBRID_ONE_FLOW_U 3 910 #define DH_HYBRID_ONE_FLOW_V 4 913 #define DH_ONE_FLOW_U 7 914 #define DH_ONE_FLOW_V 8 954 MOC_DH(hwAccelDescr hwAccelCtx)
956 randomContext *pRandomContext,
959 ubyte *pOtherPartysStatic,
960 ubyte4 otherStaticLen,
961 ubyte *pOtherPartysEphemeral,
962 ubyte4 otherEphemeralLen,
963 ubyte **ppSharedSecret,
964 ubyte4 *pSharedSecretLen);
1010 ubyte *pSeed, ubyte4 seedSize, intBoolean *pIsValid, ubyte4 *pPriKeyLen, vlong **ppVlongQueue);
1078 MOC_EXTERN MSTATUS
DH_verifyPQ_FIPS1864(MOC_DH(hwAccelDescr hwAccelCtx) randomContext* pFipsRngCtx,
1080 ubyte *pSeed, ubyte4 seedSize, intBoolean *pIsValid, vlong **ppVlongQueue);
1116 MOC_EXTERN MSTATUS DH_allocateServerExt(MOC_DH(hwAccelDescr hwAccelCtx) randomContext *pRandomContext,
diffieHellmanContext **pp_dhContext, ubyte4 groupNum,
void *pExtCtx);
1117 MOC_EXTERN MSTATUS DH_allocateClientAuxExt(MOC_DH(hwAccelDescr hwAccelCtx) randomContext *pRandomContext,
diffieHellmanContext **pp_dhContext, ubyte4 groupNum,
void *pExtCtx);
1118 MOC_EXTERN MSTATUS DH_freeDhContextExt(
diffieHellmanContext **pp_dhContext, vlong **ppVlongQueue,
void *pExtCtx);
1119 MOC_EXTERN MSTATUS DH_setKeyParametersExt(MOC_DH(hwAccelDescr hwAccelCtx)
diffieHellmanContext *pTargetCtx, MDhKeyTemplate *pSrcTemplate,
void *pExtCtx);
1120 MOC_EXTERN MSTATUS DH_getKeyParametersAllocExt(MOC_DH(hwAccelDescr hwAccelCtx) MDhKeyTemplate *pTargetTemplate,
diffieHellmanContext *pSrcCtx, ubyte keyType,
void *pExtCtx);
1121 MOC_EXTERN MSTATUS DH_freeKeyTemplateExt(
diffieHellmanContext *pCtx, MDhKeyTemplate *pTemplate,
void *pExtCtx);
1122 MOC_EXTERN MSTATUS DH_generateKeyPairExt(MOC_DH(hwAccelDescr hwAccelCtx)
diffieHellmanContext *pCtx, randomContext *pRandomContext, ubyte4 numBytes,
void *pExtCtx);
1123 MOC_EXTERN MSTATUS DH_getPublicKeyExt(MOC_DH(hwAccelDescr hwAccelCtx)
diffieHellmanContext *pCtx, ubyte **ppPublicKey, ubyte4 *pPublicKeyLen,
void *pExtCtx);
1124 MOC_EXTERN MSTATUS DH_computeKeyExchangeExExt(MOC_DH(hwAccelDescr hwAccelCtx)
diffieHellmanContext *pCtx, randomContext *pRandomContext, ubyte *pOtherPartysPublicKey,
1125 ubyte4 publicKeyLen, ubyte **ppSharedSecret, ubyte4 *pSharedSecretLen,
void *pExtCtx);
MOC_EXTERN MSTATUS DH_getG(ubyte4 groupNum, vlong **ppRetG)
Get a Generator value for DH calculations.
Context information for an exercise of the DH protocol.
Definition: dh.h:98
vlong * dh_q
Prime Divisor value; see DH_setPGQ().
Definition: dh.h:114
MOC_EXTERN MSTATUS DH_freeKeyTemplate(diffieHellmanContext *pCtx, MDhKeyTemplate *pTemplate)
Zeros and frees each parameter stored in pTemplate.
MOC_EXTERN MSTATUS DH_keyAgreementScheme(MOC_DH(hwAccelDescr hwAccelCtx) ubyte4 mode, randomContext *pRandomContext, diffieHellmanContext *pStatic, diffieHellmanContext *pEphemeral, ubyte *pOtherPartysStatic, ubyte4 otherStaticLen, ubyte *pOtherPartysEphemeral, ubyte4 otherEphemeralLen, ubyte **ppSharedSecret, ubyte4 *pSharedSecretLen)
Generates a Diffie-Hellman shared secret via one of the major modes.
MOC_EXTERN MSTATUS DH_verifySafePG(diffieHellmanContext *pCtx, intBoolean *pIsValid, ubyte4 *pPriKeyLen, vlong **ppVlongQueue)
Validates that the P and G domain parameters come from one of the pre approved safe prime groups...
MOC_EXTERN MSTATUS DH_setPG(MOC_DH(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, ubyte4 lengthY, diffieHellmanContext *p_dhContext, const vlong *P, const vlong *G)
Assign a prime and a generator to an allocated DH context.
vlong * dh_e
Received public key of the remote peer.
Definition: dh.h:129
MOC_EXTERN MSTATUS DH_computeKeyExchangeEx(MOC_DH(hwAccelDescr hwAccelCtx) diffieHellmanContext *pCtx, randomContext *pRandomContext, ubyte *pOtherPartysPublicKey, ubyte4 publicKeyLen, ubyte **ppSharedSecret, ubyte4 *pSharedSecretLen)
Generates a shared secret from the domain parameters and our private key stored in the context...
MOC_EXTERN MSTATUS DH_getPByteString(ubyte4 groupNum, const ubyte **ppBytes, sbyte4 *pLen)
Get a large prime number to use as your DH private key as a Big Endian byte array.
MOC_EXTERN MSTATUS DH_getPublicKey(MOC_DH(hwAccelDescr hwAccelCtx) diffieHellmanContext *pCtx, ubyte **ppPublicKey, ubyte4 *pPublicKeyLen)
This method will allocate a buffer and fill it with our public key in Big Endian binary.
MOC_EXTERN MSTATUS DH_allocate(diffieHellmanContext **pp_dhContext)
Allocate and initialize a diffieHellmanContext structure.
MOC_EXTERN MSTATUS DH_verifyG(MOC_DH(hwAccelDescr hwAccelCtx) diffieHellmanContext *pCtx, intBoolean *pIsValid, vlong **ppVlongQueue)
Verifies the domain parameter G is valid with respect to the P and Q parameters in a diffieHellmanCon...
vlong * dh_f
Public key of the local peer; see DH_setPG().
Definition: dh.h:124
MOC_EXTERN MSTATUS DH_allocateServer(MOC_DH(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, diffieHellmanContext **pp_dhContext, ubyte4 groupNum)
Allocate and initialize resources for a DH server.
MOC_EXTERN MSTATUS DH_allocateClientAux(MOC_DH(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, diffieHellmanContext **pp_dhContext, ubyte4 groupNum)
Allocate and initialize resources for a DH client with the group generator G.
MOC_EXTERN MSTATUS DH_allocateClient(MOC_DH(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, diffieHellmanContext **pp_dhContext, ubyte4 groupNum)
Allocate and initialize resources for a DH client.
vlong * dh_g
Generator value; see DH_getG().
Definition: dh.h:104
MOC_EXTERN MSTATUS DH_freeDhContext(diffieHellmanContext **pp_dhContext, vlong **ppVlongQueue)
Free the memory allocated for a diffieHellmanContext structure.
vlong * dh_y
Private key of the local peer; see DH_setPG().
Definition: dh.h:119
MOC_EXTERN MSTATUS DH_getKeyParametersAlloc(MOC_DH(hwAccelDescr hwAccelCtx) MDhKeyTemplate *pTargetTemplate, diffieHellmanContext *pSrcCtx, ubyte keyType)
For each parameter value g, p, q, y, f that is stored in the pSrcCtx, this method will allocate space...
MOC_EXTERN MSTATUS DH_getP(ubyte4 groupNum, vlong **ppRetP)
Get a large prime number to use as your DH private key.
MOC_EXTERN MSTATUS DH_validateDomainParams(MOC_DH(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, diffieHellmanContext *pCtx, FFCHashType hashType, ubyte4 C, ubyte *pSeed, ubyte4 seedSize, intBoolean *pIsValid, ubyte4 *pPriKeyLen, vlong **ppVlongQueue)
Validates the Diffie-Hellman domain parameters.
vlong * dh_k
Shared secret; see DH_computeKeyExchange().
Definition: dh.h:134
MOC_EXTERN MSTATUS DH_verifyPQ_FIPS1864(MOC_DH(hwAccelDescr hwAccelCtx) randomContext *pFipsRngCtx, diffieHellmanContext *pCtx, FFCHashType hashType, ubyte4 C, ubyte *pSeed, ubyte4 seedSize, intBoolean *pIsValid, vlong **ppVlongQueue)
Verifies the domain parameters P and Q in a context come from the FIPS 186-4 algorithm.
MOC_EXTERN MSTATUS DH_setPGQ(MOC_DH(hwAccelDescr hwAccelCtx) randomContext *pRandomContext, ubyte4 lengthY, diffieHellmanContext *p_dhContext, const vlong *P, const vlong *G, const vlong *Q)
Assign a prime and a generator to an allocated DH context.
MOC_EXTERN MSTATUS DH_computeKeyExchange(MOC_DH(hwAccelDescr hwAccelCtx) diffieHellmanContext *p_dhContext, vlong **ppVlongQueue)
Compute the shared secret.
vlong * dh_p
Large Prime modulus value; see DH_getP().
Definition: dh.h:109
MOC_EXTERN MSTATUS DH_setKeyParameters(MOC_DH(hwAccelDescr hwAccelCtx) diffieHellmanContext *pTargetCtx, MDhKeyTemplate *pSrcTemplate)
Sets the key parameters stored in pSrcTemplate in the pTargetCtx.
MOC_EXTERN MSTATUS DH_generateKeyPair(MOC_DH(hwAccelDescr hwAccelCtx) diffieHellmanContext *pCtx, randomContext *pRandomContext, ubyte4 numBytes)
This method generates a key pair (y,f) within a context that has already had had the domain params p ...