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