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