TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptPkcs7Sign.c File Reference
#include "CryptPkcs7Internal.h"
#include <mbedtls/ecdh.h>

Go to the source code of this file.

Macros

#define MAX_SIGNATURE_SIZE   1024
 

Functions

STATIC INT32 MbedTlsPkcs7WriteDigestAlgorithm (UINT8 **Ptr, UINT8 *Start, mbedtls_md_type_t DigestType)
 
STATIC INT32 MbedTlsPkcs7WriteDigestAlgorithmSet (UINT8 **Ptr, UINT8 *Start, mbedtls_md_type_t *DigestTypes, INTN Count)
 
STATIC INT32 MbedTlsPkcs7WriteContentInfo (UINT8 **Ptr, UINT8 *Start, UINT8 *Content, INTN ContentLen)
 
STATIC INT32 MbedTlsPkcs7WriteCertificates (UINT8 **Ptr, UINT8 *Start, mbedtls_x509_crt *Cert, mbedtls_x509_crt *OtherCerts)
 
STATIC INT32 MbedTlsPkcs7WriteInt (UINT8 **Ptr, UINT8 *Start, UINT8 *SerialRaw, INTN SerialRawLen)
 
STATIC INT32 MbedTlsPkcs7WriteIssuerAndSerialNumber (UINT8 **Ptr, UINT8 *Start, UINT8 *Serial, INTN SerialLen, UINT8 *IssuerRaw, INTN IssuerRawLen)
 
STATIC INT32 MbedTlsPkcs7WriteSignerInfo (UINT8 **Ptr, UINT8 *Start, MbedtlsPkcs7SignerInfo *SignerInfo)
 
STATIC INT32 MbedTlsPkcs7WriteSignersInfoSet (UINT8 **Ptr, UINT8 *Start, MbedtlsPkcs7SignerInfo *SignersSet)
 
STATIC INT32 MbedTlsPkcs7WriteDer (UINT8 **Ptr, UINT8 *Start, MbedtlsPkcs7 *Pkcs7)
 
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)
 

Variables

GLOBAL_REMOVE_IF_UNREFERENCED UINT8 MbedtlsOidDigestAlgSha256 [] = MBEDTLS_OID_DIGEST_ALG_SHA256
 
GLOBAL_REMOVE_IF_UNREFERENCED UINT8 MbedtlsOidPkcs1Rsa [] = MBEDTLS_OID_PKCS1_RSA
 

Detailed Description

PKCS#7 SignedData Sign Wrapper and PKCS#7 SignedData Verification Wrapper Implementation over mbedtls.

RFC 8422 - Elliptic Curve Cryptography (ECC) Cipher Suites FIPS 186-4 - Digital Signature Standard (DSS)

Copyright (c) 2024, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file CryptPkcs7Sign.c.

Macro Definition Documentation

◆ MAX_SIGNATURE_SIZE

#define MAX_SIGNATURE_SIZE   1024

Enough to store any signature generated by PKCS7

Definition at line 19 of file CryptPkcs7Sign.c.

Function Documentation

◆ MbedTlsPkcs7WriteCertificates()

STATIC INT32 MbedTlsPkcs7WriteCertificates ( UINT8 **  Ptr,
UINT8 *  Start,
mbedtls_x509_crt *  Cert,
mbedtls_x509_crt *  OtherCerts 
)

certificates :: SET OF ExtendedCertificateOrCertificate, ExtendedCertificateOrCertificate ::= CHOICE { certificate Certificate – x509, extendedCertificate[0] IMPLICIT ExtendedCertificate }.

Parameters
[in,out]PtrThe reference to the current position pointer.
[in]StartThe start of the buffer, for bounds-checking.
[in]CertCertificate.
[in]OtherCertsOhter Certificate.
Return values
numberThe number of bytes written to p on success.
negativeA negative MBEDTLS_ERR_ASN1_XXX error code on failure.

Write OtherCerts

Write Cert

Write NextContext

Definition at line 178 of file CryptPkcs7Sign.c.

◆ MbedTlsPkcs7WriteContentInfo()

