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