9#include "InternalCryptLib.h"
10#include <mbedtls/pem.h>
11#include <mbedtls/pk.h>
12#include <mbedtls/rsa.h>
13#include <mbedtls/ecp.h>
14#include <mbedtls/ecdh.h>
15#include <mbedtls/ecdsa.h>
44 mbedtls_pk_context Pk;
45 mbedtls_rsa_context *Rsa;
49 if ((PemData ==
NULL) || (RsaContext ==
NULL) || (PemSize > INT_MAX)) {
54 if (PemData[PemSize - 1] != 0) {
56 if (NewPemData ==
NULL) {
60 CopyMem (NewPemData, PemData, PemSize + 1);
61 NewPemData[PemSize] = 0;
66 mbedtls_pk_init (&Pk);
68 if (Password !=
NULL) {
74 Ret = mbedtls_pk_parse_key (&Pk, PemData, PemSize, (
CONST UINT8 *)Password, PasswordLen,
NULL,
NULL);
76 if (NewPemData !=
NULL) {
82 mbedtls_pk_free (&Pk);
86 if (mbedtls_pk_get_type (&Pk) != MBEDTLS_PK_RSA) {
87 mbedtls_pk_free (&Pk);
93 mbedtls_pk_free (&Pk);
97 Ret = mbedtls_rsa_copy (Rsa, mbedtls_pk_rsa (Pk));
100 mbedtls_pk_free (&Pk);
104 mbedtls_pk_free (&Pk);
VOID *EFIAPI RsaNew(VOID)
VOID EFIAPI RsaFree(IN VOID *RsaContext)
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
BOOLEAN EFIAPI RsaGetPrivateKeyFromPem(IN CONST UINT8 *PemData, IN UINTN PemSize, IN CONST CHAR8 *Password, OUT VOID **RsaContext)
BOOLEAN EFIAPI EcGetPrivateKeyFromPem(IN CONST UINT8 *PemData, IN UINTN PemSize, IN CONST CHAR8 *Password, OUT VOID **EcContext)