pkcs7_format.c File Reference

PKCS #7 message formatting. More...

Go to the source code of this file.

Macros

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL
 

Functions

error_t pkcs7FormatContentInfo (const Pkcs7ContentInfo *contentInfo, uint8_t *output, size_t *written)
 Format contentInfo structure. More...
 
error_t pkcs7FormatSignedData (const PrngAlgo *prngAlgo, void *prngContext, const Pkcs7SignedData *signedData, const void *signerPrivateKey, uint8_t *output, size_t *written)
 Format signed-data content. More...
 
error_t pkcs7FormatEnvelopedData (const PrngAlgo *prngAlgo, void *prngContext, const X509CertInfo *recipientCertInfo, const Pkcs7EnvelopedData *envelopedData, const uint8_t *plaintext, size_t plaintextLen, uint8_t *output, size_t *written)
 Format enveloped-data content. More...
 
error_t pkcs7FormatDigestAlgos (const Pkcs7DigestAlgos *digestAlgos, uint8_t *output, size_t *written)
 Format digestAlgos structure. More...
 
error_t pkcs7FormatCertificates (const Pkcs7Certificates *certificates, uint8_t *output, size_t *written)
 Format certificates. More...
 
error_t pkcs7FormatCrls (const Pkcs7Crls *crls, uint8_t *output, size_t *written)
 Format CRLs. More...
 
error_t pkcs7FormatSignerInfos (const PrngAlgo *prngAlgo, void *prngContext, const Pkcs7SignerInfos *signerInfos, const void *signerPrivateKey, uint8_t *output, size_t *written)
 Format SignerInfos structure. More...
 
error_t pkcs7FormatSignerInfo (const PrngAlgo *prngAlgo, void *prngContext, const Pkcs7SignerInfo *signerInfo, const void *signerPrivateKey, uint8_t *output, size_t *written)
 Format SignerInfo structure. More...
 
error_t pkcs7FormatIssuerAndSerialNumber (const Pkcs7IssuerAndSerialNumber *issuerAndSerialNumber, uint8_t *output, size_t *written)
 Format IssuerAndSerialNumber structure. More...
 
error_t pkcs7FormatAuthenticatedAttributes (const Pkcs7AuthenticatedAttributes *authenticatedAttributes, uint8_t *output, size_t *written)
 Format authenticatedAttributes structure. More...
 
error_t pkcs7FormatDigestEncryptionAlgo (const X509SignAlgoId *digestEncryptionAlgo, uint8_t *output, size_t *written)
 Format digestEncryptionAlgorithm structure. More...
 
error_t pkcs7FormatEncryptedDigest (const PrngAlgo *prngAlgo, void *prngContext, const uint8_t *digest, const Pkcs7SignerInfo *signerInfo, const void *signerPrivateKey, uint8_t *output, size_t *written)
 Format encryptedDigest structure. More...
 
error_t pkcs7FormatUnauthenticatedAttributes (const Pkcs7UnauthenticatedAttributes *unauthenticatedAttributes, uint8_t *output, size_t *written)
 Format unauthenticatedAttributes structure. More...
 
error_t pkcs7FormatAttribute (const Pkcs7Attribute *attribute, uint8_t *output, size_t *written)
 Format attribute. More...
 
error_t pkcs7AddAttribute (const Pkcs7Attribute *attribute, uint8_t *attributes, size_t *length)
 Add attribute. More...
 
error_t pkcs7FormatRecipientInfos (const PrngAlgo *prngAlgo, void *prngContext, const Pkcs7RecipientInfos *recipientInfos, const X509CertInfo *recipientCertInfo, const uint8_t *key, size_t keyLen, uint8_t *output, size_t *written)
 Format recipientInfos structure. More...
 
error_t pkcs7FormatRecipientInfo (const PrngAlgo *prngAlgo, void *prngContext, const Pkcs7RecipientInfo *recipientInfo, const X509CertInfo *recipientCertInfo, const uint8_t *key, size_t keyLen, uint8_t *output, size_t *written)
 Format RecipientInfo structure. More...
 
error_t pkcs7FormatEncryptedKey (const PrngAlgo *prngAlgo, void *prngContext, const X509CertInfo *recipientCertInfo, const uint8_t *key, size_t keyLen, uint8_t *output, size_t *written)
 Format encryptedKey structure. More...
 
error_t pkcs7FormatEncryptedContentInfo (const Pkcs7EncryptedContentInfo *encryptedContentInfo, const uint8_t *key, size_t keyLen, const uint8_t *plaintext, size_t plaintextLen, uint8_t *output, size_t *written)
 Format encryptedContentInfo structure. More...
 
error_t pkcs7FormatContentEncrAlgo (const Pkcs7ContentEncrAlgo *contentEncrAlgo, uint8_t *output, size_t *written)
 Format contentEncryptionAlgorithm structure. More...
 
