]> git.saurik.com Git - apple/security.git/blame - AppleCSP/RSA_DSA/RSA_DSA_utils.h
Security-163.tar.gz
[apple/security.git] / AppleCSP / RSA_DSA / RSA_DSA_utils.h
CommitLineData
bac41a7b
A
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
31extern "C" {
32#endif
33
bac41a7b
A
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 */
41RSA *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 */
53RSA *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 */
61RSA *rawCssmKeyToRsa(
62 const CssmKey &cssmKey);
63
df0e469f
A
64/*
65 * Given a partially formed DSA public key (with no p, q, or g) and a
66 * CssmKey representing a supposedly fully-formed DSA key, populate
67 * the public key's p, g, and q with values from the fully formed key.
68 */
69CSSM_RETURN dsaGetParamsFromKey(
70 DSA *partialKey,
71 const CssmKey &paramKey,
72 AppleCSPSession &session);
73
bac41a7b
A
74/*
75 * Given a Context:
76 * -- obtain CSSM key (there must only be one)
77 * -- validate keyClass
78 * -- validate keyUsage
79 * -- convert to DSA *, allocating the DSA key if necessary
80 */
81DSA *contextToDsaKey(
82 const Context &context,
83 AppleCSPSession &session,
84 CSSM_KEYCLASS keyClass, // CSSM_KEYCLASS_{PUBLIC,PRIVATE}_KEY
85 CSSM_KEYUSE usage, // CSSM_KEYUSE_ENCRYPT, CSSM_KEYUSE_SIGN, etc.
86 bool &mallocdKey); // RETURNED
87
88/*
89 * Convert a CssmKey to an DSA * key. May result in the creation of a new
90 * DSA (when cssmKey is a raw key); allocdKey is true in that case
91 * in which case the caller generally has to free the allocd key).
92 */
93DSA *cssmKeyToDsa(
94 const CssmKey &cssmKey,
95 AppleCSPSession &session,
96 bool &allocdKey); // RETURNED
97
98/*
99 * Convert a raw CssmKey to a newly alloc'd DSA *.
100 */
101DSA *rawCssmKeyToDsa(
df0e469f
A
102 const CssmKey &cssmKey,
103 AppleCSPSession &session,
104 const CssmKey *paramKey); // optional
105
106/*
107 * Given a DSA private key, calculate its public component if it
108 * doesn't already exist. Used for calculating the key digest of
109 * an incoming raw private key.
110 */
111void dsaKeyPrivToPub(
112 DSA *dsaKey);
bac41a7b
A
113
114#ifdef __cplusplus
115}
116#endif
117
118#endif /*_RSA_DSA_UTILS_H_ */