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

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

Committer:
wolfSSL
Date:
Thu Apr 28 00:57:21 2016 +0000
Revision:
4:1b0d80432c79
wolfSSL 3.9.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 4:1b0d80432c79 1 /* pkcs7.h
wolfSSL 4:1b0d80432c79 2 *
wolfSSL 4:1b0d80432c79 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 4:1b0d80432c79 4 *
wolfSSL 4:1b0d80432c79 5 * This file is part of wolfSSL.
wolfSSL 4:1b0d80432c79 6 *
wolfSSL 4:1b0d80432c79 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 4:1b0d80432c79 8 * it under the terms of the GNU General Public License as published by
wolfSSL 4:1b0d80432c79 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 4:1b0d80432c79 10 * (at your option) any later version.
wolfSSL 4:1b0d80432c79 11 *
wolfSSL 4:1b0d80432c79 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 4:1b0d80432c79 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 4:1b0d80432c79 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 4:1b0d80432c79 15 * GNU General Public License for more details.
wolfSSL 4:1b0d80432c79 16 *
wolfSSL 4:1b0d80432c79 17 * You should have received a copy of the GNU General Public License
wolfSSL 4:1b0d80432c79 18 * along with this program; if not, write to the Free Software
wolfSSL 4:1b0d80432c79 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 4:1b0d80432c79 20 */
wolfSSL 4:1b0d80432c79 21
wolfSSL 4:1b0d80432c79 22
wolfSSL 4:1b0d80432c79 23 #ifndef WOLF_CRYPT_PKCS7_H
wolfSSL 4:1b0d80432c79 24 #define WOLF_CRYPT_PKCS7_H
wolfSSL 4:1b0d80432c79 25
wolfSSL 4:1b0d80432c79 26 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 4:1b0d80432c79 27
wolfSSL 4:1b0d80432c79 28 #ifdef HAVE_PKCS7
wolfSSL 4:1b0d80432c79 29
wolfSSL 4:1b0d80432c79 30 #ifndef NO_ASN
wolfSSL 4:1b0d80432c79 31 #include <wolfssl/wolfcrypt/asn.h>
wolfSSL 4:1b0d80432c79 32 #endif
wolfSSL 4:1b0d80432c79 33 #include <wolfssl/wolfcrypt/asn_public.h>
wolfSSL 4:1b0d80432c79 34 #include <wolfssl/wolfcrypt/random.h>
wolfSSL 4:1b0d80432c79 35 #ifndef NO_DES3
wolfSSL 4:1b0d80432c79 36 #include <wolfssl/wolfcrypt/des3.h>
wolfSSL 4:1b0d80432c79 37 #endif
wolfSSL 4:1b0d80432c79 38
wolfSSL 4:1b0d80432c79 39 #ifdef __cplusplus
wolfSSL 4:1b0d80432c79 40 extern "C" {
wolfSSL 4:1b0d80432c79 41 #endif
wolfSSL 4:1b0d80432c79 42
wolfSSL 4:1b0d80432c79 43 /* PKCS#7 content types, ref RFC 2315 (Section 14) */
wolfSSL 4:1b0d80432c79 44 enum PKCS7_TYPES {
wolfSSL 4:1b0d80432c79 45 PKCS7_MSG = 650, /* 1.2.840.113549.1.7 */
wolfSSL 4:1b0d80432c79 46 DATA = 651, /* 1.2.840.113549.1.7.1 */
wolfSSL 4:1b0d80432c79 47 SIGNED_DATA = 652, /* 1.2.840.113549.1.7.2 */
wolfSSL 4:1b0d80432c79 48 ENVELOPED_DATA = 653, /* 1.2.840.113549.1.7.3 */
wolfSSL 4:1b0d80432c79 49 SIGNED_AND_ENVELOPED_DATA = 654, /* 1.2.840.113549.1.7.4 */
wolfSSL 4:1b0d80432c79 50 DIGESTED_DATA = 655, /* 1.2.840.113549.1.7.5 */
wolfSSL 4:1b0d80432c79 51 ENCRYPTED_DATA = 656 /* 1.2.840.113549.1.7.6 */
wolfSSL 4:1b0d80432c79 52 };
wolfSSL 4:1b0d80432c79 53
wolfSSL 4:1b0d80432c79 54 enum Pkcs7_Misc {
wolfSSL 4:1b0d80432c79 55 PKCS7_NONCE_SZ = 16,
wolfSSL 4:1b0d80432c79 56 MAX_ENCRYPTED_KEY_SZ = 512, /* max enc. key size, RSA <= 4096 */
wolfSSL 4:1b0d80432c79 57 MAX_CONTENT_KEY_LEN = DES3_KEYLEN, /* highest current cipher is 3DES */
wolfSSL 4:1b0d80432c79 58 MAX_RECIP_SZ = MAX_VERSION_SZ +
wolfSSL 4:1b0d80432c79 59 MAX_SEQ_SZ + ASN_NAME_MAX + MAX_SN_SZ +
wolfSSL 4:1b0d80432c79 60 MAX_SEQ_SZ + MAX_ALGO_SZ + 1 + MAX_ENCRYPTED_KEY_SZ
wolfSSL 4:1b0d80432c79 61 };
wolfSSL 4:1b0d80432c79 62
wolfSSL 4:1b0d80432c79 63
wolfSSL 4:1b0d80432c79 64 typedef struct PKCS7Attrib {
wolfSSL 4:1b0d80432c79 65 byte* oid;
wolfSSL 4:1b0d80432c79 66 word32 oidSz;
wolfSSL 4:1b0d80432c79 67 byte* value;
wolfSSL 4:1b0d80432c79 68 word32 valueSz;
wolfSSL 4:1b0d80432c79 69 } PKCS7Attrib;
wolfSSL 4:1b0d80432c79 70
wolfSSL 4:1b0d80432c79 71
wolfSSL 4:1b0d80432c79 72 typedef struct PKCS7 {
wolfSSL 4:1b0d80432c79 73 byte* content; /* inner content, not owner */
wolfSSL 4:1b0d80432c79 74 word32 contentSz; /* content size */
wolfSSL 4:1b0d80432c79 75 int contentOID; /* PKCS#7 content type OID sum */
wolfSSL 4:1b0d80432c79 76
wolfSSL 4:1b0d80432c79 77 WC_RNG* rng;
wolfSSL 4:1b0d80432c79 78
wolfSSL 4:1b0d80432c79 79 int hashOID;
wolfSSL 4:1b0d80432c79 80 int encryptOID; /* key encryption algorithm OID */
wolfSSL 4:1b0d80432c79 81
wolfSSL 4:1b0d80432c79 82 byte* singleCert; /* recipient cert, DER, not owner */
wolfSSL 4:1b0d80432c79 83 word32 singleCertSz; /* size of recipient cert buffer, bytes */
wolfSSL 4:1b0d80432c79 84 byte issuerHash[KEYID_SIZE]; /* hash of all alt Names */
wolfSSL 4:1b0d80432c79 85 byte* issuer; /* issuer name of singleCert */
wolfSSL 4:1b0d80432c79 86 word32 issuerSz; /* length of issuer name */
wolfSSL 4:1b0d80432c79 87 byte issuerSn[MAX_SN_SZ]; /* singleCert's serial number */
wolfSSL 4:1b0d80432c79 88 word32 issuerSnSz; /* length of serial number */
wolfSSL 4:1b0d80432c79 89 byte publicKey[512];
wolfSSL 4:1b0d80432c79 90 word32 publicKeySz;
wolfSSL 4:1b0d80432c79 91 byte* privateKey; /* private key, DER, not owner */
wolfSSL 4:1b0d80432c79 92 word32 privateKeySz; /* size of private key buffer, bytes */
wolfSSL 4:1b0d80432c79 93
wolfSSL 4:1b0d80432c79 94 PKCS7Attrib* signedAttribs;
wolfSSL 4:1b0d80432c79 95 word32 signedAttribsSz;
wolfSSL 4:1b0d80432c79 96 } PKCS7;
wolfSSL 4:1b0d80432c79 97
wolfSSL 4:1b0d80432c79 98
wolfSSL 4:1b0d80432c79 99 WOLFSSL_LOCAL int wc_SetContentType(int pkcs7TypeOID, byte* output);
wolfSSL 4:1b0d80432c79 100 WOLFSSL_LOCAL int wc_GetContentType(const byte* input, word32* inOutIdx,
wolfSSL 4:1b0d80432c79 101 word32* oid, word32 maxIdx);
wolfSSL 4:1b0d80432c79 102 WOLFSSL_LOCAL int wc_CreateRecipientInfo(const byte* cert, word32 certSz,
wolfSSL 4:1b0d80432c79 103 int keyEncAlgo, int blockKeySz,
wolfSSL 4:1b0d80432c79 104 WC_RNG* rng, byte* contentKeyPlain,
wolfSSL 4:1b0d80432c79 105 byte* contentKeyEnc,
wolfSSL 4:1b0d80432c79 106 int* keyEncSz, byte* out, word32 outSz);
wolfSSL 4:1b0d80432c79 107
wolfSSL 4:1b0d80432c79 108 WOLFSSL_API int wc_PKCS7_InitWithCert(PKCS7* pkcs7, byte* cert, word32 certSz);
wolfSSL 4:1b0d80432c79 109 WOLFSSL_API void wc_PKCS7_Free(PKCS7* pkcs7);
wolfSSL 4:1b0d80432c79 110 WOLFSSL_API int wc_PKCS7_EncodeData(PKCS7* pkcs7, byte* output, word32 outputSz);
wolfSSL 4:1b0d80432c79 111 WOLFSSL_API int wc_PKCS7_EncodeSignedData(PKCS7* pkcs7,
wolfSSL 4:1b0d80432c79 112 byte* output, word32 outputSz);
wolfSSL 4:1b0d80432c79 113 WOLFSSL_API int wc_PKCS7_VerifySignedData(PKCS7* pkcs7,
wolfSSL 4:1b0d80432c79 114 byte* pkiMsg, word32 pkiMsgSz);
wolfSSL 4:1b0d80432c79 115 WOLFSSL_API int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7,
wolfSSL 4:1b0d80432c79 116 byte* output, word32 outputSz);
wolfSSL 4:1b0d80432c79 117 WOLFSSL_API int wc_PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* pkiMsg,
wolfSSL 4:1b0d80432c79 118 word32 pkiMsgSz, byte* output,
wolfSSL 4:1b0d80432c79 119 word32 outputSz);
wolfSSL 4:1b0d80432c79 120
wolfSSL 4:1b0d80432c79 121 #ifdef __cplusplus
wolfSSL 4:1b0d80432c79 122 } /* extern "C" */
wolfSSL 4:1b0d80432c79 123 #endif
wolfSSL 4:1b0d80432c79 124
wolfSSL 4:1b0d80432c79 125 #endif /* HAVE_PKCS7 */
wolfSSL 4:1b0d80432c79 126 #endif /* WOLF_CRYPT_PKCS7_H */
wolfSSL 4:1b0d80432c79 127
wolfSSL 4:1b0d80432c79 128