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