]> git.saurik.com Git - apple/security.git/blob - Security/libsecurity_apple_csp/lib/FEESignatureObject.h
Security-57031.40.6.tar.gz
[apple/security.git] / Security / 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 protected:
68 feePubKey mFeeKey;
69 bool mWeMallocdFeeKey;
70 feeRandFcn mRandFcn;
71 void *mRandRef;
72 AppleCSPSession &mSession;
73 };
74
75 /*
76 * And two implementations.
77 *
78 * Native FEE signature, ElGamal style.
79 */
80 class FEERawSigner : public FEESigner
81 {
82 public:
83 FEERawSigner(
84 feeRandFcn randFcn,
85 void *randRef,
86 AppleCSPSession &session,
87 Allocator &alloc) :
88 FEESigner(randFcn, randRef, session, alloc) { };
89
90 ~FEERawSigner() { }
91
92 /* sign */
93 void sign(
94 const void *data,
95 size_t dataLen,
96 void *sig,
97 size_t *sigLen); /* IN/OUT */
98
99 /* verify */
100 void verify(
101 const void *data,
102 size_t dataLen,
103 const void *sig,
104 size_t sigLen);
105
106 /* works for both, but only used for signing */
107 size_t maxSigSize();
108 };
109
110 /*
111 * FEE signature, ECDSA style.
112 */
113 class FEEECDSASigner : public FEESigner
114 {
115 public:
116 FEEECDSASigner(
117 feeRandFcn randFcn,
118 void *randRef,
119 AppleCSPSession &session,
120 Allocator &alloc) :
121 FEESigner(randFcn, randRef, session, alloc) { };
122
123 ~FEEECDSASigner() { }
124
125 /* sign */
126 void sign(
127 const void *data,
128 size_t dataLen,
129 void *sig,
130 size_t *sigLen); /* IN/OUT */
131
132 /* verify */
133 void verify(
134 const void *data,
135 size_t dataLen,
136 const void *sig,
137 size_t sigLen);
138
139 /* works for both, but only used for signing */
140 size_t maxSigSize();
141 };
142
143 } /* namespace CryptKit */
144
145 #endif /* _FEE_SIGNATURE_OBJECT_H_ */
146 #endif /* CRYPTKIT_CSP_ENABLE */