]> git.saurik.com Git - apple/security.git/blob - AppleCSPDL/SSContext.h
Security-28.tar.gz
[apple/security.git] / AppleCSPDL / SSContext.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 // SSContext.h - Security Server contexts
21 //
22 #ifndef _H_SS_CONTEXT
23 #define _H_SS_CONTEXT
24
25 #include <Security/CSPsession.h>
26 #include <Security/SecurityServerClient.h>
27
28 //
29 // Parent class for all CSPContexts implemented in this CSP. Currently the
30 // only thing we add is a reference to our creator's session.
31 //
32 class SSCSPSession;
33 class SSKey;
34
35 class SSContext : public CSPFullPluginSession::CSPContext
36 {
37 public:
38 SSContext(SSCSPSession &session);
39 virtual void init(const Context &context, bool encoding);
40
41 protected:
42 SecurityServer::ClientSession &clientSession();
43 SSCSPSession &mSession;
44
45 // We remeber a pointer to the passed in context and assume it will
46 // remain a valid from init(), update() all the way though the call to
47 // final().
48 const Context *mContext;
49 };
50
51 // SSSignContext -- Context for Sign, and GenerateMac operations
52 class SSSignContext : public SSContext
53 {
54 public:
55 SSSignContext(SSCSPSession &session);
56 virtual void update(const CssmData &data);
57 virtual size_t outputSize(bool final, size_t inSize);
58 virtual void final(CssmData &out);
59 };
60
61 // SSVerifyContext -- Context for Verify, and VerifyMac operations
62 class SSVerifyContext : public SSContext
63 {
64 public:
65 SSVerifyContext(SSCSPSession &session);
66 virtual void update(const CssmData &data);
67 virtual void final(const CssmData &in);
68 };
69
70 // Context for GenerateRandom operations
71 class SSRandomContext : public SSContext
72 {
73 public:
74 SSRandomContext(SSCSPSession &session);
75 virtual void init(const Context &context, bool);
76 virtual size_t outputSize(bool final, size_t inSize);
77 virtual void final(CssmData &out);
78
79 private:
80 uint32 mOutSize;
81 };
82
83 // Context for Encrypt and Decrypt operations
84 class SSCryptContext : public SSContext
85 {
86 public:
87 SSCryptContext(SSCSPSession &session);
88 ~SSCryptContext();
89 virtual void init(const Context &context, bool encoding);
90 virtual size_t inputSize(size_t outSize);
91 virtual size_t outputSize(bool final, size_t inSize);
92 virtual void minimumProgress(size_t &in, size_t &out);
93 virtual void update(void *inp, size_t &inSize, void *outp,
94 size_t &outSize);
95 virtual void final(CssmData &out);
96
97 private:
98 void freeBuffer();
99
100 SecurityServer::KeyHandle mKeyHandle;
101 uint32 mCurrent;
102 uint32 mCapacity;
103 void *mBuffer;
104 };
105
106 #if 0
107 // Context for key (pair) generation
108 class SSKeyGenContext : public SSContext
109 {
110 public:
111 SSKeyGenContext(SSCSPSession &session);
112
113 // Subclass implements generate(const Context &, CssmKey &,
114 // CssmKey &). That method allocates two subclass-specific
115 // SSKeys and calls this method. This will call down to
116 // generate(const Context &, SSKey &, SSKey &)
117 // and optionally to SSKey::generateKeyBlob.
118 void generate(const Context &context,
119 CssmKey &pubKey,
120 SSKey *pubBinKey,
121 CssmKey &privKey,
122 SSKey *privBinKey);
123
124 protected:
125 // @@@ Subclasses must implement this. It cooks up a key pair.
126 virtual void generate(const Context &context,
127 SSKey &pubBinKey, // valid on successful return
128 SSKey &privBinKey, // ditto
129 uint32 &keySize); // ditto
130
131 public:
132 void generateSymKey(const Context &context, CssmKey &outCssmKey);
133 };
134 #endif // 0
135
136
137 #endif // _H_SS_CONTEXT