]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_apple_csp/open_ssl/opensslUtils/opensslAsn1.h
Security-59754.80.3.tar.gz
[apple/security.git] / OSX / libsecurity_apple_csp / open_ssl / opensslUtils / opensslAsn1.h
1 /*
2 * Copyright (c) 2003,2011,2014 Apple 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 * opensslAsn1.h - ANS1 encode/decode of openssl object, libssnasn1 version
21 */
22
23 #ifndef _OPENSSL_ASN1_H_
24 #define _OPENSSL_ASN1_H_
25
26
27 #include <openssl/rsa_legacy.h>
28 #include <openssl/dsa_legacy.h>
29 #include <openssl/dh_legacy.h>
30 #include <Security/osKeyTemplates.h>
31 #include <Security/cssmtype.h>
32 #include <security_cdsa_utilities/cssmdata.h>
33 #include <security_asn1/SecNssCoder.h>
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /* CSSM_DATA --> BIGNUM */
40 BIGNUM *cssmDataToBn(
41 const CSSM_DATA &cdata);
42
43 /* BIGNUM --> CSSM_DATA, mallocing from a SecNssCoder's PL_ArenaPool */
44 void bnToCssmData(
45 const BIGNUM *bn,
46 CSSM_DATA &cdata,
47 SecNssCoder &coder);
48
49 /* CSSM_DATA --> unsigned int */
50 unsigned cssmDataToInt(
51 const CSSM_DATA &cdata);
52
53 /* unsigned int --> CSSM_DATA, mallocing from an SecNssCoder */
54 void intToCssmData(
55 unsigned num,
56 CSSM_DATA &cdata,
57 SecNssCoder &coder);
58
59 /*
60 * DER encode/decode RSA keys in various formats.
61 */
62 CSSM_RETURN RSAPublicKeyDecode(
63 RSA *openKey,
64 CSSM_KEYBLOB_FORMAT format,
65 void *p,
66 size_t length);
67 CSSM_RETURN RSAPublicKeyEncode(
68 RSA *openKey,
69 CSSM_KEYBLOB_FORMAT format,
70 const CssmData &descData,
71 CssmOwnedData &encodedKey);
72 CSSM_RETURN RSAPrivateKeyDecode(
73 RSA *openKey,
74 CSSM_KEYBLOB_FORMAT format,
75 void *p,
76 size_t length);
77 CSSM_RETURN RSAPrivateKeyEncode(
78 RSA *openKey,
79 CSSM_KEYBLOB_FORMAT format,
80 const CssmData &descData,
81 CssmOwnedData &encodedKey);
82 CSSM_RETURN RSAOAEPPublicKeyDecode(
83 RSA *openKey,
84 void *p,
85 size_t length,
86 /* mallocd and returned label */
87 CSSM_DATA *label);
88 CSSM_RETURN RSAOAEPPublicKeyEncode(
89 RSA *openKey,
90 const CSSM_DATA *label,
91 CssmOwnedData &encodedKey);
92 CSSM_RETURN RSAOAEPPrivateKeyDecode(
93 RSA *openKey,
94 void *p,
95 size_t length,
96 /* mallocd and returned label */
97 CSSM_DATA *label);
98 CSSM_RETURN RSAOAEPPrivateKeyEncode(
99 RSA *openKey,
100 const CSSM_DATA *label,
101 CssmOwnedData &encodedKey);
102
103 CSSM_RETURN generateDigestInfo(
104 const void *messageDigest,
105 size_t digestLen,
106 CSSM_ALGORITHMS digestAlg, // CSSM_ALGID_SHA1, etc.
107 CssmOwnedData &encodedInfo,
108 size_t maxEncodedSize);
109 CSSM_RETURN DSAPublicKeyDecode(
110 DSA *openKey,
111 CSSM_KEYBLOB_FORMAT format,
112 void *p,
113 size_t length);
114 CSSM_RETURN DSAPublicKeyEncode(
115 DSA *openKey,
116 CSSM_KEYBLOB_FORMAT format,
117 const CssmData &descData,
118 CssmOwnedData &encodedKey);
119 CSSM_RETURN DSAPrivateKeyDecode(
120 DSA *openKey,
121 CSSM_KEYBLOB_FORMAT format,
122 void *p,
123 size_t length);
124 CSSM_RETURN DSAPrivateKeyEncode(
125 DSA *openKey,
126 CSSM_KEYBLOB_FORMAT format,
127 const CssmData &descData,
128 CssmOwnedData &encodedKey);
129
130 CSSM_RETURN DSASigEncode(
131 DSA_SIG *openSig,
132 CssmOwnedData &encodedSig);
133 CSSM_RETURN DSASigDecode(
134 DSA_SIG *openSig,
135 const void *p,
136 unsigned length);
137
138 CSSM_RETURN DSAEncodeAlgParams(
139 NSS_DSAAlgParams &algParams,
140 CssmOwnedData &encodedParams);
141 CSSM_RETURN DSADecodeAlgParams(
142 NSS_DSAAlgParams &algParams,
143 const void *p,
144 unsigned len,
145 SecNssCoder &coder);
146
147 CSSM_RETURN DHPrivateKeyDecode(
148 DH *openKey,
149 CSSM_KEYBLOB_FORMAT format,
150 unsigned char *p,
151 unsigned length);
152 CSSM_RETURN DHPrivateKeyEncode(
153 DH *openKey,
154 CSSM_KEYBLOB_FORMAT format,
155 CssmOwnedData &encodedKey);
156 CSSM_RETURN DHPublicKeyDecode(
157 DH *openKey,
158 CSSM_KEYBLOB_FORMAT format,
159 unsigned char *p,
160 unsigned length);
161 CSSM_RETURN DHPublicKeyEncode(
162 DH *openKey,
163 CSSM_KEYBLOB_FORMAT format,
164 CssmOwnedData &encodedKey);
165 CSSM_RETURN DHParamBlockDecode(
166 const CSSM_DATA &encParam,
167 NSS_DHParameterBlock &paramBlock,
168 SecNssCoder &coder);
169
170 CSSM_RETURN generateDigestInfo(
171 const void *msgDigest,
172 size_t digestLen,
173 CSSM_ALGORITHMS digestAlg, // CSSM_ALGID_SHA1, etc.
174 CssmOwnedData &encodedInfo,
175 size_t maxEncodedSize);
176
177 #ifdef __cplusplus
178 }
179 #endif
180
181 #endif /* _OPENSSL_ASN1_H_ */