10#include "InternalCryptLib.h"
11#include <mbedtls/rsa.h>
12#include <mbedtls/x509_crt.h>
51 IN CONST UINT8 *PrngSeed OPTIONAL,
53 OUT UINT8 **EncryptedData,
60 mbedtls_x509_crt CertContext;
61 mbedtls_rsa_context RsaContext;
66 if ((PublicKey ==
NULL) || (InData ==
NULL) ||
67 (EncryptedData ==
NULL) || (EncryptedDataSize ==
NULL))
75 if (PublicKeySize > UINT_MAX) {
82 *EncryptedData =
NULL;
83 *EncryptedDataSize = 0;
87 mbedtls_x509_crt_init (&CertContext);
89 if (mbedtls_x509_crt_parse_der (&CertContext, PublicKey, (UINT32)PublicKeySize) != 0) {
93 if (mbedtls_pk_get_type (&CertContext.pk) != MBEDTLS_PK_RSA) {
97 mbedtls_rsa_init (&RsaContext);
98 if (mbedtls_rsa_set_padding (&RsaContext, MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_NONE) != 0) {
102 Ret = mbedtls_rsa_copy (&RsaContext, mbedtls_pk_rsa (CertContext.pk));
107 *EncryptedDataSize = RsaContext.len;
113 if (OutData ==
NULL) {
120 Ret = mbedtls_rsa_pkcs1_encrypt (
134 *EncryptedData = OutData;
141 if (&CertContext !=
NULL) {
142 mbedtls_x509_crt_free (&CertContext);
145 if (&RsaContext !=
NULL) {
146 mbedtls_rsa_free (&RsaContext);
191 IN CONST UINT8 *PrngSeed OPTIONAL,
192 IN UINTN PrngSeedSize OPTIONAL,
193 IN UINT16 DigestLen OPTIONAL,
194 OUT UINT8 **EncryptedData,
228 IN UINT8 *EncryptedData,
269 IN UINT8 *EncryptedData,
271 IN UINT16 DigestLen OPTIONAL,
INT32 MbedtlsRand(VOID *RngState, UINT8 *Output, UINTN Len)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
BOOLEAN EFIAPI Pkcs1v2Encrypt(IN CONST UINT8 *PublicKey, IN UINTN PublicKeySize, IN UINT8 *InData, IN UINTN InDataSize, IN CONST UINT8 *PrngSeed OPTIONAL, IN UINTN PrngSeedSize OPTIONAL, OUT UINT8 **EncryptedData, OUT UINTN *EncryptedDataSize)
BOOLEAN EFIAPI RsaOaepEncrypt(IN VOID *RsaContext, IN UINT8 *InData, IN UINTN InDataSize, IN CONST UINT8 *PrngSeed OPTIONAL, IN UINTN PrngSeedSize OPTIONAL, IN UINT16 DigestLen OPTIONAL, OUT UINT8 **EncryptedData, OUT UINTN *EncryptedDataSize)
BOOLEAN EFIAPI RsaOaepDecrypt(IN VOID *RsaContext, IN UINT8 *EncryptedData, IN UINTN EncryptedDataSize, IN UINT16 DigestLen OPTIONAL, OUT UINT8 **OutData, OUT UINTN *OutDataSize)
BOOLEAN EFIAPI Pkcs1v2Decrypt(IN CONST UINT8 *PrivateKey, IN UINTN PrivateKeySize, IN UINT8 *EncryptedData, IN UINTN EncryptedDataSize, OUT UINT8 **OutData, OUT UINTN *OutDataSize)