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