]>
git.saurik.com Git - apple/security.git/blob - AppleCSP/DiffieHellman/DH_keys.h
2 * Copyright (c) 2000-2002 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 * DH_keys.h - Diffie-Hellman key pair support
26 #include <AppleCSP/AppleCSPContext.h>
27 #include <AppleCSP/AppleCSPSession.h>
28 #include <DiffieHellman/DH_csp.h>
29 #include <openssl/dh.h>
30 #include <Security/context.h>
31 #include <opensslUtils/openRsaSnacc.h>
32 #include <Security/appleoids.h>
34 #define DH_PUB_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_PKCS3
35 #define DH_PRIV_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_PKCS3
37 #define DH_MIN_KEY_SIZE 512 /* FIXME */
38 #define DH_MAX_KEY_SIZE 2048
41 * Diffie-Hellman version of a BinaryKey.
43 class DHBinaryKey
: public BinaryKey
{
45 DHBinaryKey(DH
*dhKey
= NULL
); // for private key
46 DHBinaryKey(const CSSM_DATA
*pubBlob
); // for public key
49 CssmAllocator
&allocator
,
51 CSSM_KEYBLOB_FORMAT
&format
);
53 void setPubBlob(const CSSM_DATA
*pubBlob
);
54 void setPubBlob(DH
*privKey
);
57 * At most one of these is valid - a DH for a private key,
58 * CSSM_DATA for public.
64 class DHKeyPairGenContext
:
65 public AppleCSPContext
, private AppleKeyPairGenContext
{
68 AppleCSPSession
&session
,
70 AppleCSPContext(session
),
73 ~DHKeyPairGenContext() { freeGenAttrs(); }
75 // no init functionality, but we need to implement it
80 // this one is specified in, and called from, CSPFullPluginSession
82 const Context
&context
,
86 // this one is specified in, and called from, AppleKeyPairGenContext
88 const Context
&context
,
90 BinaryKey
&privBinKey
,
93 // specified in, and called from, CSPFullPluginSessionÊ- generate parameters
95 const Context
&context
,
99 Context::Attr
* &attrs
);
102 * Necessary to handle and deflect "context changed" notification which occurs
103 * after the strange return from "generate parameters", when the plugin adds
104 * the "returned" values to the Context.
106 bool changed(const Context
&context
) { return true; }
109 uint32 keySizeInBits
,
110 unsigned g
, // probably should be BIGNUM
111 int privValueLength
, // optional
112 DHParameter
&algParams
);
115 /* gross hack to store attributes "returned" from GenParams */
116 Context::Attr
*mGenAttrs
;
118 }; /* DHKeyPairGenContext */
121 * CSPKeyInfoProvider for Diffie-Hellman keys
123 class DHKeyInfoProvider
: public CSPKeyInfoProvider
127 const CssmKey
&cssmKey
);
128 ~DHKeyInfoProvider() { }
129 void CssmKeyToBinary(
130 BinaryKey
**binKey
); // RETURNED
131 void QueryKeySizeInBits(
132 CSSM_KEY_SIZE
&keySize
); // RETURNED
135 #endif /* _DH_KEYS_H_ */