]> git.saurik.com Git - apple/security.git/blob - AppleCSP/RSA_DSA/RSA_DSA_signature.h
Security-30.1.tar.gz
[apple/security.git] / AppleCSP / RSA_DSA / RSA_DSA_signature.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 * RSA_DSA_signature.h - openssl-based signature classes.
21 */
22
23 #ifndef _RSA_DSA_SIGNATURE_H_
24 #define _RSA_DSA_SIGNATURE_H_
25
26 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
27 #include <openssl/rsa.h>
28 #include <openssl/dsa.h>
29 #include <AppleCSP/RawSigner.h>
30 #include <AppleCSP/AppleCSPSession.h>
31
32 class RSASigner : public RawSigner {
33 public:
34 RSASigner(
35 CssmAllocator &alloc,
36 AppleCSPSession &session,
37 CSSM_ALGORITHMS digestAlg) :
38 RawSigner(alloc, digestAlg),
39 mRsaKey(NULL),
40 mWeMallocdRsaKey(false),
41 mSession(session) { }
42
43 ~RSASigner();
44
45 /* reusable init */
46 void signerInit(
47 const Context &context,
48 bool isSigning);
49
50
51 /* sign */
52 void sign(
53 const void *data,
54 size_t dataLen,
55 void *sig,
56 size_t *sigLen); /* IN/OUT */
57
58 /* verify */
59 void verify(
60 const void *data,
61 size_t dataLen,
62 const void *sig,
63 size_t sigLen);
64
65 /* works for both, but only used for signing */
66 size_t maxSigSize();
67
68 private:
69
70 /*
71 * obtain key from context, validate, convert to RSA key
72 */
73 void keyFromContext(
74 const Context &context);
75
76 RSA *mRsaKey;
77 bool mWeMallocdRsaKey;
78 AppleCSPSession &mSession;
79 };
80
81 class DSASigner : public RawSigner {
82 public:
83 DSASigner(
84 CssmAllocator &alloc,
85 AppleCSPSession &session,
86 CSSM_ALGORITHMS digestAlg) :
87 RawSigner(alloc, digestAlg),
88 mDsaKey(NULL),
89 mWeMallocdDsaKey(false),
90 mSession(session) { }
91
92 ~DSASigner();
93
94 /* reusable init */
95 void signerInit(
96 const Context &context,
97 bool isSigning);
98
99
100 /* sign */
101 void sign(
102 const void *data,
103 size_t dataLen,
104 void *sig,
105 size_t *sigLen); /* IN/OUT */
106
107 /* verify */
108 void verify(
109 const void *data,
110 size_t dataLen,
111 const void *sig,
112 size_t sigLen);
113
114 /* works for both, but only used for signing */
115 size_t maxSigSize();
116
117 private:
118
119 /*
120 * obtain key from context, validate, convert to DSA key
121 */
122 void keyFromContext(
123 const Context &context);
124
125 DSA *mDsaKey;
126 bool mWeMallocdDsaKey;
127 AppleCSPSession &mSession;
128 };
129
130
131 #endif /* _RSA_DSA_SIGNATURE_H_ */