error_t pkcs7FormatAlgoId (const X509AlgoId *algoId, uint8_t *output, size_t *written)
 Format AlgorithmIdentifier structure. More...
 

Detailed Description

PKCS #7 message formatting.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneCRYPTO Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.5.2

Definition in file pkcs7_format.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   CRYPTO_TRACE_LEVEL

Definition at line 32 of file pkcs7_format.c.

Function Documentation

◆ pkcs7AddAttribute()

error_t pkcs7AddAttribute ( const Pkcs7Attribute attribute,
uint8_t *  attributes,
size_t *  length 
)

Add attribute.

Parameters
[in]attributePointer to the attribute to add
[in]attributesPointer to the list of attributes
[in,out]lengthActual length of the list of attributes
Returns
Error code

Definition at line 1408 of file pkcs7_format.c.

◆ pkcs7FormatAlgoId()

error_t pkcs7FormatAlgoId ( const X509AlgoId algoId,
uint8_t *  output,
size_t *  written 
)

Format AlgorithmIdentifier structure.

Parameters
[in]algoIdPointer to the structure to format
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1865 of file pkcs7_format.c.

◆ pkcs7FormatAttribute()

error_t pkcs7FormatAttribute ( const Pkcs7Attribute attribute,
uint8_t *  output,
size_t *  written 
)

Format attribute.

Parameters
[in]attributePointer to the attribute to format
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1321 of file pkcs7_format.c.

◆ pkcs7FormatAuthenticatedAttributes()

error_t pkcs7FormatAuthenticatedAttributes ( const Pkcs7AuthenticatedAttributes authenticatedAttributes,
uint8_t *  output,
size_t *  written 
)

Format authenticatedAttributes structure.

Parameters
[in]authenticatedAttributesPointer to the structure to format
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 962 of file pkcs7_format.c.

◆ pkcs7FormatCertificates()

error_t pkcs7FormatCertificates ( const Pkcs7Certificates certificates,
uint8_t *  output,
size_t *  written 
)

Format certificates.

Parameters
[in]certificatesPointer to the structure to format
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 525 of file pkcs7_format.c.

◆ pkcs7FormatContentEncrAlgo()

error_t pkcs7FormatContentEncrAlgo ( const Pkcs7ContentEncrAlgo contentEncrAlgo,
uint8_t *  output,
size_t *  written 
)

Format contentEncryptionAlgorithm structure.

Parameters
[in]contentEncrAlgoPointer to the structure to format
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1789 of file pkcs7_format.c.

◆ pkcs7FormatContentInfo()

error_t pkcs7FormatContentInfo ( const Pkcs7ContentInfo contentInfo,
uint8_t *  output,
size_t *  written 
)

Format contentInfo structure.

Parameters
[in]contentInfoPointer to the structure to format
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 57 of file pkcs7_format.c.

◆ pkcs7FormatCrls()

error_t pkcs7FormatCrls ( const Pkcs7Crls crls,
uint8_t *  output,
size_t *  written 
)

Format CRLs.

Parameters
[in]crlsPointer to the structure to format
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 610 of file pkcs7_format.c.

◆ pkcs7FormatDigestAlgos()

error_t pkcs7FormatDigestAlgos ( const Pkcs7DigestAlgos digestAlgos,
uint8_t *  output,
size_t *  written 
)

Format digestAlgos structure.

Parameters
[in]digestAlgosPointer to the structure to format
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 466 of file pkcs7_format.c.

◆ pkcs7FormatDigestEncryptionAlgo()

error_t pkcs7FormatDigestEncryptionAlgo ( const X509SignAlgoId digestEncryptionAlgo,
uint8_t *  output,
size_t *  written 
)

Format digestEncryptionAlgorithm structure.

Parameters
[in]digestEncryptionAlgoPointer to the structure to format
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1096 of file pkcs7_format.c.

◆ pkcs7FormatEncryptedContentInfo()

error_t pkcs7FormatEncryptedContentInfo ( const Pkcs7EncryptedContentInfo encryptedContentInfo,
const uint8_t *  key,
size_t  keyLen,
const uint8_t *  plaintext,
size_t  plaintextLen,
uint8_t *  output,
size_t *  written 
)

Format encryptedContentInfo structure.

Parameters
[in]encryptedContentInfoPointer to the structure to format
[in]keyPointer to the encryption key
[in]keyLenLength of the encryption key, in bytes
[in]plaintextPointer to the message to be encrypted
[in]plaintextLenLength of the message, in bytes
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1689 of file pkcs7_format.c.

◆ pkcs7FormatEncryptedDigest()

error_t pkcs7FormatEncryptedDigest ( const PrngAlgo prngAlgo,
void *  prngContext,
const uint8_t *  digest,
const Pkcs7SignerInfo signerInfo,
const void *  signerPrivateKey,
uint8_t *  output,
size_t *  written 
)

Format encryptedDigest structure.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]digestMessage digest
[in]signerInfoPointer to the signer information
[in]signerPrivateKeyPointer to the signer's private key
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1215 of file pkcs7_format.c.

