]> git.saurik.com Git - apple/security.git/blob - AppleCSP/RSA_DSA/RSA_DSA_utils.h
Security-30.1.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 void throwRsaDsa(
35 const char *op);
36
37 /*
38 * given an openssl-style error, throw appropriate CssmError.
39 */
40 void throwOpensslErr(
41 int irtn);
42
43 /*
44 * Given a Context:
45 * -- obtain CSSM key (there must only be one)
46 * -- validate keyClass
47 * -- validate keyUsage
48 * -- convert to RSA *, allocating the RSA key if necessary
49 */
50 RSA *contextToRsaKey(
51 const Context &context,
52 AppleCSPSession &session,
53 CSSM_KEYCLASS keyClass, // CSSM_KEYCLASS_{PUBLIC,PRIVATE}_KEY
54 CSSM_KEYUSE usage, // CSSM_KEYUSE_ENCRYPT, CSSM_KEYUSE_SIGN, etc.
55 bool &mallocdKey); // RETURNED
56
57 /*
58 * Convert a CssmKey to an RSA * key. May result in the creation of a new
59 * RSA (when cssmKey is a raw key); allocdKey is true in that case
60 * in which case the caller generally has to free the allocd key).
61 */
62 RSA *cssmKeyToRsa(
63 const CssmKey &cssmKey,
64 AppleCSPSession &session,
65 bool &allocdKey); // RETURNED
66
67 /*
68 * Convert a raw CssmKey to a newly alloc'd RSA *.
69 */
70 RSA *rawCssmKeyToRsa(
71 const CssmKey &cssmKey);
72
73 /*
74 * Given a Context:
75 * -- obtain CSSM key (there must only be one)
76 * -- validate keyClass
77 * -- validate keyUsage
78 * -- convert to DSA *, allocating the DSA key if necessary
79 */
80 DSA *contextToDsaKey(
81 const Context &context,
82 AppleCSPSession &session,
83 CSSM_KEYCLASS keyClass, // CSSM_KEYCLASS_{PUBLIC,PRIVATE}_KEY
84 CSSM_KEYUSE usage, // CSSM_KEYUSE_ENCRYPT, CSSM_KEYUSE_SIGN, etc.
85 bool &mallocdKey); // RETURNED
86
87 /*
88 * Convert a CssmKey to an DSA * key. May result in the creation of a new
89 * DSA (when cssmKey is a raw key); allocdKey is true in that case
90 * in which case the caller generally has to free the allocd key).
91 */
92 DSA *cssmKeyToDsa(
93 const CssmKey &cssmKey,
94 AppleCSPSession &session,
95 bool &allocdKey); // RETURNED
96
97 /*
98 * Convert a raw CssmKey to a newly alloc'd DSA *.
99 */
100 DSA *rawCssmKeyToDsa(
101 const CssmKey &cssmKey);
102
103 #ifdef __cplusplus
104 }
105 #endif
106
107 #endif /*_RSA_DSA_UTILS_H_ */