1/* Copyright (c) 1998,2011,2014 Apple Inc.  All Rights Reserved.
2 *
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 ***************************************************************************
10 *
11 * feeCipherFile.h
12 *
13 * Revision History
14 * ----------------
15 * 24 Oct 96 at NeXT
16 *	Created.
17 */
18
19#ifndef	_CK_FEECIPHERFILE_H_
20#define _CK_FEECIPHERFILE_H_
21
22#if	!defined(__MACH__)
23#include <ckconfig.h>
24#include <feeTypes.h>
25#include <feePublicKey.h>
26#include <CipherFileTypes.h>
27#else
28#include "ckconfig.h"
29#include "feeTypes.h"
30#include "feePublicKey.h"
31#include "CipherFileTypes.h"
32#endif
33
34#if	CRYPTKIT_CIPHERFILE_ENABLE
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/*
41 * Opaque cipherfile object.
42 */
43typedef void *feeCipherFile;
44
45/*
46 * Alloc and return a new feeCipherFile object associated with the specified
47 * data.
48 */
49feeCipherFile 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
59
60/*
61 * Obtain the contents of a feeCipherFile as a byte stream. Caller must free
62 * the returned data.
63 */
64feeReturn feeCFileDataRepresentation(feeCipherFile cipherFile,
65	const unsigned char **dataRep,	// RETURNED
66	unsigned *dataRepLen);		// RETURNED
67
68/*
69 * Alloc and return a new feeCipherFile object, given a byte stream (originally
70 * obtained from feeCFDataRepresentation()).
71 */
72feeReturn feeCFileNewFromDataRep(const unsigned char *dataRep,
73	unsigned dataRepLen,
74	feeCipherFile *cipherFile);	// RETURNED if sucessful
75
76/*
77 * Free a feeCipherFile object.
78 */
79void feeCFileFree(feeCipherFile cipherFile);
80
81/*
82 * Given a feeCipherFile object (typically obtained from
83 * feeCFileNewFromDataRep()), obtain its constituent parts.
84 *
85 * Data returned must be freed by caller.
86 * feeCFileSigData(), feeCFileSendPubKeyData, and feeCFileOtherKeyData()
87 * may return NULL, indicating component not present.
88 */
89cipherFileEncrType feeCFileEncrType(feeCipherFile cipherFile);
90unsigned char *feeCFileCipherText(feeCipherFile cipherFile,
91	unsigned *cipherTextLen);		// RETURNED
92unsigned char *feeCFileSendPubKeyData(feeCipherFile cipherFile,
93	unsigned *sendPubKeyDataLen);		// RETURNED
94unsigned char *feeCFileOtherKeyData(feeCipherFile cipherFile,
95	unsigned *otherKeyDataLen);		// RETURNED
96unsigned char *feeCFileSigData(feeCipherFile cipherFile,
97	unsigned *sigDataLen);			// RETURNED
98unsigned feeCFileUserData(feeCipherFile cipherFile);
99
100/*
101 * High-level feeCipherFile support.
102 */
103
104/*
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.
110 */
111feeReturn 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
121
122/*
123 * Parse and decrypt a cipherfile given its data representation.
124 *
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.
128 */
129feeReturn 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
139
140/*
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.
145 *
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().
151 */
152feeReturn 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
158
159#ifdef __cplusplus
160}
161#endif
162
163#endif	/* CRYPTKIT_CIPHERFILE_ENABLE */
164#endif	/*_CK_FEECIPHERFILE_H_*/
165