]> git.saurik.com Git - apple/security.git/blob - Security/libsecurity_cryptkit/lib/feeDES.h
Security-57031.40.6.tar.gz
[apple/security.git] / Security / libsecurity_cryptkit / lib / feeDES.h
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 * FeeDES.h - generic, portable DES encryption object
12 *
13 * Revision History
14 * ----------------
15 * 26 Aug 96 at NeXT
16 * Created.
17 */
18
19 #ifndef _CK_FEEDES_H_
20 #define _CK_FEEDES_H_
21
22 #if !defined(__MACH__)
23 #include <ckconfig.h>
24 #include <feeTypes.h>
25 #else
26 #include <security_cryptkit/ckconfig.h>
27 #include <security_cryptkit/feeTypes.h>
28 #endif
29
30 #if CRYPTKIT_SYMMETRIC_ENABLE
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #define FEE_DES_MIN_STATE_SIZE 8
37
38 /*
39 * Opaque object handle.
40 */
41 typedef void *feeDES;
42
43 /*
44 * Alloc and init a feeDES object with specified initial state.
45 * State must be at least 8 bytes; only 8 bytes are used, ignoring
46 * MSB of each bytes.
47 */
48 feeDES feeDESNewWithState(const unsigned char *state,
49 unsigned stateLen);
50
51 void feeDESFree(feeDES des);
52
53 /*
54 * Set new initial state.
55 */
56 feeReturn feeDESSetState(feeDES des,
57 const unsigned char *state,
58 unsigned stateLen);
59
60 /*
61 * Set block or chain (CBC) mode. CBC is default.
62 */
63 void feeDESSetBlockMode(feeDES des);
64 void feeDESSetChainMode(feeDES des);
65
66 /*
67 * Plaintext block size.
68 */
69 unsigned feeDESPlainBlockSize(feeDES des);
70
71 /*
72 * Ciphertext block size used for decryption.
73 */
74 unsigned feeDESCipherBlockSize(feeDES des);
75
76 /*
77 * Required size of buffer for ciphertext, upon encrypting one
78 * block of plaintext.
79 */
80 unsigned feeDESCipherBufSize(feeDES des);
81
82 /*
83
84 * Return the size of ciphertext to hold specified size of plaintext.
85
86 */
87
88 unsigned feeDESCipherTextSize(feeDES des, unsigned plainTextSize);
89
90
91 /*
92 * Key size in bits.
93 */
94 unsigned feeDESKeySize(feeDES des);
95
96 /*
97 * Encrypt a block or less of data. Caller malloc's cipherText. Generates
98 * up to (2 * feeDESBlockSize) bytes of cipherText. If plainTextLen is
99 * less than feeDESBlockSize, finalBlock must be true.
100 */
101 feeReturn feeDESEncryptBlock(feeDES des,
102 const unsigned char *plainText,
103 unsigned plainTextLen,
104 unsigned char *cipherText,
105 unsigned *cipherTextLen, // RETURNED
106 int finalBlock);
107
108 /*
109 * Decrypt (exactly) a block of data. Caller malloc's plainText. Always
110 * generates feeDESBlockSize bytes of plainText, unless 'finalBlock' is
111 * non-zero (in which case feeDESBlockSize or less bytes of plainText are
112 * generated).
113 */
114 feeReturn feeDESDecryptBlock(feeDES des,
115 const unsigned char *cipherText,
116 unsigned cipherTextLen,
117 unsigned char *plainText,
118 unsigned *plainTextLen, // RETURNED
119 int finalBlock);
120
121 /*
122 * Convenience routines to encrypt & decrypt multi-block data.
123 */
124 feeReturn feeDESEncrypt(feeDES des,
125 const unsigned char *plainText,
126 unsigned plainTextLen,
127 unsigned char **cipherText, // malloc'd and RETURNED
128 unsigned *cipherTextLen); // RETURNED
129
130 feeReturn feeDESDecrypt(feeDES des,
131 const unsigned char *cipherText,
132 unsigned cipherTextLen,
133 unsigned char **plainText, // malloc'd and RETURNED
134 unsigned *plainTextLen); // RETURNED
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif /* CRYPTKIT_SYMMETRIC_ENABLE */
141 #endif /*_CK_FEEDES_H_*/