◆ pkcs7FormatEncryptedKey()

error_t pkcs7FormatEncryptedKey ( const PrngAlgo prngAlgo,
void *  prngContext,
const X509CertInfo recipientCertInfo,
const uint8_t *  key,
size_t  keyLen,
uint8_t *  output,
size_t *  written 
)

Format encryptedKey structure.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]recipientCertInfoRecipient's certificate
[in]keyPointer to the encryption key
[in]keyLenLength of the encryption key, in bytes
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1641 of file pkcs7_format.c.

◆ pkcs7FormatEnvelopedData()

error_t pkcs7FormatEnvelopedData ( const PrngAlgo prngAlgo,
void *  prngContext,
const X509CertInfo recipientCertInfo,
const Pkcs7EnvelopedData envelopedData,
const uint8_t *  plaintext,
size_t  plaintextLen,
uint8_t *  output,
size_t *  written 
)

Format enveloped-data content.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]recipientCertInfoRecipient's certificate
[in]envelopedDataPointer to the structure to format
[in]plaintextPointer to the message to be encrypted
[in]plaintextLenLength of the message, in bytes
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 349 of file pkcs7_format.c.

◆ pkcs7FormatIssuerAndSerialNumber()

error_t pkcs7FormatIssuerAndSerialNumber ( const Pkcs7IssuerAndSerialNumber issuerAndSerialNumber,
uint8_t *  output,
size_t *  written 
)

Format IssuerAndSerialNumber structure.

Parameters
[in]issuerAndSerialNumberPointer to the structure to format
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 899 of file pkcs7_format.c.

◆ pkcs7FormatRecipientInfo()

error_t pkcs7FormatRecipientInfo ( const PrngAlgo prngAlgo,
void *  prngContext,
const Pkcs7RecipientInfo recipientInfo,
const X509CertInfo recipientCertInfo,
const uint8_t *  key,
size_t  keyLen,
uint8_t *  output,
size_t *  written 
)

Format RecipientInfo structure.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]recipientInfoPointer to the structure to format
[in]recipientCertInfoRecipient's certificate
[in]keyPointer to the encryption key
[in]keyLenLength of the encryption key, in bytes
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1552 of file pkcs7_format.c.

◆ pkcs7FormatRecipientInfos()

error_t pkcs7FormatRecipientInfos ( const PrngAlgo prngAlgo,
void *  prngContext,
const Pkcs7RecipientInfos recipientInfos,
const X509CertInfo recipientCertInfo,
const uint8_t *  key,
size_t  keyLen,
uint8_t *  output,
size_t *  written 
)

Format recipientInfos structure.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]recipientInfosPointer to the structure to format
[in]recipientCertInfoRecipient's certificate
[in]keyPointer to the encryption key
[in]keyLenLength of the encryption key, in bytes
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1486 of file pkcs7_format.c.

◆ pkcs7FormatSignedData()

error_t pkcs7FormatSignedData ( const PrngAlgo prngAlgo,
void *  prngContext,
const Pkcs7SignedData signedData,
const void *  signerPrivateKey,
uint8_t *  output,
size_t *  written 
)

Format signed-data content.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]signedDataPointer to the structure to format
[in]signerPrivateKeyPointer to the signer's private key
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 205 of file pkcs7_format.c.

◆ pkcs7FormatSignerInfo()

error_t pkcs7FormatSignerInfo ( const PrngAlgo prngAlgo,
void *  prngContext,
const Pkcs7SignerInfo signerInfo,
const void *  signerPrivateKey,
uint8_t *  output,
size_t *  written 
)

Format SignerInfo structure.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]signerInfoPointer to the structure to format
[in]signerPrivateKeyPointer to the signer's private key
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 761 of file pkcs7_format.c.

◆ pkcs7FormatSignerInfos()

error_t pkcs7FormatSignerInfos ( const PrngAlgo prngAlgo,
void *  prngContext,
const Pkcs7SignerInfos signerInfos,
const void *  signerPrivateKey,
uint8_t *  output,
size_t *  written 
)

Format SignerInfos structure.

Parameters
[in]prngAlgoPRNG algorithm
[in]prngContextPointer to the PRNG context
[in]signerInfosPointer to the structure to format
[in]signerPrivateKeyPointer to the signer's private key
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 697 of file pkcs7_format.c.

◆ pkcs7FormatUnauthenticatedAttributes()

error_t pkcs7FormatUnauthenticatedAttributes ( const Pkcs7UnauthenticatedAttributes unauthenticatedAttributes,
uint8_t *  output,
size_t *  written 
)

Format unauthenticatedAttributes structure.

Parameters
[in]unauthenticatedAttributesPointer to the structure to format
[out]outputBuffer where to format the ASN.1 structure
[out]writtenLength of the resulting ASN.1 structure
Returns
Error code

Definition at line 1260 of file pkcs7_format.c.