wolfSSL 3.11.1 for TLS1.3 beta

Fork of wolfSSL by wolf SSL

Committer:
wolfSSL
Date:
Tue May 02 08:44:47 2017 +0000
Revision:
7:481bce714567
wolfSSL3.10.2

Who changed what in which revision?

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