]> git.saurik.com Git - apple/security.git/blob - libsecurity_apple_csp/lib/FEESignatureObject.h
Security-55163.44.tar.gz
[apple/security.git] / libsecurity_apple_csp / lib / FEESignatureObject.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 * FEESignatureObject.h - FEE-based raw sign/verify classes
21 */
22
23 #ifdef CRYPTKIT_CSP_ENABLE
24
25 #ifndef _FEE_SIGNATURE_OBJECT_H_
26 #define _FEE_SIGNATURE_OBJECT_H_
27
28 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
29 #include <security_cryptkit/feePublicKey.h>
30 #include <security_cryptkit/feeECDSA.h>
31 #include "FEECSPUtils.h"
32 #include "CryptKitSpace.h"
33 #include <RawSigner.h>
34 #include <AppleCSPSession.h>
35
36 namespace CryptKit {
37
38 /*
39 * Common raw FEE sign/verify class.
40 */
41 class FEESigner : public RawSigner {
42 public:
43 FEESigner(
44 feeRandFcn randFcn,
45 void *randRef,
46 AppleCSPSession &session,
47 Allocator &alloc) :
48 RawSigner(alloc, CSSM_ALGID_NONE),
49 mFeeKey(NULL),
50 mWeMallocdFeeKey(false),
51 mRandFcn(randFcn),
52 mRandRef(randRef),
53 mSession(session) { }
54
55 virtual ~FEESigner();
56
57 /* reusable init */
58 void signerInit(
59 const Context &context,
60 bool isSigning);
61
62 /*
63 * obtain key from context, validate, convert to native FEE key
64 */
65 void keyFromContext(
66 const Context &context);
67
68 protected:
69 feePubKey mFeeKey;
70 bool mWeMallocdFeeKey;
71 feeRandFcn mRandFcn;
72 void *mRandRef;
73 AppleCSPSession &mSession;
74 };
75
76 /*
77 * And two implementations.
78 *
79 * Native FEE signature, ElGamal style.
80 */
81 class FEERawSigner : public FEESigner
82 {
83 public:
84 FEERawSigner(
85 feeRandFcn randFcn,
86 void *randRef,
87 AppleCSPSession &session,
88 Allocator &alloc) :
89 FEESigner(randFcn, randRef, session, alloc) { };
90
91 ~FEERawSigner() { }
92
93 /* sign */
94 void sign(
95 const void *data,
96 size_t dataLen,
97 void *sig,
98 size_t *sigLen); /* IN/OUT */
99
100 /* verify */
101 void verify(
102 const void *data,
103 size_t dataLen,
104 const void *sig,
105 size_t sigLen);
106
107 /* works for both, but only used for signing */
108 size_t maxSigSize();
109 };
110
111 /*
112 * FEE signature, ECDSA style.
113 */
114 class FEEECDSASigner : public FEESigner
115 {
116 public:
117 FEEECDSASigner(
118 feeRandFcn randFcn,
119 void *randRef,
120 AppleCSPSession &session,
121 Allocator &alloc) :
122 FEESigner(randFcn, randRef, session, alloc) { };
123
124 ~FEEECDSASigner() { }
125
126 /* sign */
127 void sign(
128 const void *data,
129 size_t dataLen,
130 void *sig,
131 size_t *sigLen); /* IN/OUT */
132
133 /* verify */
134 void verify(
135 const void *data,
136 size_t dataLen,
137 const void *sig,
138 size_t sigLen);
139
140 /* works for both, but only used for signing */
141 size_t maxSigSize();
142 };
143
144 } /* namespace CryptKit */
145
146 #endif /* _FEE_SIGNATURE_OBJECT_H_ */
147 #endif /* CRYPTKIT_CSP_ENABLE */