pkcs7.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. /* pkcs7.h
  2. *
  3. * Copyright (C) 2006-2022 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /*!
  22. \file wolfssl/wolfcrypt/pkcs7.h
  23. */
  24. #ifndef WOLF_CRYPT_PKCS7_H
  25. #define WOLF_CRYPT_PKCS7_H
  26. #include <wolfssl/wolfcrypt/types.h>
  27. #ifdef HAVE_PKCS7
  28. #ifndef NO_ASN
  29. #include <wolfssl/wolfcrypt/asn.h>
  30. #endif
  31. #include <wolfssl/wolfcrypt/asn_public.h>
  32. #include <wolfssl/wolfcrypt/random.h>
  33. #ifndef NO_AES
  34. #include <wolfssl/wolfcrypt/aes.h>
  35. #endif
  36. #ifndef NO_DES3
  37. #include <wolfssl/wolfcrypt/des3.h>
  38. #endif
  39. #include <wolfssl/wolfcrypt/wc_encrypt.h>
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Max number of certificates that PKCS7 structure can parse */
  44. #ifndef MAX_PKCS7_CERTS
  45. #ifdef OPENSSL_ALL
  46. #define MAX_PKCS7_CERTS 15
  47. #else
  48. #define MAX_PKCS7_CERTS 4
  49. #endif
  50. #endif
  51. #ifndef MAX_ORI_TYPE_SZ
  52. #define MAX_ORI_TYPE_SZ MAX_OID_SZ
  53. #endif
  54. #ifndef MAX_ORI_VALUE_SZ
  55. #define MAX_ORI_VALUE_SZ 512
  56. #endif
  57. #ifndef MAX_SIGNED_ATTRIBS_SZ
  58. #define MAX_SIGNED_ATTRIBS_SZ 7
  59. #endif
  60. #ifndef MAX_AUTH_ATTRIBS_SZ
  61. #define MAX_AUTH_ATTRIBS_SZ 7
  62. #endif
  63. #ifndef MAX_UNAUTH_ATTRIBS_SZ
  64. #define MAX_UNAUTH_ATTRIBS_SZ 7
  65. #endif
  66. /* PKCS#7 content types, ref RFC 2315 (Section 14) */
  67. enum PKCS7_TYPES {
  68. PKCS7_MSG = 650, /* 1.2.840.113549.1.7 */
  69. DATA = 651, /* 1.2.840.113549.1.7.1 */
  70. SIGNED_DATA = 652, /* 1.2.840.113549.1.7.2 */
  71. ENVELOPED_DATA = 653, /* 1.2.840.113549.1.7.3 */
  72. SIGNED_AND_ENVELOPED_DATA = 654, /* 1.2.840.113549.1.7.4 */
  73. DIGESTED_DATA = 655, /* 1.2.840.113549.1.7.5 */
  74. ENCRYPTED_DATA = 656, /* 1.2.840.113549.1.7.6 */
  75. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  76. COMPRESSED_DATA = 678, /* 1.2.840.113549.1.9.16.1.9, RFC 3274 */
  77. #endif
  78. FIRMWARE_PKG_DATA = 685, /* 1.2.840.113549.1.9.16.1.16, RFC 4108 */
  79. AUTH_ENVELOPED_DATA = 692 /* 1.2.840.113549.1.9.16.1.23, RFC 5083 */
  80. };
  81. enum PKCS7_STATE {
  82. WC_PKCS7_START = 0,
  83. /* decode encrypted */
  84. WC_PKCS7_STAGE2,
  85. WC_PKCS7_STAGE3,
  86. WC_PKCS7_STAGE4,
  87. WC_PKCS7_STAGE5,
  88. WC_PKCS7_STAGE6,
  89. WC_PKCS7_VERIFY_STAGE2,
  90. WC_PKCS7_VERIFY_STAGE3,
  91. WC_PKCS7_VERIFY_STAGE4,
  92. WC_PKCS7_VERIFY_STAGE5,
  93. WC_PKCS7_VERIFY_STAGE6,
  94. /* parse info set */
  95. WC_PKCS7_INFOSET_START,
  96. WC_PKCS7_INFOSET_BER,
  97. WC_PKCS7_INFOSET_STAGE1,
  98. WC_PKCS7_INFOSET_STAGE2,
  99. WC_PKCS7_INFOSET_END,
  100. /* decode enveloped data */
  101. WC_PKCS7_ENV_2,
  102. WC_PKCS7_ENV_3,
  103. WC_PKCS7_ENV_4,
  104. WC_PKCS7_ENV_5,
  105. /* decode auth enveloped */
  106. WC_PKCS7_AUTHENV_2,
  107. WC_PKCS7_AUTHENV_3,
  108. WC_PKCS7_AUTHENV_4,
  109. WC_PKCS7_AUTHENV_5,
  110. WC_PKCS7_AUTHENV_6,
  111. WC_PKCS7_AUTHENV_ATRB,
  112. WC_PKCS7_AUTHENV_ATRBEND,
  113. WC_PKCS7_AUTHENV_7,
  114. /* decryption state types */
  115. WC_PKCS7_DECRYPT_KTRI,
  116. WC_PKCS7_DECRYPT_KTRI_2,
  117. WC_PKCS7_DECRYPT_KTRI_3,
  118. WC_PKCS7_DECRYPT_KARI,
  119. WC_PKCS7_DECRYPT_KEKRI,
  120. WC_PKCS7_DECRYPT_PWRI,
  121. WC_PKCS7_DECRYPT_ORI,
  122. WC_PKCS7_DECRYPT_DONE,
  123. };
  124. enum Pkcs7_Misc {
  125. PKCS7_NONCE_SZ = 16,
  126. MAX_ENCRYPTED_KEY_SZ = 512, /* max enc. key size, RSA <= 4096 */
  127. MAX_CONTENT_KEY_LEN = 32, /* highest current cipher is AES-256-CBC */
  128. MAX_CONTENT_IV_SIZE = 16, /* highest current is AES128 */
  129. #ifndef NO_AES
  130. MAX_CONTENT_BLOCK_LEN = AES_BLOCK_SIZE,
  131. #else
  132. MAX_CONTENT_BLOCK_LEN = DES_BLOCK_SIZE,
  133. #endif
  134. MAX_RECIP_SZ = MAX_VERSION_SZ +
  135. MAX_SEQ_SZ + WC_ASN_NAME_MAX + MAX_SN_SZ +
  136. MAX_SEQ_SZ + MAX_ALGO_SZ + 1 + MAX_ENCRYPTED_KEY_SZ,
  137. };
  138. enum Cms_Options {
  139. CMS_SKID = 1,
  140. CMS_ISSUER_AND_SERIAL_NUMBER = 2,
  141. };
  142. #define DEGENERATE_SID 3
  143. /* CMS/PKCS#7 RecipientInfo types, RFC 5652, Section 6.2 */
  144. enum Pkcs7_RecipientInfo_Types {
  145. PKCS7_KTRI = 0,
  146. PKCS7_KARI = 1,
  147. PKCS7_KEKRI = 2,
  148. PKCS7_PWRI = 3,
  149. PKCS7_ORI = 4
  150. };
  151. typedef struct PKCS7Attrib {
  152. const byte* oid;
  153. word32 oidSz;
  154. const byte* value;
  155. word32 valueSz;
  156. } PKCS7Attrib;
  157. typedef struct PKCS7DecodedAttrib {
  158. struct PKCS7DecodedAttrib* next;
  159. byte* oid;
  160. word32 oidSz;
  161. byte* value;
  162. word32 valueSz;
  163. } PKCS7DecodedAttrib;
  164. typedef struct PKCS7State PKCS7State;
  165. typedef struct Pkcs7Cert Pkcs7Cert;
  166. typedef struct Pkcs7EncodedRecip Pkcs7EncodedRecip;
  167. typedef struct PKCS7 PKCS7;
  168. typedef struct PKCS7 PKCS7_SIGNED;
  169. typedef struct PKCS7SignerInfo PKCS7SignerInfo;
  170. /* OtherRecipientInfo decrypt callback prototype */
  171. typedef int (*CallbackOriDecrypt)(PKCS7* pkcs7, byte* oriType, word32 oriTypeSz,
  172. byte* oriValue, word32 oriValueSz,
  173. byte* decryptedKey, word32* decryptedKeySz,
  174. void* ctx);
  175. typedef int (*CallbackOriEncrypt)(PKCS7* pkcs7, byte* cek, word32 cekSz,
  176. byte* oriType, word32* oriTypeSz,
  177. byte* oriValue, word32* oriValueSz,
  178. void* ctx);
  179. typedef int (*CallbackDecryptContent)(PKCS7* pkcs7, int encryptOID,
  180. byte* iv, int ivSz, byte* aad, word32 aadSz,
  181. byte* authTag, word32 authTagSz, byte* in,
  182. int inSz, byte* out, void* ctx);
  183. typedef int (*CallbackWrapCEK)(PKCS7* pkcs7, byte* cek, word32 cekSz,
  184. byte* keyId, word32 keyIdSz,
  185. byte* originKey, word32 originKeySz,
  186. byte* out, word32 outSz,
  187. int keyWrapAlgo, int type, int dir);
  188. #if defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && !defined(NO_RSA)
  189. /* RSA sign raw digest callback, user builds DigestInfo */
  190. typedef int (*CallbackRsaSignRawDigest)(PKCS7* pkcs7, byte* digest,
  191. word32 digestSz, byte* out, word32 outSz,
  192. byte* privateKey, word32 privateKeySz,
  193. int devId, int hashOID);
  194. #endif
  195. /* Public Structure Warning:
  196. * Existing members must not be changed to maintain backwards compatibility!
  197. */
  198. struct PKCS7 {
  199. WC_RNG* rng;
  200. PKCS7Attrib* signedAttribs;
  201. byte* content; /* inner content, not owner */
  202. byte* contentDynamic; /* content if constructed OCTET_STRING */
  203. byte* singleCert; /* recipient cert, DER, not owner */
  204. const byte* issuer; /* issuer name of singleCert */
  205. byte* privateKey; /* private key, DER, not owner */
  206. void* heap; /* heap hint for dynamic memory */
  207. #ifdef ASN_BER_TO_DER
  208. byte* der; /* DER encoded version of message */
  209. word32 derSz;
  210. #endif
  211. byte* cert[MAX_PKCS7_CERTS]; /* array of certs parsed from bundle */
  212. byte* verifyCert; /* cert from array used for verify */
  213. word32 verifyCertSz;
  214. /* Encrypted-data Content Type */
  215. byte* encryptionKey; /* block cipher encryption key */
  216. PKCS7Attrib* unprotectedAttribs; /* optional */
  217. PKCS7DecodedAttrib* decodedAttrib; /* linked list of decoded attribs */
  218. /* Enveloped-data optional ukm, not owner */
  219. byte* ukm;
  220. word32 ukmSz;
  221. word32 encryptionKeySz; /* size of key buffer, bytes */
  222. word32 unprotectedAttribsSz;
  223. word32 contentSz; /* content size */
  224. word32 singleCertSz; /* size of recipient cert buffer, bytes */
  225. word32 issuerSz; /* length of issuer name */
  226. word32 issuerSnSz; /* length of serial number */
  227. word32 publicKeySz;
  228. word32 publicKeyOID; /* key OID (RSAk, ECDSAk, etc) */
  229. word32 privateKeySz; /* size of private key buffer, bytes */
  230. word32 signedAttribsSz;
  231. int contentOID; /* PKCS#7 content type OID sum */
  232. int hashOID;
  233. int encryptOID; /* key encryption algorithm OID */
  234. int keyWrapOID; /* key wrap algorithm OID */
  235. int keyAgreeOID; /* key agreement algorithm OID */
  236. int devId; /* device ID for HW based private key */
  237. byte issuerHash[KEYID_SIZE]; /* hash of all alt Names */
  238. byte issuerSn[MAX_SN_SZ]; /* singleCert's serial number */
  239. byte publicKey[MAX_RSA_INT_SZ + MAX_RSA_E_SZ]; /* MAX RSA key size (m + e)*/
  240. word32 certSz[MAX_PKCS7_CERTS];
  241. /* flags - up to 16-bits */
  242. word16 isDynamic:1;
  243. word16 noDegenerate:1; /* allow degenerate case in verify function */
  244. word16 detached:1; /* generate detached SignedData signature bundles */
  245. byte contentType[MAX_OID_SZ]; /* custom contentType byte array */
  246. word32 contentTypeSz; /* size of contentType, bytes */
  247. int sidType; /* SignerIdentifier type to use, of type
  248. Pkcs7_SignerIdentifier_Types, default to
  249. SID_ISSUER_AND_SERIAL_NUMBER */
  250. byte issuerSubjKeyId[KEYID_SIZE]; /* SubjectKeyIdentifier of singleCert */
  251. Pkcs7Cert* certList; /* certificates list for SignedData set */
  252. Pkcs7EncodedRecip* recipList; /* recipients list */
  253. byte* cek; /* content encryption key, random, dynamic */
  254. word32 cekSz; /* size of cek, bytes */
  255. byte* pass; /* password, for PWRI decryption */
  256. word32 passSz; /* size of pass, bytes */
  257. int kekEncryptOID; /* KEK encryption algorithm OID */
  258. CallbackOriEncrypt oriEncryptCb; /* ORI encrypt callback */
  259. CallbackOriDecrypt oriDecryptCb; /* ORI decrypt callback */
  260. void* oriEncryptCtx; /* ORI encrypt user context ptr */
  261. void* oriDecryptCtx; /* ORI decrypt user context ptr */
  262. PKCS7Attrib* authAttribs; /* authenticated attribs */
  263. word32 authAttribsSz;
  264. PKCS7Attrib* unauthAttribs; /* unauthenticated attribs */
  265. word32 unauthAttribsSz;
  266. #ifndef NO_PKCS7_STREAM
  267. PKCS7State* stream;
  268. #endif
  269. word32 state;
  270. word16 skipDefaultSignedAttribs:1; /* skip adding default signed attribs */
  271. byte version; /* 1 for RFC 2315 and 3 for RFC 4108 */
  272. PKCS7SignerInfo* signerInfo;
  273. CallbackDecryptContent decryptionCb;
  274. CallbackWrapCEK wrapCEKCb;
  275. void* decryptionCtx;
  276. byte* signature;
  277. byte* plainDigest;
  278. byte* pkcs7Digest;
  279. word32 signatureSz;
  280. word32 plainDigestSz;
  281. word32 pkcs7DigestSz;
  282. #if defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && !defined(NO_RSA)
  283. CallbackRsaSignRawDigest rsaSignRawDigestCb;
  284. #endif
  285. /* used by DecodeEnvelopedData with multiple encrypted contents */
  286. byte* cachedEncryptedContent;
  287. word32 cachedEncryptedContentSz;
  288. word16 contentCRLF:1; /* have content line endings been converted to CRLF */
  289. /* !! NEW DATA MEMBERS MUST BE ADDED AT END !! */
  290. };
  291. WOLFSSL_API PKCS7* wc_PKCS7_New(void* heap, int devId);
  292. WOLFSSL_API int wc_PKCS7_Init(PKCS7* pkcs7, void* heap, int devId);
  293. WOLFSSL_API int wc_PKCS7_InitWithCert(PKCS7* pkcs7, byte* der, word32 derSz);
  294. WOLFSSL_API int wc_PKCS7_AddCertificate(PKCS7* pkcs7, byte* der, word32 derSz);
  295. WOLFSSL_API void wc_PKCS7_Free(PKCS7* pkcs7);
  296. WOLFSSL_API int wc_PKCS7_GetAttributeValue(PKCS7* pkcs7, const byte* oid,
  297. word32 oidSz, byte* out, word32* outSz);
  298. WOLFSSL_API int wc_PKCS7_SetSignerIdentifierType(PKCS7* pkcs7, int type);
  299. WOLFSSL_API int wc_PKCS7_SetContentType(PKCS7* pkcs7, byte* contentType,
  300. word32 sz);
  301. WOLFSSL_API int wc_PKCS7_GetPadSize(word32 inputSz, word32 blockSz);
  302. WOLFSSL_API int wc_PKCS7_PadData(byte* in, word32 inSz, byte* out, word32 outSz,
  303. word32 blockSz);
  304. /* CMS/PKCS#7 Data */
  305. WOLFSSL_API int wc_PKCS7_EncodeData(PKCS7* pkcs7, byte* output,
  306. word32 outputSz);
  307. /* CMS/PKCS#7 SignedData */
  308. WOLFSSL_API int wc_PKCS7_SetDetached(PKCS7* pkcs7, word16 flag);
  309. WOLFSSL_API int wc_PKCS7_NoDefaultSignedAttribs(PKCS7* pkcs7);
  310. WOLFSSL_API int wc_PKCS7_EncodeSignedData(PKCS7* pkcs7,
  311. byte* output, word32 outputSz);
  312. WOLFSSL_API int wc_PKCS7_EncodeSignedData_ex(PKCS7* pkcs7, const byte* hashBuf,
  313. word32 hashSz, byte* outputHead,
  314. word32* outputHeadSz,
  315. byte* outputFoot,
  316. word32* outputFootSz);
  317. WOLFSSL_API void wc_PKCS7_AllowDegenerate(PKCS7* pkcs7, word16 flag);
  318. WOLFSSL_API int wc_PKCS7_VerifySignedData(PKCS7* pkcs7,
  319. byte* pkiMsg, word32 pkiMsgSz);
  320. WOLFSSL_API int wc_PKCS7_VerifySignedData_ex(PKCS7* pkcs7, const byte* hashBuf,
  321. word32 hashSz, byte* pkiMsgHead,
  322. word32 pkiMsgHeadSz, byte* pkiMsgFoot,
  323. word32 pkiMsgFootSz);
  324. WOLFSSL_API int wc_PKCS7_GetSignerSID(PKCS7* pkcs7, byte* out, word32* outSz);
  325. /* CMS single-shot API for Signed FirmwarePkgData */
  326. WOLFSSL_API int wc_PKCS7_EncodeSignedFPD(PKCS7* pkcs7, byte* privateKey,
  327. word32 privateKeySz, int signOID,
  328. int hashOID, byte* content,
  329. word32 contentSz,
  330. PKCS7Attrib* signedAttribs,
  331. word32 signedAttribsSz, byte* output,
  332. word32 outputSz);
  333. #ifndef NO_PKCS7_ENCRYPTED_DATA
  334. /* CMS single-shot API for Signed Encrypted FirmwarePkgData */
  335. WOLFSSL_API int wc_PKCS7_EncodeSignedEncryptedFPD(PKCS7* pkcs7,
  336. byte* encryptKey, word32 encryptKeySz,
  337. byte* privateKey, word32 privateKeySz,
  338. int encryptOID, int signOID,
  339. int hashOID, byte* content,
  340. word32 contentSz,
  341. PKCS7Attrib* unprotectedAttribs,
  342. word32 unprotectedAttribsSz,
  343. PKCS7Attrib* signedAttribs,
  344. word32 signedAttribsSz,
  345. byte* output, word32 outputSz);
  346. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  347. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  348. /* CMS single-shot API for Signed Compressed FirmwarePkgData */
  349. WOLFSSL_API int wc_PKCS7_EncodeSignedCompressedFPD(PKCS7* pkcs7,
  350. byte* privateKey, word32 privateKeySz,
  351. int signOID, int hashOID,
  352. byte* content, word32 contentSz,
  353. PKCS7Attrib* signedAttribs,
  354. word32 signedAttribsSz, byte* output,
  355. word32 outputSz);
  356. #ifndef NO_PKCS7_ENCRYPTED_DATA
  357. /* CMS single-shot API for Signed Encrypted Compressed FirmwarePkgData */
  358. WOLFSSL_API int wc_PKCS7_EncodeSignedEncryptedCompressedFPD(PKCS7* pkcs7,
  359. byte* encryptKey, word32 encryptKeySz,
  360. byte* privateKey, word32 privateKeySz,
  361. int encryptOID, int signOID,
  362. int hashOID, byte* content,
  363. word32 contentSz,
  364. PKCS7Attrib* unprotectedAttribs,
  365. word32 unprotectedAttribsSz,
  366. PKCS7Attrib* signedAttribs,
  367. word32 signedAttribsSz,
  368. byte* output, word32 outputSz);
  369. #endif /* !NO_PKCS7_ENCRYPTED_DATA */
  370. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  371. /* EnvelopedData and AuthEnvelopedData RecipientInfo functions */
  372. WOLFSSL_API int wc_PKCS7_AddRecipient_KTRI(PKCS7* pkcs7, const byte* cert,
  373. word32 certSz, int options);
  374. WOLFSSL_API int wc_PKCS7_AddRecipient_KARI(PKCS7* pkcs7, const byte* cert,
  375. word32 certSz, int keyWrapOID,
  376. int keyAgreeOID, byte* ukm,
  377. word32 ukmSz, int options);
  378. WOLFSSL_API int wc_PKCS7_SetKey(PKCS7* pkcs7, byte* key, word32 keySz);
  379. WOLFSSL_API int wc_PKCS7_AddRecipient_KEKRI(PKCS7* pkcs7, int keyWrapOID,
  380. byte* kek, word32 kekSz,
  381. byte* keyID, word32 keyIdSz,
  382. void* timePtr, byte* otherOID,
  383. word32 otherOIDSz, byte* other,
  384. word32 otherSz, int options);
  385. WOLFSSL_API int wc_PKCS7_SetPassword(PKCS7* pkcs7, byte* passwd, word32 pLen);
  386. WOLFSSL_API int wc_PKCS7_AddRecipient_PWRI(PKCS7* pkcs7, byte* passwd,
  387. word32 pLen, byte* salt,
  388. word32 saltSz, int kdfOID,
  389. int prfOID, int iterations,
  390. int kekEncryptOID, int options);
  391. WOLFSSL_API int wc_PKCS7_SetOriEncryptCtx(PKCS7* pkcs7, void* ctx);
  392. WOLFSSL_API int wc_PKCS7_SetOriDecryptCtx(PKCS7* pkcs7, void* ctx);
  393. WOLFSSL_API int wc_PKCS7_SetOriDecryptCb(PKCS7* pkcs7, CallbackOriDecrypt cb);
  394. WOLFSSL_API int wc_PKCS7_AddRecipient_ORI(PKCS7* pkcs7, CallbackOriEncrypt cb,
  395. int options);
  396. WOLFSSL_API int wc_PKCS7_SetWrapCEKCb(PKCS7* pkcs7,
  397. CallbackWrapCEK wrapCEKCb);
  398. #if defined(HAVE_PKCS7_RSA_RAW_SIGN_CALLBACK) && !defined(NO_RSA)
  399. WOLFSSL_API int wc_PKCS7_SetRsaSignRawDigestCb(PKCS7* pkcs7,
  400. CallbackRsaSignRawDigest cb);
  401. #endif
  402. /* CMS/PKCS#7 EnvelopedData */
  403. WOLFSSL_API int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7,
  404. byte* output, word32 outputSz);
  405. WOLFSSL_API int wc_PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* pkiMsg,
  406. word32 pkiMsgSz, byte* output,
  407. word32 outputSz);
  408. /* CMS/PKCS#7 AuthEnvelopedData */
  409. WOLFSSL_API int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7,
  410. byte* output, word32 outputSz);
  411. WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(PKCS7* pkcs7, byte* pkiMsg,
  412. word32 pkiMsgSz, byte* output,
  413. word32 outputSz);
  414. /* CMS/PKCS#7 EncryptedData */
  415. #ifndef NO_PKCS7_ENCRYPTED_DATA
  416. WOLFSSL_API int wc_PKCS7_EncodeEncryptedData(PKCS7* pkcs7,
  417. byte* output, word32 outputSz);
  418. WOLFSSL_API int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* pkiMsg,
  419. word32 pkiMsgSz, byte* output,
  420. word32 outputSz);
  421. WOLFSSL_API int wc_PKCS7_SetDecodeEncryptedCb(PKCS7* pkcs7,
  422. CallbackDecryptContent decryptionCb);
  423. WOLFSSL_API int wc_PKCS7_SetDecodeEncryptedCtx(PKCS7* pkcs7, void* ctx);
  424. #endif /* NO_PKCS7_ENCRYPTED_DATA */
  425. /* CMS/PKCS#7 CompressedData */
  426. #if defined(HAVE_LIBZ) && !defined(NO_PKCS7_COMPRESSED_DATA)
  427. WOLFSSL_API int wc_PKCS7_EncodeCompressedData(PKCS7* pkcs7, byte* output,
  428. word32 outputSz);
  429. WOLFSSL_API int wc_PKCS7_DecodeCompressedData(PKCS7* pkcs7, byte* pkiMsg,
  430. word32 pkiMsgSz, byte* output,
  431. word32 outputSz);
  432. #endif /* HAVE_LIBZ && !NO_PKCS7_COMPRESSED_DATA */
  433. #ifdef __cplusplus
  434. } /* extern "C" */
  435. #endif
  436. #endif /* HAVE_PKCS7 */
  437. #endif /* WOLF_CRYPT_PKCS7_H */