STATIC INT32 MbedTlsPkcs7WriteContentInfo ( UINT8 **  Ptr,
UINT8 *  Start,
UINT8 *  Content,
INTN  ContentLen 
)

ContentInfo ::= SEQUENCE { contentType ContentType, content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }.

Parameters
[in,out]PtrThe reference to the current position pointer.
[in]StartThe start of the buffer, for bounds-checking.
[in]ContentContentInfo.
[in]ContentLenSize of ContentInfo.
Return values
numberThe number of bytes written to p on success.
negativeA negative MBEDTLS_ERR_ASN1_XXX error code on failure.

Definition at line 130 of file CryptPkcs7Sign.c.

◆ MbedTlsPkcs7WriteDer()

STATIC INT32 MbedTlsPkcs7WriteDer ( UINT8 **  Ptr,
UINT8 *  Start,
MbedtlsPkcs7 Pkcs7 
)

Signed Data Type SignedData ::= SEQUENCE { version Version, digestAlgorithms DigestAlgorithmIdentifiers, contentInfo ContentInfo, certificates [0] IMPLICIT ExtendedCertificatesAndCertificates OPTIONAL, crls [1] IMPLICIT CertificateRevocationLists OPTIONAL, signerInfos SignerInfos }

DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier

SignerInfos ::= SET OF SignerInfo.

Parameters
[in,out]PtrThe reference to the current position pointer.
[in]StartThe start of the buffer, for bounds-checking.
[in]Pkcs7MbedtlsPkcs7
Return values
numberThe number of bytes written to p on success.
negativeA negative MBEDTLS_ERR_ASN1_XXX error code on failure.

Definition at line 394 of file CryptPkcs7Sign.c.

◆ MbedTlsPkcs7WriteDigestAlgorithm()

STATIC INT32 MbedTlsPkcs7WriteDigestAlgorithm ( UINT8 **  Ptr,
UINT8 *  Start,
mbedtls_md_type_t  DigestType 
)

Write DigestAlgorithmIdentifier.

Parameters
[in,out]PtrThe reference to the current position pointer.
[in]StartThe start of the buffer, for bounds-checking.
[in]DigestTypeDigest Type
Return values
numberThe number of bytes written to p on success.
negativeA negative MBEDTLS_ERR_ASN1_XXX error code on failure.

Definition at line 36 of file CryptPkcs7Sign.c.

◆ MbedTlsPkcs7WriteDigestAlgorithmSet()

STATIC INT32 MbedTlsPkcs7WriteDigestAlgorithmSet ( UINT8 **  Ptr,
UINT8 *  Start,
mbedtls_md_type_t *  DigestTypes,
INTN  Count 
)

DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier.

Parameters
[in,out]PtrThe reference to the current position pointer.
[in]StartThe start of the buffer, for bounds-checking.
[in]DigestTypesDigest Type array.
[in]CountThe index for Digest Type.
Return values
numberThe number of bytes written to p on success.
negativeA negative MBEDTLS_ERR_ASN1_XXX error code on failure.

Definition at line 68 of file CryptPkcs7Sign.c.

◆ MbedTlsPkcs7WriteInt()

STATIC INT32 MbedTlsPkcs7WriteInt ( UINT8 **  Ptr,
UINT8 *  Start,
UINT8 *  SerialRaw,
INTN  SerialRawLen 
)

write Pkcs7 Int.

Parameters
[in,out]PtrThe reference to the current position pointer.
[in]StartThe start of the buffer, for bounds-checking.
[in]SerialRawSerialRaw.
[in]SerialRawLenSize of SerialRaw.
Return values
numberThe number of bytes written to p on success.
negativeA negative MBEDTLS_ERR_ASN1_XXX error code on failure.

Definition at line 220 of file CryptPkcs7Sign.c.

◆ MbedTlsPkcs7WriteIssuerAndSerialNumber()

STATIC INT32 MbedTlsPkcs7WriteIssuerAndSerialNumber ( UINT8 **  Ptr,
UINT8 *  Start,
UINT8 *  Serial,
INTN  SerialLen,
UINT8 *  IssuerRaw,
INTN  IssuerRawLen 
)

