]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_apple_csp/lib/DH_keys.h
2 * Copyright (c) 2000-2002,2011,2014 Apple 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 <AppleCSPContext.h>
27 #include <AppleCSPSession.h>
28 #include "AppleCSPKeys.h"
30 #include <openssl/dh_legacy.h>
31 #include <security_cdsa_utilities/context.h>
32 #include <security_utilities/debugging.h>
33 #include <security_asn1/SecNssCoder.h>
34 #include <Security/osKeyTemplates.h>
36 #define DH_PUB_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_PKCS3
37 #define DH_PRIV_KEY_FORMAT CSSM_KEYBLOB_RAW_FORMAT_PKCS3
39 #define DH_MIN_KEY_SIZE 512 /* FIXME */
40 #define DH_MAX_KEY_SIZE 2048
42 #define cspDhDebug(args...) secinfo("dhDebug", ## args)
45 * Diffie-Hellman version of a BinaryKey.
47 class DHBinaryKey
: public BinaryKey
{
49 DHBinaryKey(DH
*dhKey
= NULL
);
54 CSSM_KEYBLOB_FORMAT
&format
,
55 AppleCSPSession
&session
,
56 const CssmKey
*paramKey
, /* optional, unused here */
57 CSSM_KEYATTR_FLAGS
&attrFlags
); /* IN/OUT */
60 * This may contain a fully-capable private key, or a public
61 * key with as little as the pub_key field set.
66 class DHKeyPairGenContext
:
67 public AppleCSPContext
, private AppleKeyPairGenContext
{
70 AppleCSPSession
&session
,
72 AppleCSPContext(session
),
75 ~DHKeyPairGenContext() { freeGenAttrs(); }
77 // no init functionality, but we need to implement it
82 // this one is specified in, and called from, CSPFullPluginSession
84 const Context
&context
,
88 // this one is specified in, and called from, AppleKeyPairGenContext
90 const Context
&context
,
92 BinaryKey
&privBinKey
,
95 // specified in, and called from, CSPFullPluginSessionÊ- generate parameters
97 const Context
&context
,
101 Context::Attr
* &attrs
);
104 * Necessary to handle and deflect "context changed" notification which occurs
105 * after the strange return from "generate parameters", when the plugin adds
106 * the "returned" values to the Context.
108 bool changed(const Context
&context
) { return true; }
111 uint32 keySizeInBits
,
112 unsigned g
, // probably should be BIGNUM
113 int privValueLength
, // optional
114 NSS_DHParameter
&algParams
,
115 SecNssCoder
&coder
); // for temp contents of algParams
118 /* gross hack to store attributes "returned" from GenParams */
119 Context::Attr
*mGenAttrs
;
121 }; /* DHKeyPairGenContext */
124 * CSPKeyInfoProvider for Diffie-Hellman keys
126 class DHKeyInfoProvider
: public CSPKeyInfoProvider
130 const CssmKey
&cssmKey
,
131 AppleCSPSession
&session
);
133 static CSPKeyInfoProvider
*provider(
134 const CssmKey
&cssmKey
,
135 AppleCSPSession
&session
);
137 ~DHKeyInfoProvider() { }
138 void CssmKeyToBinary(
139 CssmKey
*paramKey
, // optional, ignored here
140 CSSM_KEYATTR_FLAGS
&attrFlags
, // IN/OUT
141 BinaryKey
**binKey
); // RETURNED
142 void QueryKeySizeInBits(
143 CSSM_KEY_SIZE
&keySize
); // RETURNED
144 bool getHashableBlob(
145 Allocator
&allocator
,
149 #endif /* _DH_KEYS_H_ */