]> begriffs open source - freertos/blob - FreeRTOS-Plus/Source/WolfSSL/wolfssl/wolfcrypt/pkcs7.h
Update WolfSSL library to the latest version.
[freertos] / FreeRTOS-Plus / Source / WolfSSL / wolfssl / wolfcrypt / pkcs7.h
1 /* pkcs7.h
2  *
3  * Copyright (C) 2006-2015 wolfSSL Inc.
4  *
5  * This file is part of wolfSSL. (formerly known as CyaSSL)
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #ifndef WOLF_CRYPT_PKCS7_H
23 #define WOLF_CRYPT_PKCS7_H
24
25 #include <wolfssl/wolfcrypt/types.h>
26
27 #ifdef HAVE_PKCS7
28
29 #ifndef NO_ASN
30     #include <wolfssl/wolfcrypt/asn.h>
31 #endif
32 #include <wolfssl/wolfcrypt/asn_public.h>
33 #include <wolfssl/wolfcrypt/random.h>
34 #ifndef NO_DES3
35     #include <wolfssl/wolfcrypt/des3.h>
36 #endif
37
38 #ifdef __cplusplus
39     extern "C" {
40 #endif
41
42 /* PKCS#7 content types, ref RFC 2315 (Section 14) */
43 enum PKCS7_TYPES {
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 */
51 };
52
53 enum Pkcs7_Misc {
54     PKCS7_NONCE_SZ       = 16,
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
60 };
61
62
63 typedef struct PKCS7Attrib {
64     byte* oid;
65     word32 oidSz;
66     byte* value;
67     word32 valueSz;
68 } PKCS7Attrib;
69
70
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          */
75
76     RNG* rng;
77
78     int hashOID;
79     int encryptOID;               /* key encryption algorithm OID         */
80
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              */
88     byte publicKey[512];
89     word32 publicKeySz;
90     byte*  privateKey;            /* private key, DER, not owner          */
91     word32 privateKeySz;          /* size of private key buffer, bytes    */
92
93     PKCS7Attrib* signedAttribs;
94     word32 signedAttribsSz;
95 } PKCS7;
96
97
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,
104                                      byte* contentKeyEnc,
105                                      int* keyEncSz, byte* out, word32 outSz);
106
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,
118                                           word32 outputSz);
119
120 #ifdef __cplusplus
121     } /* extern "C" */
122 #endif
123
124 #endif /* HAVE_PKCS7 */
125 #endif /* WOLF_CRYPT_PKCS7_H */
126