]>
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
);
99 static CSPKeyInfoProvider
*provider(
100 const CssmKey
&cssmKey
);
101 ~RSAKeyInfoProvider() { }
102 void CssmKeyToBinary(
103 BinaryKey
**binKey
); // RETURNED
104 void QueryKeySizeInBits(
105 CSSM_KEY_SIZE
&keySize
); // RETURNED
109 * DSA version of a BinaryKey.
111 class DSABinaryKey
: public BinaryKey
{
113 DSABinaryKey(DSA
*dsaKey
= NULL
);
115 void generateKeyBlob(
116 CssmAllocator
&allocator
,
118 CSSM_KEYBLOB_FORMAT
&format
);
123 class DSAKeyPairGenContext
:
124 public AppleCSPContext
, private AppleKeyPairGenContext
{
126 DSAKeyPairGenContext(
127 AppleCSPSession
&session
,
129 AppleCSPContext(session
), mGenAttrs(NULL
) {}
131 ~DSAKeyPairGenContext() { freeGenAttrs(); }
133 /* no init functionality, but we need to implement it */
138 // this one is specified in, and called from, CSPFullPluginSession
140 const Context
&context
,
144 // this one is specified in, and called from, AppleKeyPairGenContext
146 const Context
&context
,
147 BinaryKey
&pubBinKey
,
148 BinaryKey
&privBinKey
,
151 // specified in, and called from, CSPFullPluginSessionÊ- generate parameters
153 const Context
&context
,
157 Context::Attr
* &attrs
);
160 * Necessary to handle and deflect "context changed" notification which occurs
161 * after the strange return from "generate parameters", when the plugin adds
162 * the "returned" values to the Context.
164 bool changed(const Context
&context
) { return true; }
167 uint32 keySizeInBits
,
168 const void *inSeed
, // optional
170 DSAAlgParams
&algParams
);
173 /* gross hack to store attributes "returned" from GenParams */
174 Context::Attr
*mGenAttrs
;
176 }; /* KeyPairGenContext */
179 * CSPKeyInfoProvider for DSA keys
181 class DSAKeyInfoProvider
: public CSPKeyInfoProvider
185 const CssmKey
&cssmKey
);
187 static CSPKeyInfoProvider
*provider(
188 const CssmKey
&cssmKey
);
189 ~DSAKeyInfoProvider() { }
190 void CssmKeyToBinary(
191 BinaryKey
**binKey
); // RETURNED
192 void QueryKeySizeInBits(
193 CSSM_KEY_SIZE
&keySize
); // RETURNED
196 #endif /* _RSA_DSA_KEYS_H_ */