2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
20 // SSContext.h - Security Server contexts
25 #include <Security/CSPsession.h>
26 #include <Security/SecurityServerClient.h>
27 #include <Security/digestobject.h>
28 #include <Security/utilities.h>
31 // Parent class for all CSPContexts implemented in this CSP. Currently the
32 // only thing we add is a reference to our creator's session.
37 class SSContext
: public CSPFullPluginSession::CSPContext
40 SSContext(SSCSPSession
&session
);
41 ~SSContext() { clearOutBuf(); }
42 virtual void init(const Context
&context
, bool encoding
);
45 SecurityServer::ClientSession
&clientSession();
46 SSCSPSession
&mSession
;
48 // mOutBuf provides a holding tank for implied final() operations
49 // resulting from an outputSize(true, 0). This form of outputSize()
50 // is understood to only occur just prior to the final() call. To avoid
51 // an extra RPC (just to perform the outputSize(), most subclasses of
52 // SSContext actually perform the final() operation at this time,
53 // storing the result in mOutBuf. At final(), mOutBuf() is just copied
54 // to the caller's supplied output buffer.
57 // We remember a pointer to the passed in context and assume it will
58 // remain a valid from init(), update() all the way though the call to
60 const Context
*mContext
;
63 void copyOutBuf(CssmData
&out
);
66 // context for signature (sign and verify)
67 class SSSignatureContext
: public SSContext
70 SSSignatureContext(SSCSPSession
&session
);
71 ~SSSignatureContext();
72 virtual void init(const Context
&context
, bool signing
);
73 virtual void update(const CssmData
&data
);
74 virtual size_t outputSize(bool final
, size_t inSize
);
77 void sign(CssmData
&sig
);
78 virtual void final(CssmData
&out
);
81 virtual void final(const CssmData
&in
);
83 /* for raw sign/verify - optionally called after init */
84 virtual void setDigestAlgorithm(CSSM_ALGORITHMS digestAlg
);
87 /* stash the context's key for final sign/verify */
88 SecurityServer::KeyHandle mKeyHandle
;
90 /* alg-dependent, calculated at init time */
91 CSSM_ALGORITHMS mSigAlg
; // raw signature alg
92 CSSM_ALGORITHMS mDigestAlg
; // digest
93 CSSM_ALGORITHMS mOrigAlg
; // caller's context alg
95 /* exactly one of these is used to collect updates */
96 NullDigest
*mNullDigest
;
97 CssmClient::Digest
*mDigest
;
100 // Context for GenerateRandom operations
101 class SSRandomContext
: public SSContext
104 SSRandomContext(SSCSPSession
&session
);
105 virtual void init(const Context
&context
, bool);
106 virtual size_t outputSize(bool final
, size_t inSize
);
107 virtual void final(CssmData
&out
);
110 uint32 mOutSize
; // spec'd in context at init() time
113 // Context for Encrypt and Decrypt operations
114 class SSCryptContext
: public SSContext
117 SSCryptContext(SSCSPSession
&session
);
119 virtual void init(const Context
&context
, bool encoding
);
120 virtual size_t inputSize(size_t outSize
);
121 virtual size_t outputSize(bool final
, size_t inSize
);
122 virtual void minimumProgress(size_t &in
, size_t &out
);
123 virtual void update(void *inp
, size_t &inSize
, void *outp
,
125 virtual void final(CssmData
&out
);
128 SecurityServer::KeyHandle mKeyHandle
;
129 NullDigest mNullDigest
; // accumulator
132 // Digest, using raw CSP
133 class SSDigestContext
: public SSContext
136 SSDigestContext(SSCSPSession
&session
);
138 virtual void init(const Context
&context
, bool);
139 virtual void update(const CssmData
&data
);
140 virtual void final(CssmData
&out
);
141 virtual size_t outputSize(bool final
, size_t inSize
);
144 CssmClient::Digest
*mDigest
;
147 // common class for MAC generate, verify
148 class SSMACContext
: public SSContext
151 SSMACContext(SSCSPSession
&session
);
152 virtual void init(const Context
&context
, bool);
153 virtual void update(const CssmData
&data
);
154 virtual size_t outputSize(bool final
, size_t inSize
);
157 void genMac(CssmData
&mac
);
158 virtual void final(CssmData
&out
);
160 virtual void final(const CssmData
&in
);
163 SecurityServer::KeyHandle mKeyHandle
;
164 NullDigest mNullDigest
; // accumulator
168 #endif // _H_SS_CONTEXT