3 * Copyright (C) 2006-2015 wolfSSL Inc.
5 * This file is part of wolfSSL. (formerly known as CyaSSL)
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 #ifndef WOLF_CRYPT_PKCS7_H
23 #define WOLF_CRYPT_PKCS7_H
25 #include <wolfssl/wolfcrypt/types.h>
30 #include <wolfssl/wolfcrypt/asn.h>
32 #include <wolfssl/wolfcrypt/asn_public.h>
33 #include <wolfssl/wolfcrypt/random.h>
35 #include <wolfssl/wolfcrypt/des3.h>
42 /* PKCS#7 content types, ref RFC 2315 (Section 14) */
44 PKCS7_MSG = 650, /* 1.2.840.113549.1.7 */
45 DATA = 651, /* 1.2.840.113549.1.7.1 */
46 SIGNED_DATA = 652, /* 1.2.840.113549.1.7.2 */
47 ENVELOPED_DATA = 653, /* 1.2.840.113549.1.7.3 */
48 SIGNED_AND_ENVELOPED_DATA = 654, /* 1.2.840.113549.1.7.4 */
49 DIGESTED_DATA = 655, /* 1.2.840.113549.1.7.5 */
50 ENCRYPTED_DATA = 656 /* 1.2.840.113549.1.7.6 */
55 MAX_ENCRYPTED_KEY_SZ = 512, /* max enc. key size, RSA <= 4096 */
56 MAX_CONTENT_KEY_LEN = DES3_KEYLEN, /* highest current cipher is 3DES */
57 MAX_RECIP_SZ = MAX_VERSION_SZ +
58 MAX_SEQ_SZ + ASN_NAME_MAX + MAX_SN_SZ +
59 MAX_SEQ_SZ + MAX_ALGO_SZ + 1 + MAX_ENCRYPTED_KEY_SZ
63 typedef struct PKCS7Attrib {
71 typedef struct PKCS7 {
72 byte* content; /* inner content, not owner */
73 word32 contentSz; /* content size */
74 int contentOID; /* PKCS#7 content type OID sum */
79 int encryptOID; /* key encryption algorithm OID */
81 byte* singleCert; /* recipient cert, DER, not owner */
82 word32 singleCertSz; /* size of recipient cert buffer, bytes */
83 byte issuerHash[KEYID_SIZE]; /* hash of all alt Names */
84 byte* issuer; /* issuer name of singleCert */
85 word32 issuerSz; /* length of issuer name */
86 byte issuerSn[MAX_SN_SZ]; /* singleCert's serial number */
87 word32 issuerSnSz; /* length of serial number */
90 byte* privateKey; /* private key, DER, not owner */
91 word32 privateKeySz; /* size of private key buffer, bytes */
93 PKCS7Attrib* signedAttribs;
94 word32 signedAttribsSz;
98 WOLFSSL_LOCAL int wc_SetContentType(int pkcs7TypeOID, byte* output);
99 WOLFSSL_LOCAL int wc_GetContentType(const byte* input, word32* inOutIdx,
100 word32* oid, word32 maxIdx);
101 WOLFSSL_LOCAL int wc_CreateRecipientInfo(const byte* cert, word32 certSz,
102 int keyEncAlgo, int blockKeySz,
103 RNG* rng, byte* contentKeyPlain,
105 int* keyEncSz, byte* out, word32 outSz);
107 WOLFSSL_API int wc_PKCS7_InitWithCert(PKCS7* pkcs7, byte* cert, word32 certSz);
108 WOLFSSL_API void wc_PKCS7_Free(PKCS7* pkcs7);
109 WOLFSSL_API int wc_PKCS7_EncodeData(PKCS7* pkcs7, byte* output, word32 outputSz);
110 WOLFSSL_API int wc_PKCS7_EncodeSignedData(PKCS7* pkcs7,
111 byte* output, word32 outputSz);
112 WOLFSSL_API int wc_PKCS7_VerifySignedData(PKCS7* pkcs7,
113 byte* pkiMsg, word32 pkiMsgSz);
114 WOLFSSL_API int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7,
115 byte* output, word32 outputSz);
116 WOLFSSL_API int wc_PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* pkiMsg,
117 word32 pkiMsgSz, byte* output,
124 #endif /* HAVE_PKCS7 */
125 #endif /* WOLF_CRYPT_PKCS7_H */