Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/pkcs7/internal.h

raw
1 // Copyright (c) 2017, Google Inc.
2 // SPDX-License-Identifier: ISC
3
4 #ifndef OPENSSL_HEADER_PKCS7_INTERNAL_H
5 #define OPENSSL_HEADER_PKCS7_INTERNAL_H
6
7 #include <openssl/base.h>
8
9 #if defined(__cplusplus)
10 extern "C" {
11 #endif
12
13
14
15 DECLARE_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
16 DECLARE_ASN1_FUNCTIONS(PKCS7_SIGNED)
17 DECLARE_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
18 DECLARE_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
19 DECLARE_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
20 DECLARE_ASN1_FUNCTIONS(PKCS7_DIGEST)
21 DECLARE_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
22
23 DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY)
24
25 DEFINE_STACK_OF(PKCS7)
26
27 // ASN.1 defined here https://datatracker.ietf.org/doc/html/rfc2315#section-10.1
28 //
29 // EncryptedContentInfo ::= SEQUENCE {
30 // contentType ContentType,
31 // contentEncryptionAlgorithm
32 // ContentEncryptionAlgorithmIdentifier,
33 // encryptedContent
34 // [0] IMPLICIT EncryptedContent OPTIONAL }
35 //
36 // EncryptedContent ::= OCTET STRING
37 struct pkcs7_enc_content_st {
38 ASN1_OBJECT *content_type;
39 X509_ALGOR *algorithm;
40 ASN1_OCTET_STRING *enc_data;
41 const EVP_CIPHER *cipher; // NOTE: |cipher| is not serialized
42 };
43
44 // ASN.1 defined here https://datatracker.ietf.org/doc/html/rfc2315#section-12
45 //
46 // DigestedData ::= SEQUENCE {
47 // version Version,
48 // digestAlgorithm DigestAlgorithmIdentifier,
49 // contentInfo ContentInfo,
50 // digest Digest }
51 //
52 // Digest ::= OCTET STRING
53 struct pkcs7_digest_st {
54 ASN1_INTEGER *version;
55 X509_ALGOR *digest_alg;
56 PKCS7 *contents;
57 ASN1_OCTET_STRING *digest;
58 const EVP_MD *md; // NOTE: |md| is not serialized
59 };
60
61 // ASN.1 defined here https://datatracker.ietf.org/doc/html/rfc2315#section-13
62 //
63 // EncryptedData ::= SEQUENCE {
64 // version Version,
65 // encryptedContentInfo EncryptedContentInfo }
66 struct pkcs7_encrypt_st {
67 ASN1_INTEGER *version;
68 PKCS7_ENC_CONTENT *enc_data;
69 };
70
71 // pkcs7_parse_header reads the non-certificate/non-CRL prefix of a PKCS#7
72 // SignedData blob from |cbs| and sets |*out| to point to the rest of the
73 // input. If the input is in BER format, then |*der_bytes| will be set to a
74 // pointer that needs to be freed by the caller once they have finished
75 // processing |*out| (which will be pointing into |*der_bytes|).
76 //
77 // It returns one on success or zero on error. On error, |*der_bytes| is
78 // NULL.
79 int pkcs7_parse_header(uint8_t **der_bytes, CBS *out, CBS *cbs);
80
81 // pkcs7_add_signed_data writes a PKCS#7, SignedData structure to |out|. While
82 // doing so it makes callbacks to let the caller fill in parts of the structure.
83 // All callbacks are ignored if NULL and return one on success or zero on error.
84 //
85 // digest_algos_cb: may write AlgorithmIdentifiers into the given CBB, which
86 // is a SET of digest algorithms.
87 // cert_crl_cb: may write the |certificates| or |crls| fields.
88 // (See https://datatracker.ietf.org/doc/html/rfc2315#section-9.1)
89 // signer_infos_cb: may write the contents of the |signerInfos| field.
90 // (See https://datatracker.ietf.org/doc/html/rfc2315#section-9.1)
91 //
92 // pkcs7_add_signed_data returns one on success or zero on error.
93 int pkcs7_add_signed_data(CBB *out,
94 int (*digest_algos_cb)(CBB *out, const void *arg),
95 int (*cert_crl_cb)(CBB *out, const void *arg),
96 int (*signer_infos_cb)(CBB *out, const void *arg),
97 const void *arg);
98
99 // BIO_f_cipher is used internally by the pkcs7 module. It is not recommended
100 // for external use.
101 OPENSSL_EXPORT const BIO_METHOD *BIO_f_cipher(void);
102
103 // BIO_get_cipher_ctx writes a reference of |b|'s EVP_CIPHER_CTX* to |*ctx|
104 int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **ctx);
105
106 // BIO_set_cipher is used internally for testing. It is not recommended for
107 // external use.
108 OPENSSL_EXPORT int BIO_set_cipher(BIO *b, const EVP_CIPHER *cipher,
109 const unsigned char *key,
110 const unsigned char *iv, int enc);
111
112 // BIO_get_cipher_status returns 1 if the cipher is in a healthy state or 0
113 // otherwise. Unhealthy state could indicate decryption failure or other
114 // abnormalities. Data read from an unhealthy cipher should not be considered
115 // authentic.
116 OPENSSL_EXPORT int BIO_get_cipher_status(BIO *b);
117
118 // pkcs7_final initializes a data BIO using |p7|, copies all of |data| into it,
119 // before final finalizing |p7|. It returns 1 on success and 0 on failure.
120 int pkcs7_final(PKCS7 *p7, BIO *data);
121
122 #if defined(__cplusplus)
123 } // extern C
124 #endif
125
126 #endif // OPENSSL_HEADER_PKCS7_INTERNAL_H