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