9#include "InternalCryptLib.h"
10#include <openssl/pem.h>
39 KeyLength = (KeyLength > Size) ? Size : KeyLength;
79 if ((PemData ==
NULL) || (RsaContext ==
NULL) || (PemSize > INT_MAX)) {
87 if (EVP_add_cipher (EVP_aes_128_cbc ()) == 0) {
91 if (EVP_add_cipher (EVP_aes_192_cbc ()) == 0) {
95 if (EVP_add_cipher (EVP_aes_256_cbc ()) == 0) {
104 PemBio = BIO_new (BIO_s_mem ());
105 if (PemBio ==
NULL) {
109 if (BIO_write (PemBio, PemData, (
int)PemSize) <= 0) {
116 *RsaContext = PEM_read_bio_RSAPrivateKey (PemBio,
NULL, (pem_password_cb *)&
PasswordCallback, (
void *)Password);
117 if (*RsaContext !=
NULL) {
162 if ((PemData ==
NULL) || (EcContext ==
NULL) || (PemSize > INT_MAX)) {
170 if (EVP_add_cipher (EVP_aes_128_cbc ()) == 0) {
174 if (EVP_add_cipher (EVP_aes_192_cbc ()) == 0) {
178 if (EVP_add_cipher (EVP_aes_256_cbc ()) == 0) {
187 PemBio = BIO_new (BIO_s_mem ());
188 if (PemBio ==
NULL) {
192 if (BIO_write (PemBio, PemData, (
int)PemSize) <= 0) {
199 *EcContext = PEM_read_bio_ECPrivateKey (PemBio,
NULL, (pem_password_cb *)&
PasswordCallback, (
void *)Password);
200 if (*EcContext !=
NULL) {
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
INTN PasswordCallback(OUT CHAR8 *Buf, IN INTN Size, IN INTN Flag, IN VOID *Key)
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)