Leancrypto 1.7.2
Post-Quantum Cryptographic Library
lc_pkcs7_parser.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. 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 CONTRACT, STRICT LIABILITY, OR TORT
15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING ANY WAY OF THE
16 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 */
19
20#ifndef _CRYPTO_PKCS7_H
21#define _CRYPTO_PKCS7_H
22
23#include "ext_headers.h"
24#include "lc_hash.h"
25#include "lc_pkcs7_common.h"
26#include "lc_x509_parser.h"
27
84struct lc_pkcs7_parse_context {
85 struct lc_pkcs7_message *msg; /* Message being constructed */
86 struct lc_x509_certificate *certs; /* Certificate cache */
87 struct lc_x509_certificate **ppcerts; /* linked list of certs */
88 const uint8_t *data; /* Start of data */
89 enum OID last_oid; /* Last OID encountered */
90 const uint8_t *last_oid_data;
91 size_t last_oid_datalen;
92 unsigned int x509_index;
93 unsigned int sinfo_index;
94 size_t raw_serial_size;
95 size_t raw_issuer_size;
96 size_t raw_skid_size;
97 const uint8_t *raw_serial;
98 const uint8_t *raw_issuer;
99 const uint8_t *raw_skid;
100 unsigned int expect_skid : 1; /* Subject key ID */
101
102 /**********************************************************************
103 * Caller-provided data
104 **********************************************************************/
105
106 /*
107 * SignerInfo
108 */
109 enum OID data_type; /* Type of Data */
110};
112
141int lc_pkcs7_decode(struct lc_pkcs7_message *pkcs7, const uint8_t *data,
142 size_t datalen);
143
162int lc_pkcs7_decode_ctx_init(struct lc_pkcs7_parse_context *ctx);
163
170void lc_pkcs7_decode_ctx_clear(struct lc_pkcs7_parse_context *ctx);
171
184int lc_pkcs7_decode_ctx_set_pkcs7(struct lc_pkcs7_parse_context *ctx,
185 struct lc_pkcs7_message *pkcs7);
186
200int lc_pkcs7_decode_ctx_set_aa_content_type(struct lc_pkcs7_parse_context *ctx,
201 enum OID oid);
202
222int lc_pkcs7_decode_ctx(struct lc_pkcs7_parse_context *ctx, const uint8_t *data,
223 size_t datalen);
224
231void lc_pkcs7_message_clear(struct lc_pkcs7_message *pkcs7);
232
248int lc_pkcs7_get_content_data(const struct lc_pkcs7_message *pkcs7,
249 const uint8_t **data, size_t *datalen);
250
260
269 uint16_t required_eku;
270};
271
325int lc_pkcs7_verify(struct lc_pkcs7_message *pkcs7,
326 const struct lc_pkcs7_trust_store *trust_store,
327 const struct lc_verify_rules *verify_rules);
328
346int lc_pkcs7_supply_detached_data(struct lc_pkcs7_message *pkcs7,
347 const uint8_t *data, size_t datalen);
348
372int lc_pkcs7_get_digest(struct lc_pkcs7_message *pkcs7,
373 const uint8_t **message_digest,
374 size_t *message_digest_len,
375 const struct lc_hash **hash_algo);
376
401int lc_pkcs7_trust_store_add(struct lc_pkcs7_trust_store *trust_store,
402 struct lc_x509_certificate *x509);
403
410void lc_pkcs7_trust_store_clear(struct lc_pkcs7_trust_store *trust_store);
411
412#endif /* _CRYPTO_PKCS7_H */
int lc_hash(const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest)
Calculate message digest - one-shot.
int lc_pkcs7_decode(struct lc_pkcs7_message *pkcs7, const uint8_t *data, size_t datalen)
Decode a PKCS#7 message.
int lc_pkcs7_decode_ctx_set_pkcs7(struct lc_pkcs7_parse_context *ctx, struct lc_pkcs7_message *pkcs7)
Set the PKCS#7 message definition.
void lc_pkcs7_message_clear(struct lc_pkcs7_message *pkcs7)
Clear the resources used by the PKCS#7 message parsing state.
int lc_pkcs7_decode_ctx_set_aa_content_type(struct lc_pkcs7_parse_context *ctx, enum OID oid)
Set the expected authenticated attribute ContentType OID.
void lc_pkcs7_decode_ctx_clear(struct lc_pkcs7_parse_context *ctx)
Clear the context for decoding a PKCS#7 message.
int lc_pkcs7_verify(struct lc_pkcs7_message *pkcs7, const struct lc_pkcs7_trust_store *trust_store, const struct lc_verify_rules *verify_rules)
Verify a PKCS#7 message.
int lc_pkcs7_trust_store_add(struct lc_pkcs7_trust_store *trust_store, struct lc_x509_certificate *x509)
Add a certificate to a certificate trust store.
int lc_pkcs7_decode_ctx_init(struct lc_pkcs7_parse_context *ctx)
Initialize a context for decoding a PKCS#7 message.
int lc_pkcs7_get_content_data(const struct lc_pkcs7_message *pkcs7, const uint8_t **data, size_t *datalen)
Get access to the PKCS#7 encapsulated content.
int lc_pkcs7_get_digest(struct lc_pkcs7_message *pkcs7, const uint8_t **message_digest, size_t *message_digest_len, const struct lc_hash **hash_algo)
Calculate and return the message digest of the data.
int lc_pkcs7_decode_ctx(struct lc_pkcs7_parse_context *ctx, const uint8_t *data, size_t datalen)
Decode a PKCS#7 message using the provided context.
int lc_pkcs7_supply_detached_data(struct lc_pkcs7_message *pkcs7, const uint8_t *data, size_t datalen)
Supply the data needed to verify a PKCS#7 message.
void lc_pkcs7_trust_store_clear(struct lc_pkcs7_trust_store *trust_store)
Release and clear the trust store.
OID
Definition: lc_asn1.h:44
uint16_t required_keyusage