TianoCore EDK2 master
|
#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) |
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.
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.
[in,out] | DhContext | Pointer to the DH context. |
[in] | PeerPublicKey | Pointer to the peer's public key. |
[in] | PeerPublicKeySize | Size of peer's public key in bytes. |
[out] | Key | Pointer to the buffer to receive generated key. |
[in,out] | KeySize | On input, the size of Key buffer in bytes. On output, the size of data returned in Key buffer in bytes. |
TRUE | DH exchanged key generation succeeded. |
FALSE | DH exchanged key generation failed. |
FALSE | KeySize is not large enough. |
VOID EFIAPI DhFree | ( | IN VOID * | DhContext | ) |
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.
[in,out] | DhContext | Pointer to the DH context. |
[out] | PublicKey | Pointer to the buffer to receive generated public key. |
[in,out] | PublicKeySize | On input, the size of PublicKey buffer in bytes. On output, the size of data returned in PublicKey buffer in bytes. |
TRUE | DH public key generation succeeded. |
FALSE | DH public key generation failed. |
FALSE | PublicKeySize is not large enough. |
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.
[in,out] | DhContext | Pointer to the DH context. |
[in] | Generator | Value of generator. |
[in] | PrimeLength | Length in bits of prime to be generated. |
[out] | Prime | Pointer to the buffer to receive the generated prime number. |
TRUE | DH parameter generation succeeded. |
FALSE | Value of Generator is not supported. |
FALSE | PRNG fails to generate random prime number with PrimeLength. |
VOID *EFIAPI DhNew | ( | VOID | ) |
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.
[in,out] | DhContext | Pointer to the DH context. |
[in] | Generator | Value of generator. |
[in] | PrimeLength | Length in bits of prime to be generated. |
[in] | Prime | Pointer to the prime number. |