4 Contains: interface for low-level comcryption engine
6 Written by: Doug Mitchell
8 Copyright: (c) 1997 by Apple Computer, Inc., all rights reserved.
10 Change History (most recent first):
12 11/11/97 gab Updated for MPW
13 10/29/97 dm Created, based on work by R. Crandall,
18 #ifndef _COMCRYPTION_H_
19 #define _COMCRYPTION_H_
29 CCR_SUCCESS
= 0, // normal result
30 CCR_OUTBUFFER_TOO_SMALL
, // caller needs to alloc more out buffer
31 CCR_MEMORY_ERROR
, // internal error
32 CCR_WRONG_VERSION
, // compatibility error
33 CCR_BAD_CIPHERTEXT
, // can't decrypt ciphertext stream
34 CCR_INTERNAL
// internal library error
38 * Used to specify optimization in ComcryptInit(). May be ignored in
39 * early implementation.
42 CCO_DEFAULT
, // let the low-level code decide
43 CCO_SIZE
, // optimize for max compression
44 CCO_SECURITY
, // optimize for max crypto security
45 CCO_TIME
, // optimize for minimum runtime; implies no
46 // second-level comcryption; security not
48 CCO_TIME_SIZE
, // minimum runtime with second-level
49 // comcryption enabled; implies loss of
51 CCO_ASCII
, // optimize for max compression for ASCII
57 * Used to specify operation type.
65 * Used to specify End of stream.
68 CCE_MORE_TO_COME
, // more ops to follow
69 CCE_END_OF_STREAM
// end of stream, close output strem
73 * Maximum key length in bytes.
75 #define COMCRYPT_MAX_KEYLENGTH 64
78 * Clients can *optionally* register external memory alloc/free functions here.
80 typedef void *(comMallocExternFcn
)(unsigned size
);
81 typedef void (comFreeExternFcn
)(void *data
);
82 void comMallocRegister(comMallocExternFcn
*mallocExtern
,
83 comFreeExternFcn
*freeExtern
);
86 * Opaque data type for ComCryptData() and DeComCryptData()
88 typedef void *comcryptObj
;
91 * Call once at startup. The resulting comcryptObj can be reused multiple
94 comcryptObj
comcryptAlloc();
97 * Use this before starting every stream process
99 comcryptReturn
comcryptInit(
101 const unsigned char *key
,
103 comcryptOptimize optimize
); // CCO_SIZE, etc.
106 * Free a comcryptObj object obtained via comcryptAlloc()
108 void comcryptObjFree(comcryptObj cobj
);
111 * Return the maximum input buffer size allowed for for specified
112 * output buffer size. Note that for both comcrypt and decomcrypt,
113 * to cover the worst case, the output buffer always has to be
114 * larger that the input buffer.
116 unsigned comcryptMaxInBufSize(comcryptObj cobj
,
118 comcryptOp op
); // CCOP_COMCRYPT, etc.
121 * Return the maximum output buffer size for specified input buffer size.
122 * Output buffer size will always be larger than input buffer size.
124 unsigned comcryptMaxOutBufSize(comcryptObj cobj
,
126 comcryptOp op
, // CCOP_COMCRYPT, etc.
127 char final
); // nonzero for last op
128 // only used for CCOP_DECOMCRYPT
131 * the one-function-fits-all comcrypt routine -
132 * call it multiple times for one ComcryptObj if
133 * you want, or just once to do a whole stream
136 * NOTE: in the current implementation, the endOfStream is not used;
137 * no "final" call is necessary on comcryption.
139 comcryptReturn
comcryptData(
141 unsigned char *plainText
,
142 unsigned plainTextLen
,
143 unsigned char *cipherText
, // malloc'd by caller
144 unsigned *cipherTextLen
, // IN/OUT
145 comcryptEos endOfStream
); // CCE_END_OF_STREAM, etc.
148 * decomcrypt routine - call it multiple times for
149 * one comcryptObj, or just once to do a whole stream
150 * in one shot. Boundaries of ciphertext segments -
151 * across calls to this function - are arbitrary.
153 * NOTE: in the current implementation, the final call to this (when
154 * endOfStrem == CCE_END_OF_STREAM) must contain a nonzero amount of
157 comcryptReturn
deComcryptData(
159 unsigned char *cipherText
,
160 unsigned cipherTextLen
,
161 unsigned char *plainText
,
162 unsigned *plainTextLen
, // IN/OUT
163 comcryptEos endOfStream
); // CCE_END_OF_STREAM, etc.
169 #endif /*_COMCRYPTION_H_*/