1/* 2 * Copyright (c) 2000-2001,2011,2013-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 * RawSigner.h - low-level virtual sign/verify object (no digest) 21 */ 22 23#ifndef _RAW_SIGNER_H_ 24#define _RAW_SIGNER_H_ 25 26#include <security_cdsa_utilities/context.h> 27#include <security_utilities/alloc.h> 28 29class RawSigner { 30public: 31 RawSigner( 32 Allocator &alloc, 33 CSSM_ALGORITHMS digestAlg) : 34 mInitFlag(false), 35 mIsSigning(false), 36 mDigestAlg(digestAlg), 37 mAlloc(alloc) { } 38 virtual ~RawSigner() { } 39 40 /* 41 * The use of our mDigestAlg variable is pretty crufty. For some algs, it's 42 * known and specified at construction time (e.g., CSSM_ALGID_MD5WithRSA). 43 * For some algs, it's set by CSPFullPluginSession via 44 * CSPContext::setDigestAlgorithm during raw sign/verify. 45 */ 46 void setDigestAlg(CSSM_ALGORITHMS alg) 47 { mDigestAlg = alg; } 48 49 /* 50 * The remaining functions must be implemented by subclass. 51 */ 52 53 /* reusable init */ 54 virtual void signerInit( 55 const Context &context, 56 bool isSigning) = 0; 57 58 /* sign */ 59 virtual void sign( 60 const void *data, 61 size_t dataLen, 62 void *sig, 63 size_t *sigLen) = 0; /* IN/OUT */ 64 65 /* verify */ 66 virtual void verify( 67 const void *data, 68 size_t dataLen, 69 const void *sig, 70 size_t sigLen) = 0; 71 72 /* works for both, but only used for signing */ 73 virtual size_t maxSigSize() = 0; 74 75protected: 76 bool mInitFlag; // true after init 77 bool mOpStarted; // true after update 78 bool mIsSigning; 79 CSSM_ALGORITHMS mDigestAlg; // for raw sign/verify 80 Allocator &mAlloc; 81 82 bool initFlag() { return mInitFlag; } 83 void setInitFlag(bool flag) { mInitFlag = flag; } 84 bool opStarted() { return mOpStarted; } 85 void setOpStarted(bool flag) { mOpStarted = flag; } 86 bool isSigning() { return mIsSigning; } 87 void setIsSigning(bool signing) 88 { mIsSigning = signing; } 89 CSSM_ALGORITHMS digestAlg() { return mDigestAlg; } 90 Allocator &alloc() { return mAlloc; } 91}; 92 93 94#endif /* _RAW_SIGNER_H_ */ 95