]>
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 <openssl/rsa.h>
30 #include <openssl/dsa.h>
31 #include <Security/context.h>
32 #include <opensslUtils/openRsaSnacc.h>
33 #include <Security/appleoids.h>
35 #define RSA_PUB_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_PKCS1
36 #define RSA_PRIV_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_PKCS8
38 #define DSA_PUB_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_FIPS186
39 #define DSA_PRIV_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_FIPS186
41 #define DSA_MIN_KEY_SIZE 512
42 #define DSA_MAX_KEY_SIZE 1024
43 #define DSA_KEY_BITS_MASK (64 - 1) /* these bits must be zero */
44 /* i.e., aligned to 64 bits */
46 * RSA version of a BinaryKey.
48 class RSABinaryKey
: public BinaryKey
{
50 RSABinaryKey(RSA
*rsaKey
= NULL
);
53 CssmAllocator
&allocator
,
55 CSSM_KEYBLOB_FORMAT
&format
);
60 class RSAKeyPairGenContext
:
61 public AppleCSPContext
, private AppleKeyPairGenContext
{
64 AppleCSPSession
&session
,
66 AppleCSPContext(session
) {}
68 ~RSAKeyPairGenContext() { }
70 /* no init functionality, but we need to implement it */
75 // this one is specified in, and called from, CSPFullPluginSession
77 const Context
&context
,
81 // this one is specified in, and called from, AppleKeyPairGenContext
83 const Context
&context
,
85 BinaryKey
&privBinKey
,
88 }; /* KeyPairGenContext */
91 * CSPKeyInfoProvider for RSA keys
93 class RSAKeyInfoProvider
: public CSPKeyInfoProvider
97 const CssmKey
&cssmKey
);
98 ~RSAKeyInfoProvider() { }
100 BinaryKey
**binKey
); // RETURNED
101 void QueryKeySizeInBits(
102 CSSM_KEY_SIZE
&keySize
); // RETURNED
106 * DSA version of a BinaryKey.
108 class DSABinaryKey
: public BinaryKey
{
110 DSABinaryKey(DSA
*dsaKey
= NULL
);
112 void generateKeyBlob(
113 CssmAllocator
&allocator
,
115 CSSM_KEYBLOB_FORMAT
&format
);
120 class DSAKeyPairGenContext
:
121 public AppleCSPContext
, private AppleKeyPairGenContext
{
123 DSAKeyPairGenContext(
124 AppleCSPSession
&session
,
126 AppleCSPContext(session
), mGenAttrs(NULL
) {}
128 ~DSAKeyPairGenContext() { freeGenAttrs(); }
130 /* no init functionality, but we need to implement it */
135 // this one is specified in, and called from, CSPFullPluginSession
137 const Context
&context
,
141 // this one is specified in, and called from, AppleKeyPairGenContext
143 const Context
&context
,
144 BinaryKey
&pubBinKey
,
145 BinaryKey
&privBinKey
,
148 // specified in, and called from, CSPFullPluginSessionÊ- generate parameters
150 const Context
&context
,
154 Context::Attr
* &attrs
);
157 * Necessary to handle and deflect "context changed" notification which occurs
158 * after the strange return from "generate parameters", when the plugin adds
159 * the "returned" values to the Context.
161 bool changed(const Context
&context
) { return true; }
164 uint32 keySizeInBits
,
165 const void *inSeed
, // optional
167 DSAAlgParams
&algParams
);
170 /* gross hack to store attributes "returned" from GenParams */
171 Context::Attr
*mGenAttrs
;
173 }; /* KeyPairGenContext */
176 * CSPKeyInfoProvider for DSA keys
178 class DSAKeyInfoProvider
: public CSPKeyInfoProvider
182 const CssmKey
&cssmKey
);
183 ~DSAKeyInfoProvider() { }
184 void CssmKeyToBinary(
185 BinaryKey
**binKey
); // RETURNED
186 void QueryKeySizeInBits(
187 CSSM_KEY_SIZE
&keySize
); // RETURNED
190 #endif /* _RSA_DSA_KEYS_H_ */