]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cryptkit/lib/feeFEEDExp.h
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_cryptkit / lib / feeFEEDExp.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 * feeFEEDExp.h - generic FEED encryption object using 2:1 expansion
12 *
13 * Revision History
14 * ----------------
15 * 28 Aug 96 at NeXT
16 * Created.
17 */
18
19 #ifndef _CK_FEEFEEDEXP_H_
20 #define _CK_FEEFEEDEXP_H_
21
22 #if !defined(__MACH__)
23 #include <ckconfig.h>
24 #include <feeTypes.h>
25 #include <feePublicKey.h>
26 #else
27 #include <security_cryptkit/ckconfig.h>
28 #include <security_cryptkit/feeTypes.h>
29 #include <security_cryptkit/feePublicKey.h>
30 #endif
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /*
37 * Opaque object handle.
38 */
39 typedef void *feeFEEDExp;
40
41 /*
42 * Alloc and init a feeFEEDExp object associated with specified feePubKey.
43 */
44 feeFEEDExp feeFEEDExpNewWithPubKey(
45 feePubKey pubKey,
46 feeRandFcn randFcn, // optional
47 void *randRef);
48
49 void feeFEEDExpFree(feeFEEDExp feed);
50
51 /*
52 * Plaintext block size.
53 */
54 unsigned feeFEEDExpPlainBlockSize(feeFEEDExp feed);
55
56 /*
57 * Ciphertext block size used for decryption.
58 */
59 unsigned feeFEEDExpCipherBlockSize(feeFEEDExp feed);
60
61 /*
62 * Required size of buffer for ciphertext, upon encrypting one
63 * block of plaintext.
64 */
65 unsigned feeFEEDExpCipherBufSize(feeFEEDExp feed);
66
67 /*
68 * Return the size of ciphertext to hold specified size of encrypted plaintext.
69 */
70 unsigned feeFEEDExpCipherTextSize(feeFEEDExp feed, unsigned plainTextSize);
71
72 /*
73 * Return the size of plaintext to hold specified size of decrypted ciphertext.
74 */
75 unsigned feeFEEDExpPlainTextSize(feeFEEDExp feed, unsigned cipherTextSize);
76
77 /*
78 * Encrypt a block or less of data. Caller malloc's cipherText. Generates
79 * feeFEEDExpCipherBlockSize() bytes of cipherText if finalBlock is false;
80 * if finalBlock is true it could produce twice as much ciphertext.
81 * If plainTextLen is less than feeFEEDExpPlainBlockSize(), finalBlock must be true.
82 */
83 feeReturn feeFEEDExpEncryptBlock(feeFEEDExp feed,
84 const unsigned char *plainText,
85 unsigned plainTextLen,
86 unsigned char *cipherText,
87 unsigned *cipherTextLen, // RETURNED
88 int finalBlock);
89
90 /*
91 * Decrypt (exactly) a block of data. Caller malloc's plainText. Always
92 * generates feeFEEDExpBlockSize bytes of plainText, unless 'finalBlock' is
93 * non-zero (in which case feeFEEDExpBlockSize or less bytes of plainText are
94 * generated).
95 */
96 feeReturn feeFEEDExpDecryptBlock(feeFEEDExp feed,
97 const unsigned char *cipherText,
98 unsigned cipherTextLen,
99 unsigned char *plainText,
100 unsigned *plainTextLen, // RETURNED
101 int finalBlock);
102
103 /*
104 * Convenience routines to encrypt & decrypt multi-block data.
105 */
106 feeReturn feeFEEDExpEncrypt(feeFEEDExp feed,
107 const unsigned char *plainText,
108 unsigned plainTextLen,
109 unsigned char **cipherText, // malloc'd and RETURNED
110 unsigned *cipherTextLen); // RETURNED
111
112 feeReturn feeFEEDExpDecrypt(feeFEEDExp feed,
113 const unsigned char *cipherText,
114 unsigned cipherTextLen,
115 unsigned char **plainText, // malloc'd and RETURNED
116 unsigned *plainTextLen); // RETURNED
117
118 #ifdef __cplusplus
119 }
120 #endif
121
122 #endif /*_CK_FEEFEEDEXP_H_*/