9#include "InternalCryptLib.h"
10#include <openssl/bn.h>
11#include <openssl/dh.h>
29 return (VOID *)DH_new ();
49 DH_free ((DH *)DhContext);
77 IN OUT VOID *DhContext,
89 if ((DhContext ==
NULL) || (Prime ==
NULL) || (PrimeLength > INT_MAX)) {
97 RetVal = (BOOLEAN)DH_generate_parameters_ex (DhContext, (UINT32)PrimeLength, (UINT32)
Generator,
NULL);
102 DH_get0_pqg (DhContext, (
const BIGNUM **)&BnP,
NULL,
NULL);
103 BN_bn2bin (BnP, Prime);
132 IN OUT VOID *DhContext,
145 if ((DhContext ==
NULL) || (Prime ==
NULL) || (PrimeLength > INT_MAX)) {
156 Dh = (DH *)DhContext;
157 BnP = BN_bin2bn ((
const unsigned char *)Prime, (
int)(PrimeLength / 8),
NULL);
158 BnG = BN_bin2bn ((
const unsigned char *)&
Generator, 1,
NULL);
159 if ((BnP ==
NULL) || (BnG ==
NULL) || !DH_set0_pqg (Dh, BnP,
NULL, BnG)) {
197 IN OUT VOID *DhContext,
198 OUT UINT8 *PublicKey,
210 if ((DhContext ==
NULL) || (PublicKeySize ==
NULL)) {
214 if ((PublicKey ==
NULL) && (*PublicKeySize != 0)) {
218 Dh = (DH *)DhContext;
220 RetVal = (BOOLEAN)DH_generate_key (DhContext);
222 DH_get0_key (Dh, (
const BIGNUM **)&DhPubKey,
NULL);
223 Size = BN_num_bytes (DhPubKey);
224 if ((Size > 0) && (*PublicKeySize < (
UINTN)Size)) {
225 *PublicKeySize = Size;
229 if (PublicKey !=
NULL) {
230 BN_bn2bin (DhPubKey, PublicKey);
233 *PublicKeySize = Size;
266 IN OUT VOID *DhContext,
279 if ((DhContext ==
NULL) || (PeerPublicKey ==
NULL) || (KeySize ==
NULL) || (Key ==
NULL)) {
283 if (PeerPublicKeySize > INT_MAX) {
287 Bn = BN_bin2bn (PeerPublicKey, (UINT32)PeerPublicKeySize,
NULL);
292 Size = DH_compute_key (Key, Bn, DhContext);
298 if (*KeySize < (
UINTN)Size) {
BOOLEAN EFIAPI DhGenerateParameter(IN OUT VOID *DhContext, IN UINTN Generator, IN UINTN PrimeLength, OUT UINT8 *Prime)
BOOLEAN EFIAPI DhGenerateKey(IN OUT VOID *DhContext, OUT UINT8 *PublicKey, IN OUT UINTN *PublicKeySize)
VOID EFIAPI DhFree(IN VOID *DhContext)
BOOLEAN EFIAPI DhSetParameter(IN OUT VOID *DhContext, IN UINTN Generator, IN UINTN PrimeLength, IN CONST UINT8 *Prime)
BOOLEAN EFIAPI DhComputeKey(IN OUT VOID *DhContext, IN CONST UINT8 *PeerPublicKey, IN UINTN PeerPublicKeySize, OUT UINT8 *Key, IN OUT UINTN *KeySize)