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