Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of wolfSSL by
pkcs7.h
00001 /* pkcs7.h 00002 * 00003 * Copyright (C) 2006-2016 wolfSSL Inc. 00004 * 00005 * This file is part of wolfSSL. 00006 * 00007 * wolfSSL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * wolfSSL is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA 00020 */ 00021 00022 00023 #ifndef WOLF_CRYPT_PKCS7_H 00024 #define WOLF_CRYPT_PKCS7_H 00025 00026 #include <wolfssl/wolfcrypt/types.h> 00027 00028 #ifdef HAVE_PKCS7 00029 00030 #ifndef NO_ASN 00031 #include <wolfssl/wolfcrypt/asn.h> 00032 #endif 00033 #include <wolfssl/wolfcrypt/asn_public.h> 00034 #include <wolfssl/wolfcrypt/random.h> 00035 #ifndef NO_AES 00036 #include <wolfssl/wolfcrypt/aes.h> 00037 #endif 00038 #ifndef NO_DES3 00039 #include <wolfssl/wolfcrypt/des3.h> 00040 #endif 00041 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00046 /* PKCS#7 content types, ref RFC 2315 (Section 14) */ 00047 enum PKCS7_TYPES { 00048 PKCS7_MSG = 650, /* 1.2.840.113549.1.7 */ 00049 DATA = 651, /* 1.2.840.113549.1.7.1 */ 00050 SIGNED_DATA = 652, /* 1.2.840.113549.1.7.2 */ 00051 ENVELOPED_DATA = 653, /* 1.2.840.113549.1.7.3 */ 00052 SIGNED_AND_ENVELOPED_DATA = 654, /* 1.2.840.113549.1.7.4 */ 00053 DIGESTED_DATA = 655, /* 1.2.840.113549.1.7.5 */ 00054 ENCRYPTED_DATA = 656 /* 1.2.840.113549.1.7.6 */ 00055 }; 00056 00057 enum Pkcs7_Misc { 00058 PKCS7_NONCE_SZ = 16, 00059 MAX_ENCRYPTED_KEY_SZ = 512, /* max enc. key size, RSA <= 4096 */ 00060 MAX_CONTENT_KEY_LEN = 32, /* highest current cipher is AES-256-CBC */ 00061 MAX_CONTENT_IV_SIZE = 16, /* highest current is AES128 */ 00062 #ifndef NO_AES 00063 MAX_CONTENT_BLOCK_LEN = AES_BLOCK_SIZE, 00064 #else 00065 MAX_CONTENT_BLOCK_LEN = DES_BLOCK_SIZE, 00066 #endif 00067 MAX_RECIP_SZ = MAX_VERSION_SZ + 00068 MAX_SEQ_SZ + ASN_NAME_MAX + MAX_SN_SZ + 00069 MAX_SEQ_SZ + MAX_ALGO_SZ + 1 + MAX_ENCRYPTED_KEY_SZ 00070 }; 00071 00072 00073 typedef struct PKCS7Attrib { 00074 byte* oid; 00075 word32 oidSz; 00076 byte* value; 00077 word32 valueSz; 00078 } PKCS7Attrib; 00079 00080 00081 typedef struct PKCS7DecodedAttrib { 00082 byte* oid; 00083 word32 oidSz; 00084 byte* value; 00085 word32 valueSz; 00086 struct PKCS7DecodedAttrib* next; 00087 } PKCS7DecodedAttrib; 00088 00089 00090 typedef struct PKCS7 { 00091 byte* content; /* inner content, not owner */ 00092 word32 contentSz; /* content size */ 00093 int contentOID; /* PKCS#7 content type OID sum */ 00094 00095 WC_RNG* rng; 00096 00097 int hashOID; 00098 int encryptOID; /* key encryption algorithm OID */ 00099 int keyWrapOID; /* key wrap algorithm OID */ 00100 int keyAgreeOID; /* key agreement algorithm OID */ 00101 00102 void* heap; /* heap hint for dynamic memory */ 00103 byte* singleCert; /* recipient cert, DER, not owner */ 00104 word32 singleCertSz; /* size of recipient cert buffer, bytes */ 00105 byte issuerHash[KEYID_SIZE]; /* hash of all alt Names */ 00106 byte* issuer; /* issuer name of singleCert */ 00107 word32 issuerSz; /* length of issuer name */ 00108 byte issuerSn[MAX_SN_SZ]; /* singleCert's serial number */ 00109 word32 issuerSnSz; /* length of serial number */ 00110 00111 byte publicKey[512]; 00112 word32 publicKeySz; 00113 word32 publicKeyOID; /* key OID (RSAk, ECDSAk, etc) */ 00114 byte* privateKey; /* private key, DER, not owner */ 00115 word32 privateKeySz; /* size of private key buffer, bytes */ 00116 00117 PKCS7Attrib* signedAttribs; 00118 word32 signedAttribsSz; 00119 00120 /* Enveloped-data optional ukm, not owner */ 00121 byte* ukm; 00122 word32 ukmSz; 00123 00124 /* Encrypted-data Content Type */ 00125 byte* encryptionKey; /* block cipher encryption key */ 00126 word32 encryptionKeySz; /* size of key buffer, bytes */ 00127 PKCS7Attrib* unprotectedAttribs; /* optional */ 00128 word32 unprotectedAttribsSz; 00129 PKCS7DecodedAttrib* decodedAttrib; /* linked list of decoded attribs */ 00130 } PKCS7; 00131 00132 00133 WOLFSSL_API int wc_PKCS7_InitWithCert(PKCS7* pkcs7, byte* cert, word32 certSz); 00134 WOLFSSL_API void wc_PKCS7_Free(PKCS7* pkcs7); 00135 WOLFSSL_API int wc_PKCS7_EncodeData(PKCS7* pkcs7, byte* output, 00136 word32 outputSz); 00137 WOLFSSL_API int wc_PKCS7_EncodeSignedData(PKCS7* pkcs7, 00138 byte* output, word32 outputSz); 00139 WOLFSSL_API int wc_PKCS7_VerifySignedData(PKCS7* pkcs7, 00140 byte* pkiMsg, word32 pkiMsgSz); 00141 WOLFSSL_API int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7, 00142 byte* output, word32 outputSz); 00143 WOLFSSL_API int wc_PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* pkiMsg, 00144 word32 pkiMsgSz, byte* output, 00145 word32 outputSz); 00146 WOLFSSL_API int wc_PKCS7_EncodeEncryptedData(PKCS7* pkcs7, 00147 byte* output, word32 outputSz); 00148 WOLFSSL_API int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* pkiMsg, 00149 word32 pkiMsgSz, byte* output, 00150 word32 outputSz); 00151 #ifdef __cplusplus 00152 } /* extern "C" */ 00153 #endif 00154 00155 #endif /* HAVE_PKCS7 */ 00156 #endif /* WOLF_CRYPT_PKCS7_H */ 00157 00158
Generated on Tue Jul 12 2022 23:30:59 by
1.7.2
