]> git.saurik.com Git - apple/security.git/blob - libsecurity_apple_csp/lib/FEEAsymmetricContext.h
Security-55163.44.tar.gz
[apple/security.git] / libsecurity_apple_csp / lib / FEEAsymmetricContext.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /*
20 * FEEAsymmetricContext.h - CSPContexts for FEE asymmetric encryption
21 *
22 * Created March 8 2001 by dmitch.
23 */
24
25 #ifdef CRYPTKIT_CSP_ENABLE
26
27 #ifndef _FEE_ASYMMETRIC_CONTEXT_H_
28 #define _FEE_ASYMMETRIC_CONTEXT_H_
29
30 #include <security_cdsa_plugin/CSPsession.h>
31 #include "AppleCSP.h"
32 #include "AppleCSPContext.h"
33 #include "AppleCSPSession.h"
34 #include "BlockCryptor.h"
35 #include <security_cryptkit/feeFEED.h>
36 #include <security_cryptkit/feeFEEDExp.h>
37
38 namespace CryptKit {
39
40 class FEEDContext : public BlockCryptor {
41 public:
42 FEEDContext(AppleCSPSession &session) :
43 BlockCryptor(session),
44 mFeeFeed(NULL),
45 mPrivKey(NULL),
46 mPubKey(NULL),
47 mInitFlag(false) { }
48 ~FEEDContext();
49
50 /* called by CSPFullPluginSession */
51 void init(const Context &context, bool encoding = true);
52
53 /* called by BlockCryptor */
54 void encryptBlock(
55 const void *plainText, // length implied (one block)
56 size_t plainTextLen,
57 void *cipherText,
58 size_t &cipherTextLen, // in/out, throws on overflow
59 bool final);
60 void decryptBlock(
61 const void *cipherText, // length implied (one cipher block)
62 size_t cipherTextLen,
63 void *plainText,
64 size_t &plainTextLen, // in/out, throws on overflow
65 bool final);
66
67 /*
68 * Additional query size support, necessary because we don't conform to
69 * BlockCryptor's standard one-to-one block scheme
70 */
71 size_t inputSize(
72 size_t outSize); // input for given output size
73 size_t outputSize(
74 bool final = false,
75 size_t inSize = 0); // output for given input size
76 void minimumProgress(
77 size_t &in,
78 size_t &out); // minimum progress chunks
79
80
81 private:
82 feeFEED mFeeFeed;
83 feePubKey mPrivKey;
84 bool mAllocdPrivKey;
85 feePubKey mPubKey;
86 bool mAllocdPubKey;
87 bool mInitFlag; // allows easy reuse
88 }; /* FEEDContext */
89
90
91 class FEEDExpContext : public BlockCryptor {
92 public:
93 FEEDExpContext(AppleCSPSession &session) :
94 BlockCryptor(session),
95 mFeeFeedExp(NULL),
96 mFeeKey(NULL),
97 mInitFlag(false) { }
98
99 ~FEEDExpContext();
100
101 /* called by CSPFullPluginSession */
102 void init(const Context &context, bool encoding = true);
103
104 /* called by BlockCryptor */
105 void encryptBlock(
106 const void *plainText, // length implied (one block)
107 size_t plainTextLen,
108 void *cipherText,
109 size_t &cipherTextLen, // in/out, throws on overflow
110 bool final);
111 void decryptBlock(
112 const void *cipherText, // length implied (one cipher block)
113 size_t cipherTextLen,
114 void *plainText,
115 size_t &plainTextLen, // in/out, throws on overflow
116 bool final);
117
118 private:
119 feeFEEDExp mFeeFeedExp;
120 feePubKey mFeeKey;
121 bool mAllocdFeeKey;
122 bool mInitFlag; // allows easy reuse
123 }; /* FEEDExpContext */
124
125 /*
126 * Elliptic curve Diffie-Hellman key exchange. The public key is
127 * specified in one of two ways - a raw X9.62 format public key
128 * string in Param, or a CSSM_KEY in the Context.
129 * Requested size, in keyData->Length, must be the same size as
130 * the keys' modulus. Data is returned in keyData->Data, which is
131 * allocated by the caller.
132 * Optionally performs X9.63 key derivation if algId ==
133 * CSSM_ALGID_ECDH_X963_KDF, with the optional SharedInfo passed
134 * as optional context attribute CSSM_ATTRIBUTE_SALT.
135 */
136 extern void DeriveKey_ECDH (
137 const Context &context,
138 CSSM_ALGORITHMS algId,
139 const CssmData &Param,
140 CSSM_DATA *keyData,
141 AppleCSPSession &session);
142
143 } /* namespace CryptKit */
144
145 #endif /* _FEE_ASYMMETRIC_CONTEXT_H_ */
146 #endif /* CRYPTKIT_CSP_ENABLE */