]>
git.saurik.com Git - apple/security.git/blob - AppleCSP/RSA_DSA/RSA_DSA_keys.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
20 * RSA_DSA_keys.h - key pair support for RSA/DSA
23 #ifndef _RSA_DSA_KEYS_H_
24 #define _RSA_DSA_KEYS_H_
26 #include <AppleCSP/AppleCSPContext.h>
27 #include <AppleCSP/AppleCSPSession.h>
28 #include <RSA_DSA/RSA_DSA_csp.h>
29 #include "AppleCSPKeys.h"
30 #include <opensslUtils/osKeyTemplates.h>
31 #include <openssl/rsa.h>
32 #include <openssl/dsa.h>
33 #include <Security/context.h>
34 #include <SecurityNssAsn1/SecNssCoder.h>
36 #define RSA_PUB_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_PKCS1
37 #define RSA_PRIV_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_PKCS8
39 #define DSA_PUB_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_X509
40 #define DSA_PRIV_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_FIPS186
42 #define DSA_MIN_KEY_SIZE 512
43 #define DSA_MAX_KEY_SIZE 1024
44 #define DSA_KEY_BITS_MASK (64 - 1) /* these bits must be zero */
45 /* i.e., aligned to 64 bits */
47 * RSA version of a BinaryKey.
49 class RSABinaryKey
: public BinaryKey
{
51 RSABinaryKey(RSA
*rsaKey
= NULL
);
54 CssmAllocator
&allocator
,
56 CSSM_KEYBLOB_FORMAT
&format
,
57 AppleCSPSession
&session
,
58 const CssmKey
*paramKey
, /* optional, unused here */
59 CSSM_KEYATTR_FLAGS
&attrFlags
); /* IN/OUT */
64 class RSAKeyPairGenContext
:
65 public AppleCSPContext
, private AppleKeyPairGenContext
{
68 AppleCSPSession
&session
,
70 AppleCSPContext(session
) {}
72 ~RSAKeyPairGenContext() { }
74 /* no init functionality, but we need to implement it */
79 // this one is specified in, and called from, CSPFullPluginSession
81 const Context
&context
,
85 // this one is specified in, and called from, AppleKeyPairGenContext
87 const Context
&context
,
89 BinaryKey
&privBinKey
,
92 }; /* KeyPairGenContext */
95 * CSPKeyInfoProvider for RSA keys
97 class RSAKeyInfoProvider
: public CSPKeyInfoProvider
101 const CssmKey
&cssmKey
,
102 AppleCSPSession
&session
);
104 static CSPKeyInfoProvider
*provider(
105 const CssmKey
&cssmKey
,
106 AppleCSPSession
&session
);
108 ~RSAKeyInfoProvider() { }
109 void CssmKeyToBinary(
110 CssmKey
*paramKey
, // optional
111 CSSM_KEYATTR_FLAGS
&attrFlags
, // IN/OUT
112 BinaryKey
**binKey
); // RETURNED
113 void QueryKeySizeInBits(
114 CSSM_KEY_SIZE
&keySize
); // RETURNED
115 bool getHashableBlob(
116 CssmAllocator
&allocator
,
121 * DSA version of a BinaryKey.
123 class DSABinaryKey
: public BinaryKey
{
125 DSABinaryKey(DSA
*dsaKey
= NULL
);
127 void generateKeyBlob(
128 CssmAllocator
&allocator
,
130 CSSM_KEYBLOB_FORMAT
&format
,
131 AppleCSPSession
&session
,
132 const CssmKey
*paramKey
, /* optional */
133 CSSM_KEYATTR_FLAGS
&attrFlags
); /* IN/OUT */
138 class DSAKeyPairGenContext
:
139 public AppleCSPContext
, private AppleKeyPairGenContext
{
141 DSAKeyPairGenContext(
142 AppleCSPSession
&session
,
144 AppleCSPContext(session
), mGenAttrs(NULL
) {}
146 ~DSAKeyPairGenContext() { freeGenAttrs(); }
148 /* no init functionality, but we need to implement it */
153 // this one is specified in, and called from, CSPFullPluginSession
155 const Context
&context
,
159 // this one is specified in, and called from, AppleKeyPairGenContext
161 const Context
&context
,
162 BinaryKey
&pubBinKey
,
163 BinaryKey
&privBinKey
,
166 // specified in, and called from, CSPFullPluginSessionÊ- generate parameters
168 const Context
&context
,
172 Context::Attr
* &attrs
);
175 * Necessary to handle and deflect "context changed" notification which occurs
176 * after the strange return from "generate parameters", when the plugin adds
177 * the "returned" values to the Context.
179 bool changed(const Context
&context
) { return true; }
182 uint32 keySizeInBits
,
183 const void *inSeed
, // optional
185 NSS_DSAAlgParams
&algParams
,
189 /* gross hack to store attributes "returned" from GenParams */
190 Context::Attr
*mGenAttrs
;
192 }; /* KeyPairGenContext */
195 * CSPKeyInfoProvider for DSA keys
197 class DSAKeyInfoProvider
: public CSPKeyInfoProvider
201 const CssmKey
&cssmKey
,
202 AppleCSPSession
&session
);
204 static CSPKeyInfoProvider
*provider(
205 const CssmKey
&cssmKey
,
206 AppleCSPSession
&session
);
208 ~DSAKeyInfoProvider() { }
209 void CssmKeyToBinary(
210 CssmKey
*paramKey
, // optional
211 CSSM_KEYATTR_FLAGS
&attrFlags
, // IN/OUT
212 BinaryKey
**binKey
); // RETURNED
213 void QueryKeySizeInBits(
214 CSSM_KEY_SIZE
&keySize
); // RETURNED
215 bool getHashableBlob(
216 CssmAllocator
&allocator
,
220 #endif /* _RSA_DSA_KEYS_H_ */