TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptDh.c File Reference
#include "InternalCryptLib.h"
#include <openssl/bn.h>
#include <openssl/dh.h>

Go to the source code of this file.

Functions

VOID *EFIAPI DhNew (VOID)
 
VOID EFIAPI DhFree (IN VOID *DhContext)
 
BOOLEAN EFIAPI DhGenerateParameter (IN OUT VOID *DhContext, IN UINTN Generator, IN UINTN PrimeLength, OUT UINT8 *Prime)
 
BOOLEAN EFIAPI DhSetParameter (IN OUT VOID *DhContext, IN UINTN Generator, IN UINTN PrimeLength, IN CONST UINT8 *Prime)
 
BOOLEAN EFIAPI DhGenerateKey (IN OUT VOID *DhContext, OUT UINT8 *PublicKey, IN OUT UINTN *PublicKeySize)
 
BOOLEAN EFIAPI DhComputeKey (IN OUT VOID *DhContext, IN CONST UINT8 *PeerPublicKey, IN UINTN PeerPublicKeySize, OUT UINT8 *Key, IN OUT UINTN *KeySize)
 

Detailed Description

Diffie-Hellman Wrapper Implementation over OpenSSL.

Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CryptDh.c.

Function Documentation

◆ DhComputeKey()

BOOLEAN EFIAPI DhComputeKey ( IN OUT VOID *  DhContext,
IN CONST UINT8 *  PeerPublicKey,
IN UINTN  PeerPublicKeySize,
OUT UINT8 *  Key,
IN OUT UINTN KeySize 
)

Computes exchanged common key.

Given peer's public key, this function computes the exchanged common key, based on its own context including value of prime modulus and random secret exponent.

If DhContext is NULL, then return FALSE. If PeerPublicKey is NULL, then return FALSE. If KeySize is NULL, then return FALSE. If Key is NULL, then return FALSE. If KeySize is not large enough, then return FALSE.

Parameters
[in,out]DhContextPointer to the DH context.
[in]PeerPublicKeyPointer to the peer's public key.
[in]PeerPublicKeySizeSize of peer's public key in bytes.
[out]KeyPointer to the buffer to receive generated key.
[in,out]KeySizeOn input, the size of Key buffer in bytes. On output, the size of data returned in Key buffer in bytes.
Return values
TRUEDH exchanged key generation succeeded.
FALSEDH exchanged key generation failed.
FALSEKeySize is not large enough.

Definition at line 265 of file CryptDh.c.

◆ DhFree()

VOID EFIAPI DhFree ( IN VOID *  DhContext)

Release the specified DH context.

If DhContext is NULL, then return FALSE.

Parameters
[in]DhContextPointer to the DH context to be released.

Definition at line 42 of file CryptDh.c.

◆ DhGenerateKey()

BOOLEAN EFIAPI DhGenerateKey ( IN OUT VOID *  DhContext,
OUT UINT8 *  PublicKey,
IN OUT UINTN PublicKeySize 
)

Generates DH public key.

This function generates random secret exponent, and computes the public key, which is returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly. If the PublicKey buffer is too small to hold the public key, FALSE is returned and PublicKeySize is set to the required buffer size to obtain the public key.

If DhContext is NULL, then return FALSE. If PublicKeySize is NULL, then return FALSE. If PublicKeySize is large enough but PublicKey is NULL, then return FALSE.

Parameters
[in,out]DhContextPointer to the DH context.
[out]PublicKeyPointer to the buffer to receive generated public key.
[in,out]PublicKeySizeOn input, the size of PublicKey buffer in bytes. On output, the size of data returned in PublicKey buffer in bytes.
Return values
TRUEDH public key generation succeeded.
FALSEDH public key generation failed.
FALSEPublicKeySize is not large enough.

Definition at line 196 of file CryptDh.c.

◆ DhGenerateParameter()

BOOLEAN EFIAPI DhGenerateParameter ( IN OUT VOID *  DhContext,
IN UINTN  Generator,
IN UINTN  PrimeLength,
OUT UINT8 *  Prime 
)

Generates DH parameter.

Given generator g, and length of prime number p in bits, this function generates p, and sets DH context according to value of g and p.

Before this function can be invoked, pseudorandom number generator must be correctly initialized by RandomSeed().

If DhContext is NULL, then return FALSE. If Prime is NULL, then return FALSE.

Parameters
[in,out]DhContextPointer to the DH context.
[in]GeneratorValue of generator.
[in]PrimeLengthLength in bits of prime to be generated.
[out]PrimePointer to the buffer to receive the generated prime number.
Return values
TRUEDH parameter generation succeeded.
FALSEValue of Generator is not supported.
FALSEPRNG fails to generate random prime number with PrimeLength.

Definition at line 76 of file CryptDh.c.

◆ DhNew()

VOID *EFIAPI DhNew ( VOID  )

Allocates and Initializes one Diffie-Hellman Context for subsequent use.

Returns
Pointer to the Diffie-Hellman Context that has been initialized. If the allocations fails, DhNew() returns NULL.

Definition at line 22 of file CryptDh.c.

◆ DhSetParameter()

BOOLEAN EFIAPI DhSetParameter ( IN OUT VOID *  DhContext,
IN UINTN  Generator,
IN UINTN  PrimeLength,
IN CONST UINT8 *  Prime 
)

Sets generator and prime parameters for DH.

Given generator g, and prime number p, this function and sets DH context accordingly.

If DhContext is NULL, then return FALSE. If Prime is NULL, then return FALSE.

Parameters
[in,out]DhContextPointer to the DH context.
[in]GeneratorValue of generator.
[in]PrimeLengthLength in bits of prime to be generated.
[in]PrimePointer to the prime number.
Return values
TRUEDH parameter setting succeeded.
FALSEValue of Generator is not supported.
FALSEValue of Generator is not suitable for the Prime.
FALSEValue of Prime is not a prime number.
FALSEValue of Prime is not a safe prime number.

Definition at line 131 of file CryptDh.c.