1 /* Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved.
3 * NOTICE: USE OF THE MATERIALS ACCOMPANYING THIS NOTICE IS SUBJECT
4 * TO THE TERMS OF THE SIGNED "FAST ELLIPTIC ENCRYPTION (FEE) REFERENCE
5 * SOURCE CODE EVALUATION AGREEMENT" BETWEEN APPLE, INC. AND THE
6 * ORIGINAL LICENSEE THAT OBTAINED THESE MATERIALS FROM APPLE,
7 * INC. ANY USE OF THESE MATERIALS NOT PERMITTED BY SUCH AGREEMENT WILL
8 * EXPOSE YOU TO LIABILITY.
9 ***************************************************************************
19 #ifndef _CK_FEECIPHERFILE_H_
20 #define _CK_FEECIPHERFILE_H_
22 #if !defined(__MACH__)
25 #include <feePublicKey.h>
26 #include <CipherFileTypes.h>
30 #include "feePublicKey.h"
31 #include "CipherFileTypes.h"
34 #if CRYPTKIT_CIPHERFILE_ENABLE
41 * Opaque cipherfile object.
43 typedef void *feeCipherFile
;
46 * Alloc and return a new feeCipherFile object associated with the specified
49 feeCipherFile
feeCFileNewFromCipherText(cipherFileEncrType encrType
,
50 const unsigned char *cipherText
,
51 unsigned cipherTextLen
,
52 const unsigned char *sendPubKeyData
,
53 unsigned sendPubKeyDataLen
,
54 const unsigned char *otherKeyData
,
55 unsigned otherKeyDataDataLen
,
56 const unsigned char *sigData
, // optional; NULL means no signature
57 unsigned sigDataLen
, // 0 if sigData is NULL
58 unsigned userData
); // for caller's convenience
61 * Obtain the contents of a feeCipherFile as a byte stream. Caller must free
64 feeReturn
feeCFileDataRepresentation(feeCipherFile cipherFile
,
65 const unsigned char **dataRep
, // RETURNED
66 unsigned *dataRepLen
); // RETURNED
69 * Alloc and return a new feeCipherFile object, given a byte stream (originally
70 * obtained from feeCFDataRepresentation()).
72 feeReturn
feeCFileNewFromDataRep(const unsigned char *dataRep
,
74 feeCipherFile
*cipherFile
); // RETURNED if sucessful
77 * Free a feeCipherFile object.
79 void feeCFileFree(feeCipherFile cipherFile
);
82 * Given a feeCipherFile object (typically obtained from
83 * feeCFileNewFromDataRep()), obtain its constituent parts.
85 * Data returned must be freed by caller.
86 * feeCFileSigData(), feeCFileSendPubKeyData, and feeCFileOtherKeyData()
87 * may return NULL, indicating component not present.
89 cipherFileEncrType
feeCFileEncrType(feeCipherFile cipherFile
);
90 unsigned char *feeCFileCipherText(feeCipherFile cipherFile
,
91 unsigned *cipherTextLen
); // RETURNED
92 unsigned char *feeCFileSendPubKeyData(feeCipherFile cipherFile
,
93 unsigned *sendPubKeyDataLen
); // RETURNED
94 unsigned char *feeCFileOtherKeyData(feeCipherFile cipherFile
,
95 unsigned *otherKeyDataLen
); // RETURNED
96 unsigned char *feeCFileSigData(feeCipherFile cipherFile
,
97 unsigned *sigDataLen
); // RETURNED
98 unsigned feeCFileUserData(feeCipherFile cipherFile
);
101 * High-level feeCipherFile support.
105 * Obtain the data representation of a feeCipherFile given the specified
106 * plainText and cipherFileEncrType.
107 * Receiver's public key is required for all encrTypes; sender's private
108 * key is required for signature generation and also for encrType
109 * CFE_PublicDES and CFE_FEED.
111 feeReturn
createCipherFile(feePubKey sendPrivKey
,
112 feePubKey recvPubKey
,
113 cipherFileEncrType encrType
,
114 const unsigned char *plainText
,
115 unsigned plainTextLen
,
116 int genSig
, // 1 ==> generate signature
117 int doEnc64
, // 1 ==> perform enc64
118 unsigned userData
, // for caller's convenience
119 unsigned char **cipherFileData
, // RETURNED
120 unsigned *cipherFileDataLen
); // RETURNED
123 * Parse and decrypt a cipherfile given its data representation.
125 * recvPrivKey is required in all cases. If sendPubKey is present,
126 * sendPubKey - rather than the embedded sender's public key - will be
127 * used for signature validation.
129 feeReturn
parseCipherFile(feePubKey recvPrivKey
, // required
130 feePubKey sendPubKey
, // optional, for signature
131 const unsigned char *cipherFileData
,
132 unsigned cipherFileDataLen
,
133 int doDec64
, // 1 ==> perform dec64
134 cipherFileEncrType
*encrType
, // RETURNED
135 unsigned char **plainText
, // malloc'd & RETURNED
136 unsigned *plainTextLen
, // RETURNED
137 feeSigStatus
*sigStatus
, // RETURNED
138 unsigned *userData
); // RETURNED
141 * Decrypt a feeCipherFile object obtained via feeCFileNewFromDataRep().
142 * recvPrivKey is required in all cases. If sendPubKey is present,
143 * sendPubKey - rather than the embedded sender's public key - will be
144 * used for signature validation.
146 * Note: this function is used (in conjunction with feeCFileNewFromDataRep())
147 * rather than the simpler parseCipherFile(), in case the caller needs
148 * access to CipherFile fields not returned in parseCipherFile(). For
149 * example, the caller might want to get the sender's public key data
150 * via feeCFileSendPubKeyData().
152 feeReturn
decryptCipherFile(feeCipherFile cipherFile
,
153 feePubKey recvPrivKey
, // required
154 feePubKey sendPubKey
, // optional, for signature
155 unsigned char **plainText
, // malloc'd & RETURNED
156 unsigned *plainTextLen
, // RETURNED
157 feeSigStatus
*sigStatus
); // RETURNED
163 #endif /* CRYPTKIT_CIPHERFILE_ENABLE */
164 #endif /*_CK_FEECIPHERFILE_H_*/