wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Tue Aug 22 10:48:22 2017 +0000
Revision:
13:f67a6c6013ca
wolfSSL3.12.0 with TLS1.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 13:f67a6c6013ca 1 /* pkcs7.h
wolfSSL 13:f67a6c6013ca 2 *
wolfSSL 13:f67a6c6013ca 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 13:f67a6c6013ca 4 *
wolfSSL 13:f67a6c6013ca 5 * This file is part of wolfSSL.
wolfSSL 13:f67a6c6013ca 6 *
wolfSSL 13:f67a6c6013ca 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 13:f67a6c6013ca 8 * it under the terms of the GNU General Public License as published by
wolfSSL 13:f67a6c6013ca 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 13:f67a6c6013ca 10 * (at your option) any later version.
wolfSSL 13:f67a6c6013ca 11 *
wolfSSL 13:f67a6c6013ca 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 13:f67a6c6013ca 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 13:f67a6c6013ca 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 13:f67a6c6013ca 15 * GNU General Public License for more details.
wolfSSL 13:f67a6c6013ca 16 *
wolfSSL 13:f67a6c6013ca 17 * You should have received a copy of the GNU General Public License
wolfSSL 13:f67a6c6013ca 18 * along with this program; if not, write to the Free Software
wolfSSL 13:f67a6c6013ca 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 13:f67a6c6013ca 20 */
wolfSSL 13:f67a6c6013ca 21
wolfSSL 13:f67a6c6013ca 22
wolfSSL 13:f67a6c6013ca 23 #ifndef WOLF_CRYPT_PKCS7_H
wolfSSL 13:f67a6c6013ca 24 #define WOLF_CRYPT_PKCS7_H
wolfSSL 13:f67a6c6013ca 25
wolfSSL 13:f67a6c6013ca 26 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 13:f67a6c6013ca 27
wolfSSL 13:f67a6c6013ca 28 #ifdef HAVE_PKCS7
wolfSSL 13:f67a6c6013ca 29
wolfSSL 13:f67a6c6013ca 30 #ifndef NO_ASN
wolfSSL 13:f67a6c6013ca 31 #include <wolfssl/wolfcrypt/asn.h>
wolfSSL 13:f67a6c6013ca 32 #endif
wolfSSL 13:f67a6c6013ca 33 #include <wolfssl/wolfcrypt/asn_public.h>
wolfSSL 13:f67a6c6013ca 34 #include <wolfssl/wolfcrypt/random.h>
wolfSSL 13:f67a6c6013ca 35 #ifndef NO_AES
wolfSSL 13:f67a6c6013ca 36 #include <wolfssl/wolfcrypt/aes.h>
wolfSSL 13:f67a6c6013ca 37 #endif
wolfSSL 13:f67a6c6013ca 38 #ifndef NO_DES3
wolfSSL 13:f67a6c6013ca 39 #include <wolfssl/wolfcrypt/des3.h>
wolfSSL 13:f67a6c6013ca 40 #endif
wolfSSL 13:f67a6c6013ca 41
wolfSSL 13:f67a6c6013ca 42 #ifdef __cplusplus
wolfSSL 13:f67a6c6013ca 43 extern "C" {
wolfSSL 13:f67a6c6013ca 44 #endif
wolfSSL 13:f67a6c6013ca 45
wolfSSL 13:f67a6c6013ca 46 /* PKCS#7 content types, ref RFC 2315 (Section 14) */
wolfSSL 13:f67a6c6013ca 47 enum PKCS7_TYPES {
wolfSSL 13:f67a6c6013ca 48 PKCS7_MSG = 650, /* 1.2.840.113549.1.7 */
wolfSSL 13:f67a6c6013ca 49 DATA = 651, /* 1.2.840.113549.1.7.1 */
wolfSSL 13:f67a6c6013ca 50 SIGNED_DATA = 652, /* 1.2.840.113549.1.7.2 */
wolfSSL 13:f67a6c6013ca 51 ENVELOPED_DATA = 653, /* 1.2.840.113549.1.7.3 */
wolfSSL 13:f67a6c6013ca 52 SIGNED_AND_ENVELOPED_DATA = 654, /* 1.2.840.113549.1.7.4 */
wolfSSL 13:f67a6c6013ca 53 DIGESTED_DATA = 655, /* 1.2.840.113549.1.7.5 */
wolfSSL 13:f67a6c6013ca 54 ENCRYPTED_DATA = 656 /* 1.2.840.113549.1.7.6 */
wolfSSL 13:f67a6c6013ca 55 };
wolfSSL 13:f67a6c6013ca 56
wolfSSL 13:f67a6c6013ca 57 enum Pkcs7_Misc {
wolfSSL 13:f67a6c6013ca 58 PKCS7_NONCE_SZ = 16,
wolfSSL 13:f67a6c6013ca 59 MAX_ENCRYPTED_KEY_SZ = 512, /* max enc. key size, RSA <= 4096 */
wolfSSL 13:f67a6c6013ca 60 MAX_CONTENT_KEY_LEN = 32, /* highest current cipher is AES-256-CBC */
wolfSSL 13:f67a6c6013ca 61 MAX_CONTENT_IV_SIZE = 16, /* highest current is AES128 */
wolfSSL 13:f67a6c6013ca 62 #ifndef NO_AES
wolfSSL 13:f67a6c6013ca 63 MAX_CONTENT_BLOCK_LEN = AES_BLOCK_SIZE,
wolfSSL 13:f67a6c6013ca 64 #else
wolfSSL 13:f67a6c6013ca 65 MAX_CONTENT_BLOCK_LEN = DES_BLOCK_SIZE,
wolfSSL 13:f67a6c6013ca 66 #endif
wolfSSL 13:f67a6c6013ca 67 MAX_RECIP_SZ = MAX_VERSION_SZ +
wolfSSL 13:f67a6c6013ca 68 MAX_SEQ_SZ + ASN_NAME_MAX + MAX_SN_SZ +
wolfSSL 13:f67a6c6013ca 69 MAX_SEQ_SZ + MAX_ALGO_SZ + 1 + MAX_ENCRYPTED_KEY_SZ
wolfSSL 13:f67a6c6013ca 70 };
wolfSSL 13:f67a6c6013ca 71
wolfSSL 13:f67a6c6013ca 72
wolfSSL 13:f67a6c6013ca 73 typedef struct PKCS7Attrib {
wolfSSL 13:f67a6c6013ca 74 byte* oid;
wolfSSL 13:f67a6c6013ca 75 word32 oidSz;
wolfSSL 13:f67a6c6013ca 76 byte* value;
wolfSSL 13:f67a6c6013ca 77 word32 valueSz;
wolfSSL 13:f67a6c6013ca 78 } PKCS7Attrib;
wolfSSL 13:f67a6c6013ca 79
wolfSSL 13:f67a6c6013ca 80
wolfSSL 13:f67a6c6013ca 81 typedef struct PKCS7DecodedAttrib {
wolfSSL 13:f67a6c6013ca 82 byte* oid;
wolfSSL 13:f67a6c6013ca 83 word32 oidSz;
wolfSSL 13:f67a6c6013ca 84 byte* value;
wolfSSL 13:f67a6c6013ca 85 word32 valueSz;
wolfSSL 13:f67a6c6013ca 86 struct PKCS7DecodedAttrib* next;
wolfSSL 13:f67a6c6013ca 87 } PKCS7DecodedAttrib;
wolfSSL 13:f67a6c6013ca 88
wolfSSL 13:f67a6c6013ca 89
wolfSSL 13:f67a6c6013ca 90 typedef struct PKCS7 {
wolfSSL 13:f67a6c6013ca 91 byte* content; /* inner content, not owner */
wolfSSL 13:f67a6c6013ca 92 word32 contentSz; /* content size */
wolfSSL 13:f67a6c6013ca 93 int contentOID; /* PKCS#7 content type OID sum */
wolfSSL 13:f67a6c6013ca 94
wolfSSL 13:f67a6c6013ca 95 WC_RNG* rng;
wolfSSL 13:f67a6c6013ca 96
wolfSSL 13:f67a6c6013ca 97 int hashOID;
wolfSSL 13:f67a6c6013ca 98 int encryptOID; /* key encryption algorithm OID */
wolfSSL 13:f67a6c6013ca 99 int keyWrapOID; /* key wrap algorithm OID */
wolfSSL 13:f67a6c6013ca 100 int keyAgreeOID; /* key agreement algorithm OID */
wolfSSL 13:f67a6c6013ca 101
wolfSSL 13:f67a6c6013ca 102 void* heap; /* heap hint for dynamic memory */
wolfSSL 13:f67a6c6013ca 103 byte* singleCert; /* recipient cert, DER, not owner */
wolfSSL 13:f67a6c6013ca 104 word32 singleCertSz; /* size of recipient cert buffer, bytes */
wolfSSL 13:f67a6c6013ca 105 byte issuerHash[KEYID_SIZE]; /* hash of all alt Names */
wolfSSL 13:f67a6c6013ca 106 byte* issuer; /* issuer name of singleCert */
wolfSSL 13:f67a6c6013ca 107 word32 issuerSz; /* length of issuer name */
wolfSSL 13:f67a6c6013ca 108 byte issuerSn[MAX_SN_SZ]; /* singleCert's serial number */
wolfSSL 13:f67a6c6013ca 109 word32 issuerSnSz; /* length of serial number */
wolfSSL 13:f67a6c6013ca 110
wolfSSL 13:f67a6c6013ca 111 byte publicKey[512];
wolfSSL 13:f67a6c6013ca 112 word32 publicKeySz;
wolfSSL 13:f67a6c6013ca 113 word32 publicKeyOID; /* key OID (RSAk, ECDSAk, etc) */
wolfSSL 13:f67a6c6013ca 114 byte* privateKey; /* private key, DER, not owner */
wolfSSL 13:f67a6c6013ca 115 word32 privateKeySz; /* size of private key buffer, bytes */
wolfSSL 13:f67a6c6013ca 116
wolfSSL 13:f67a6c6013ca 117 PKCS7Attrib* signedAttribs;
wolfSSL 13:f67a6c6013ca 118 word32 signedAttribsSz;
wolfSSL 13:f67a6c6013ca 119
wolfSSL 13:f67a6c6013ca 120 /* Enveloped-data optional ukm, not owner */
wolfSSL 13:f67a6c6013ca 121 byte* ukm;
wolfSSL 13:f67a6c6013ca 122 word32 ukmSz;
wolfSSL 13:f67a6c6013ca 123
wolfSSL 13:f67a6c6013ca 124 /* Encrypted-data Content Type */
wolfSSL 13:f67a6c6013ca 125 byte* encryptionKey; /* block cipher encryption key */
wolfSSL 13:f67a6c6013ca 126 word32 encryptionKeySz; /* size of key buffer, bytes */
wolfSSL 13:f67a6c6013ca 127 PKCS7Attrib* unprotectedAttribs; /* optional */
wolfSSL 13:f67a6c6013ca 128 word32 unprotectedAttribsSz;
wolfSSL 13:f67a6c6013ca 129 PKCS7DecodedAttrib* decodedAttrib; /* linked list of decoded attribs */
wolfSSL 13:f67a6c6013ca 130 } PKCS7;
wolfSSL 13:f67a6c6013ca 131
wolfSSL 13:f67a6c6013ca 132
wolfSSL 13:f67a6c6013ca 133 WOLFSSL_API int wc_PKCS7_Init(PKCS7* pkcs7, void* heap, int devId);
wolfSSL 13:f67a6c6013ca 134 WOLFSSL_API int wc_PKCS7_InitWithCert(PKCS7* pkcs7, byte* cert, word32 certSz);
wolfSSL 13:f67a6c6013ca 135 WOLFSSL_API void wc_PKCS7_Free(PKCS7* pkcs7);
wolfSSL 13:f67a6c6013ca 136 WOLFSSL_API int wc_PKCS7_EncodeData(PKCS7* pkcs7, byte* output,
wolfSSL 13:f67a6c6013ca 137 word32 outputSz);
wolfSSL 13:f67a6c6013ca 138 WOLFSSL_API int wc_PKCS7_EncodeSignedData(PKCS7* pkcs7,
wolfSSL 13:f67a6c6013ca 139 byte* output, word32 outputSz);
wolfSSL 13:f67a6c6013ca 140 WOLFSSL_API int wc_PKCS7_VerifySignedData(PKCS7* pkcs7,
wolfSSL 13:f67a6c6013ca 141 byte* pkiMsg, word32 pkiMsgSz);
wolfSSL 13:f67a6c6013ca 142 WOLFSSL_API int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7,
wolfSSL 13:f67a6c6013ca 143 byte* output, word32 outputSz);
wolfSSL 13:f67a6c6013ca 144 WOLFSSL_API int wc_PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* pkiMsg,
wolfSSL 13:f67a6c6013ca 145 word32 pkiMsgSz, byte* output,
wolfSSL 13:f67a6c6013ca 146 word32 outputSz);
wolfSSL 13:f67a6c6013ca 147 WOLFSSL_API int wc_PKCS7_EncodeEncryptedData(PKCS7* pkcs7,
wolfSSL 13:f67a6c6013ca 148 byte* output, word32 outputSz);
wolfSSL 13:f67a6c6013ca 149 WOLFSSL_API int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* pkiMsg,
wolfSSL 13:f67a6c6013ca 150 word32 pkiMsgSz, byte* output,
wolfSSL 13:f67a6c6013ca 151 word32 outputSz);
wolfSSL 13:f67a6c6013ca 152 #ifdef __cplusplus
wolfSSL 13:f67a6c6013ca 153 } /* extern "C" */
wolfSSL 13:f67a6c6013ca 154 #endif
wolfSSL 13:f67a6c6013ca 155
wolfSSL 13:f67a6c6013ca 156 #endif /* HAVE_PKCS7 */
wolfSSL 13:f67a6c6013ca 157 #endif /* WOLF_CRYPT_PKCS7_H */
wolfSSL 13:f67a6c6013ca 158
wolfSSL 13:f67a6c6013ca 159