write Pkcs7 Issuer And SerialNumber.

Parameters
[in,out]PtrThe reference to the current position pointer.
[in]StartThe start of the buffer, for bounds-checking.
[in]SerialSerial.
[in]SerialLenSize of Serial.
[in]IssuerRawIssuerRawLen.
[in]IssuerRawLenSize of IssuerRawLen.
Return values
numberThe number of bytes written to p on success.
negativeA negative MBEDTLS_ERR_ASN1_XXX error code on failure.

Definition at line 259 of file CryptPkcs7Sign.c.

◆ MbedTlsPkcs7WriteSignerInfo()

STATIC INT32 MbedTlsPkcs7WriteSignerInfo ( UINT8 **  Ptr,
UINT8 *  Start,
MbedtlsPkcs7SignerInfo SignerInfo 
)

SignerInfo ::= SEQUENCE { version Version; issuerAndSerialNumber IssuerAndSerialNumber, digestAlgorithm DigestAlgorithmIdentifier, authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL, digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier, encryptedDigest EncryptedDigest, unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL.

Parameters
[in,out]PtrThe reference to the current position pointer.
[in]StartThe start of the buffer, for bounds-checking.
[in]SignerInfoSignerInfo.
Return values
numberThe number of bytes written to p on success.
negativeA negative MBEDTLS_ERR_ASN1_XXX error code on failure.

Definition at line 303 of file CryptPkcs7Sign.c.

◆ MbedTlsPkcs7WriteSignersInfoSet()

STATIC INT32 MbedTlsPkcs7WriteSignersInfoSet ( UINT8 **  Ptr,
UINT8 *  Start,
MbedtlsPkcs7SignerInfo SignersSet 
)

write Pkcs7 Signers Info Set.

Parameters
[in,out]PtrThe reference to the current position pointer.
[in]StartThe start of the buffer, for bounds-checking.
[in]SignersSetSignerInfo Set.
Return values
numberThe number of bytes written to p on success.
negativeA negative MBEDTLS_ERR_ASN1_XXX error code on failure.

Definition at line 342 of file CryptPkcs7Sign.c.

◆ Pkcs7Sign()

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 
)

Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message Syntax Standard, version 1.5". This interface is only intended to be used for application to perform PKCS#7 functionality validation.

If this interface is not supported, then return FALSE.

Parameters
[in]PrivateKeyPointer to the PEM-formatted private key data for data signing.
[in]PrivateKeySizeSize of the PEM private key data in bytes.
[in]KeyPasswordNULL-terminated passphrase used for encrypted PEM key data.
[in]InDataPointer to the content to be signed.
[in]InDataSizeSize of InData in bytes.
[in]SignCertPointer to signer's DER-encoded certificate to sign with.
[in]OtherCertsPointer to an optional additional set of certificates to include in the PKCS#7 signedData (e.g. any intermediate CAs in the chain).
[out]SignedDataPointer to output PKCS#7 signedData. It's caller's responsibility to free the buffer with FreePool().
[out]SignedDataSizeSize of SignedData in bytes.
Return values
TRUEPKCS#7 data signing succeeded.
FALSEPKCS#7 data signing failed.
FALSEThis interface is not supported.

Calculate InData Digest

Pk Sign

Enlarge buffer if buffer is too small

Definition at line 452 of file CryptPkcs7Sign.c.

Variable Documentation

◆ MbedtlsOidDigestAlgSha256

GLOBAL_REMOVE_IF_UNREFERENCED UINT8 MbedtlsOidDigestAlgSha256[] = MBEDTLS_OID_DIGEST_ALG_SHA256

Definition at line 21 of file CryptPkcs7Sign.c.

◆ MbedtlsOidPkcs1Rsa

GLOBAL_REMOVE_IF_UNREFERENCED UINT8 MbedtlsOidPkcs1Rsa[] = MBEDTLS_OID_PKCS1_RSA

Definition at line 22 of file CryptPkcs7Sign.c.