9#include "InternalCryptLib.h"
11#include <openssl/objects.h>
12#include <openssl/x509.h>
13#include <openssl/pkcs7.h>
48 IN UINT8 *OtherCerts OPTIONAL,
49 OUT UINT8 **SignedData,
65 if ((PrivateKey ==
NULL) || (KeyPassword ==
NULL) || (InData ==
NULL) ||
66 (SignCert ==
NULL) || (SignedData ==
NULL) || (SignedDataSize ==
NULL) || (InDataSize > INT_MAX))
83 (
CONST CHAR8 *)KeyPassword,
95 if (EVP_add_digest (EVP_md5 ()) == 0) {
99 if (EVP_add_digest (EVP_sha1 ()) == 0) {
103 if (EVP_add_digest (EVP_sha256 ()) == 0) {
112 Key = EVP_PKEY_new ();
117 if (EVP_PKEY_assign_RSA (Key, (RSA *)RsaContext) == 0) {
124 DataBio = BIO_new (BIO_s_mem ());
125 if (DataBio ==
NULL) {
129 if (BIO_write (DataBio, InData, (
int)InDataSize) <= 0) {
139 (STACK_OF (X509) *) OtherCerts,
141 PKCS7_BINARY | PKCS7_NOATTR | PKCS7_DETACHED
150 P7DataSize = i2d_PKCS7 (Pkcs7,
NULL);
151 if (P7DataSize <= 19) {
155 P7Data = malloc (P7DataSize);
156 if (P7Data ==
NULL) {
161 P7DataSize = i2d_PKCS7 (Pkcs7, (
unsigned char **)&Tmp);
162 ASSERT (P7DataSize > 19);
168 *SignedDataSize = P7DataSize - 19;
170 if (*SignedData ==
NULL) {
171 OPENSSL_free (P7Data);
175 CopyMem (*SignedData, P7Data + 19, *SignedDataSize);
177 OPENSSL_free (P7Data);
189 if (DataBio !=
NULL) {
BOOLEAN EFIAPI RsaGetPrivateKeyFromPem(IN CONST UINT8 *PemData, IN UINTN PemSize, IN CONST CHAR8 *Password, OUT VOID **RsaContext)
BOOLEAN EFIAPI RandomSeed(IN CONST UINT8 *Seed OPTIONAL, IN UINTN SeedSize)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI Pkcs7Sign(IN CONST UINT8 *PrivateKey, IN UINTN PrivateKeySize, IN CONST UINT8 *KeyPassword, IN UINT8 *InData, IN UINTN InDataSize, IN UINT8 *SignCert, IN UINT8 *OtherCerts OPTIONAL, OUT UINT8 **SignedData, OUT UINTN *SignedDataSize)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)