feeFEED.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 * FeeFEED.h - generic, portable FEED encryption object 12 * 13 * Revision History 14 * ---------------- 15 * 28 Aug 96 at NeXT 16 * Created. 17 */ 18 19 #ifndef _CK_FEEFEED_H_ 20 #define _CK_FEEFEED_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 *feeFEED; 40 41 /* 42 * forEncrypt argument values. 43 */ 44 #define FF_DECRYPT 0 45 #define FF_ENCRYPT 1 46 47 /* 48 * Alloc and init a feeFEED object associated with specified feePubKey 49 * objects. 50 */ 51 feeFEED feeFEEDNewWithPubKey(feePubKey myPrivKey, 52 feePubKey theirPubKey, 53 int forEncrypt, // FF_DECRYPT, FF_ENCRYPT 54 feeRandFcn randFcn, // optional 55 void *randRef); 56 57 void feeFEEDFree(feeFEED feed); 58 59 /* 60 * Plaintext block size. 61 */ 62 unsigned feeFEEDPlainBlockSize(feeFEED feed); 63 64 /* 65 * Ciphertext block size used for decryption. 66 */ 67 unsigned feeFEEDCipherBlockSize(feeFEED feed); 68 69 /* 70 * Calculate size of buffer currently needed to encrypt one block of 71 * plaintext. 72 */ 73 unsigned feeFEEDCipherBufSize(feeFEED feed, 74 int finalBlock); 75 76 /* 77 * Return the size of ciphertext currently needed to encrypt specified 78 * size of plaintext. Also can be used to calculate size of ciphertext 79 * which can be decrypted into specified size of plaintext. 80 */ 81 unsigned feeFEEDCipherTextSize(feeFEED feed, 82 unsigned plainTextSize, 83 int finalBlock); 84 85 /* 86 * Return the size of plaintext currently needed to decrypt specified size 87 * of ciphertext. Also can be used to calculate size of plaintext 88 * which can be encrypted into specified size of ciphertext. 89 */ 90 unsigned feeFEEDPlainTextSize(feeFEED feed, 91 unsigned cipherTextSize, 92 int finalBlock); // ignored if decrypting 93 94 /* 95 * Encrypt a block or less of data. Caller malloc's cipherText. 96 */ 97 feeReturn feeFEEDEncryptBlock(feeFEED feed, 98 const unsigned char *plainText, 99 unsigned plainTextLen, 100 unsigned char *cipherText, 101 unsigned *cipherTextLen, // RETURNED 102 int finalBlock); 103 104 /* 105 * Decrypt (exactly) a block of data. Caller malloc's plainText. Always 106 * generates feeFEEDBlockSize bytes of plainText, unless 'finalBlock' is 107 * non-zero (in which case feeFEEDBlockSize or less bytes of plainText are 108 * generated). 109 */ 110 feeReturn feeFEEDDecryptBlock(feeFEED feed, 111 const unsigned char *cipherText, 112 unsigned cipherTextLen, 113 unsigned char *plainText, 114 unsigned *plainTextLen, // RETURNED 115 int finalBlock); 116 117 /* 118 * Convenience routines to encrypt & decrypt multi-block data. 119 */ 120 feeReturn feeFEEDEncrypt(feeFEED feed, 121 const unsigned char *plainText, 122 unsigned plainTextLen, 123 unsigned char **cipherText, // malloc'd and RETURNED 124 unsigned *cipherTextLen); // RETURNED 125 126 feeReturn feeFEEDDecrypt(feeFEED feed, 127 const unsigned char *cipherText, 128 unsigned cipherTextLen, 129 unsigned char **plainText, // malloc'd and RETURNED 130 unsigned *plainTextLen); // RETURNED 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 #endif /*_CK_FEEFEED_H_*/