]> git.saurik.com Git - apple/security.git/blob - AppleCSP/RSA_DSA/RSA_DSA_utils.h
Security-54.1.9.tar.gz
[apple/security.git] / AppleCSP / RSA_DSA / RSA_DSA_utils.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19 /*
20 * RSA_DSA_utils.h
21 */
22 #ifndef _RSA_DSA_UTILS_H_
23 #define _RSA_DSA_UTILS_H_
24
25 #include <openssl/rsa.h>
26 #include <openssl/dsa.h>
27 #include <AppleCSP/AppleCSPSession.h>
28 #include <Security/context.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /*
35 * Given a Context:
36 * -- obtain CSSM key (there must only be one)
37 * -- validate keyClass
38 * -- validate keyUsage
39 * -- convert to RSA *, allocating the RSA key if necessary
40 */
41 RSA *contextToRsaKey(
42 const Context &context,
43 AppleCSPSession &session,
44 CSSM_KEYCLASS keyClass, // CSSM_KEYCLASS_{PUBLIC,PRIVATE}_KEY
45 CSSM_KEYUSE usage, // CSSM_KEYUSE_ENCRYPT, CSSM_KEYUSE_SIGN, etc.
46 bool &mallocdKey); // RETURNED
47
48 /*
49 * Convert a CssmKey to an RSA * key. May result in the creation of a new
50 * RSA (when cssmKey is a raw key); allocdKey is true in that case
51 * in which case the caller generally has to free the allocd key).
52 */
53 RSA *cssmKeyToRsa(
54 const CssmKey &cssmKey,
55 AppleCSPSession &session,
56 bool &allocdKey); // RETURNED
57
58 /*
59 * Convert a raw CssmKey to a newly alloc'd RSA *.
60 */
61 RSA *rawCssmKeyToRsa(
62 const CssmKey &cssmKey);
63
64 /*
65 * Given a Context:
66 * -- obtain CSSM key (there must only be one)
67 * -- validate keyClass
68 * -- validate keyUsage
69 * -- convert to DSA *, allocating the DSA key if necessary
70 */
71 DSA *contextToDsaKey(
72 const Context &context,
73 AppleCSPSession &session,
74 CSSM_KEYCLASS keyClass, // CSSM_KEYCLASS_{PUBLIC,PRIVATE}_KEY
75 CSSM_KEYUSE usage, // CSSM_KEYUSE_ENCRYPT, CSSM_KEYUSE_SIGN, etc.
76 bool &mallocdKey); // RETURNED
77
78 /*
79 * Convert a CssmKey to an DSA * key. May result in the creation of a new
80 * DSA (when cssmKey is a raw key); allocdKey is true in that case
81 * in which case the caller generally has to free the allocd key).
82 */
83 DSA *cssmKeyToDsa(
84 const CssmKey &cssmKey,
85 AppleCSPSession &session,
86 bool &allocdKey); // RETURNED
87
88 /*
89 * Convert a raw CssmKey to a newly alloc'd DSA *.
90 */
91 DSA *rawCssmKeyToDsa(
92 const CssmKey &cssmKey);
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 #endif /*_RSA_DSA_UTILS_H_ */