SignatureContext.h
1 /* 2 * Copyright (c) 2000-2001,2011-2012,2014 Apple 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 * SignatureContext.h - AppleCSPContext subclass for generic sign/verify 21 * 22 * This class performs all of the sign/verify operations in the CSP. The general 23 * scheme is that an instance of this class has references to one DigestObject 24 * and one RawSigner. Sign and Verify "updates" go to the DigestObject. The "final" 25 * operation consists of obtaining the final digest from the DigestObject and 26 * performing a sign or verify on that data via the RawSigner. 27 * 28 * This class knows nothing about any of the algorithms involved; all sign and 29 * verify operations follow this same scheme. Various modules' AlgorithmFactories 30 * construct one of these objects by providing the appropriate DigestObject and 31 * RawSigner. 32 * 33 * The seemingly special case of "raw RSA sign", in which the app calculates the 34 * digest separately from the sign operation, is handled via the NullDigest object. 35 */ 36 37 #ifndef _SIGNATURE_CONTEXT_H_ 38 #define _SIGNATURE_CONTEXT_H_ 39 40 #include <RawSigner.h> 41 #include <security_cdsa_utilities/digestobject.h> 42 #include <AppleCSPContext.h> 43 44 class SignatureContext : public AppleCSPContext { 45 public: 46 SignatureContext( 47 AppleCSPSession &session, 48 DigestObject &digest, 49 RawSigner &signer) : 50 AppleCSPContext(session), 51 mDigest(digest), 52 mSigner(signer), 53 mInitFlag(false) { } 54 55 ~SignatureContext(); 56 57 /* called out from CSPFullPluginSession.... 58 * both sign & verify: */ 59 void init(const Context &context, bool isSigning); 60 void update(const CssmData &data); 61 62 /* sign only */ 63 void final(CssmData &out); 64 65 /* verify only */ 66 void final(const CssmData &in); 67 68 size_t outputSize(bool final, size_t inSize); 69 70 /* for raw sign/verify - optionally called after init */ 71 virtual void setDigestAlgorithm(CSSM_ALGORITHMS digestAlg); 72 73 74 private: 75 DigestObject &mDigest; 76 RawSigner &mSigner; 77 bool mInitFlag; // true after init 78 }; 79 80 81 #endif /* _SIGNATURE_CONTEXT_H_ */