Leancrypto 1.7.2
Post-Quantum Cryptographic Library
lc_pkcs7_generator.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 - 2026, Stephan Mueller <smueller@chronox.de>
3 *
4 * License: see LICENSE file in root directory
5 *
6 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
7 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
9 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
10 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
11 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
12 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
13 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
14 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
16 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 */
19
20#ifndef LC_PKCS7_GENERATOR_H
21#define LC_PKCS7_GENERATOR_H
22
23#include "lc_pkcs7_common.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
30struct lc_pkcs7_generate_context {
31 /*
32 * Message being converted into PKCS#7 blob
33 */
34 const struct lc_pkcs7_message *pkcs7;
35
36 /*
37 * Iterator over the additional certificates to place their public key
38 * information into the PKCS#7 message.
39 */
40 const struct lc_x509_certificate *current_x509;
41
42 /*
43 * Iterator over the signer certificates to perform the actual signature
44 * operation.
45 */
46 const struct lc_pkcs7_signed_info *current_sinfo;
47
48 unsigned long aa_set_applied;
49 uint16_t subject_attrib_processed;
50
51 /* Authenticated Attribute data (or NULL) */
52 const struct lc_hash *authattr_hash;
53 size_t authattrs_digest_size;
54 size_t authattrs_size;
55 uint8_t authattrs_digest[LC_SHA_MAX_SIZE_DIGEST];
56 uint8_t authattrs[LC_PKCS7_AUTHATTRS_MAX_SIZE];
57
58 /**********************************************************************
59 * Caller-provided data
60 **********************************************************************/
61
62 /*
63 * SignedData
64 */
65 enum OID signed_info_data_type; /* Type of Data */
66};
68
119int lc_pkcs7_encode(const struct lc_pkcs7_message *pkcs7, uint8_t *data,
120 size_t *avail_datalen);
121
140int lc_pkcs7_encode_ctx_init(struct lc_pkcs7_generate_context *ctx);
141
148void lc_pkcs7_encode_ctx_clear(struct lc_pkcs7_generate_context *ctx);
149
163int lc_pkcs7_encode_ctx_set_pkcs7(struct lc_pkcs7_generate_context *ctx,
164 const struct lc_pkcs7_message *pkcs7);
165
180 struct lc_pkcs7_generate_context *ctx, enum OID oid);
181
205int lc_pkcs7_encode_ctx(struct lc_pkcs7_generate_context *ctx, uint8_t *data,
206 size_t *avail_datalen);
207
227int lc_pkcs7_set_certificate(struct lc_pkcs7_message *pkcs7,
228 struct lc_x509_certificate *x509);
229
270int lc_pkcs7_set_signer(struct lc_pkcs7_message *pkcs7,
271 struct lc_x509_certificate *x509_with_sk,
272 const struct lc_hash *signing_hash,
273 unsigned long auth_attribute);
274
280};
281
296int lc_pkcs7_set_data(struct lc_pkcs7_message *pkcs7, const uint8_t *data,
297 size_t data_len, enum lc_pkcs7_set_data_flags flags);
298
314int lc_pkcs7_set_data_with_type(struct lc_pkcs7_message *pkcs7,
315 const uint8_t *data, size_t data_len,
316 enum lc_pkcs7_set_data_flags flags,
317 enum OID data_type);
318#ifdef __cplusplus
319}
320#endif
321
322#endif /* LC_PKCS7_GENERATOR_H */
int lc_hash(const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest)
Calculate message digest - one-shot.
void lc_pkcs7_encode_ctx_clear(struct lc_pkcs7_generate_context *ctx)
Clear the context for encoding a PKCS#7 message.
int lc_pkcs7_set_signer(struct lc_pkcs7_message *pkcs7, struct lc_x509_certificate *x509_with_sk, const struct lc_hash *signing_hash, unsigned long auth_attribute)
Set an PKCS#7 certificate as signer for a PKCS#7 message.
int lc_pkcs7_encode_ctx_set_pkcs7(struct lc_pkcs7_generate_context *ctx, const struct lc_pkcs7_message *pkcs7)
Set the PKCS#7 message definition.
int lc_pkcs7_set_certificate(struct lc_pkcs7_message *pkcs7, struct lc_x509_certificate *x509)
Set an PKCS#7 certificate to be added to a PKCS#7 message.
int lc_pkcs7_encode_ctx_init(struct lc_pkcs7_generate_context *ctx)
Initialize a context for encoding a PKCS#7 message.
int lc_pkcs7_encode_ctx(struct lc_pkcs7_generate_context *ctx, uint8_t *data, size_t *avail_datalen)
Encode a PKCS#7 message using the provided context.
int lc_pkcs7_set_data(struct lc_pkcs7_message *pkcs7, const uint8_t *data, size_t data_len, enum lc_pkcs7_set_data_flags flags)
Set the data to be signed with PKCS#7.
int lc_pkcs7_encode(const struct lc_pkcs7_message *pkcs7, uint8_t *data, size_t *avail_datalen)
Encode a PKCS#7 message.
int lc_pkcs7_encode_ctx_set_signer_data_type(struct lc_pkcs7_generate_context *ctx, enum OID oid)
Set the PKCS#7 SignedData contentType.
int lc_pkcs7_set_data_with_type(struct lc_pkcs7_message *pkcs7, const uint8_t *data, size_t data_len, enum lc_pkcs7_set_data_flags flags, enum OID data_type)
Set the data to be signed with PKCS#7.
OID
Definition: lc_asn1.h:44
lc_pkcs7_set_data_flags
@ lc_pkcs7_set_data_embed
@ lc_pkcs7_set_data_noflag