2 * Copyright (c) 2003,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 * opensslAsn1.h - ANS1 encode/decode of openssl object, libssnasn1 version
23 #ifndef _OPENSSL_ASN1_H_
24 #define _OPENSSL_ASN1_H_
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>
39 /* CSSM_DATA --> BIGNUM */
41 const CSSM_DATA
&cdata
);
43 /* BIGNUM --> CSSM_DATA, mallocing from a SecNssCoder's PL_ArenaPool */
49 /* CSSM_DATA --> unsigned int */
50 unsigned cssmDataToInt(
51 const CSSM_DATA
&cdata
);
53 /* unsigned int --> CSSM_DATA, mallocing from an SecNssCoder */
60 * DER encode/decode RSA keys in various formats.
62 CSSM_RETURN
RSAPublicKeyDecode(
64 CSSM_KEYBLOB_FORMAT format
,
67 CSSM_RETURN
RSAPublicKeyEncode(
69 CSSM_KEYBLOB_FORMAT format
,
70 const CssmData
&descData
,
71 CssmOwnedData
&encodedKey
);
72 CSSM_RETURN
RSAPrivateKeyDecode(
74 CSSM_KEYBLOB_FORMAT format
,
77 CSSM_RETURN
RSAPrivateKeyEncode(
79 CSSM_KEYBLOB_FORMAT format
,
80 const CssmData
&descData
,
81 CssmOwnedData
&encodedKey
);
82 CSSM_RETURN
RSAOAEPPublicKeyDecode(
86 /* mallocd and returned label */
88 CSSM_RETURN
RSAOAEPPublicKeyEncode(
90 const CSSM_DATA
*label
,
91 CssmOwnedData
&encodedKey
);
92 CSSM_RETURN
RSAOAEPPrivateKeyDecode(
96 /* mallocd and returned label */
98 CSSM_RETURN
RSAOAEPPrivateKeyEncode(
100 const CSSM_DATA
*label
,
101 CssmOwnedData
&encodedKey
);
103 CSSM_RETURN
generateDigestInfo(
104 const void *messageDigest
,
106 CSSM_ALGORITHMS digestAlg
, // CSSM_ALGID_SHA1, etc.
107 CssmOwnedData
&encodedInfo
,
108 size_t maxEncodedSize
);
109 CSSM_RETURN
DSAPublicKeyDecode(
111 CSSM_KEYBLOB_FORMAT format
,
114 CSSM_RETURN
DSAPublicKeyEncode(
116 CSSM_KEYBLOB_FORMAT format
,
117 const CssmData
&descData
,
118 CssmOwnedData
&encodedKey
);
119 CSSM_RETURN
DSAPrivateKeyDecode(
121 CSSM_KEYBLOB_FORMAT format
,
124 CSSM_RETURN
DSAPrivateKeyEncode(
126 CSSM_KEYBLOB_FORMAT format
,
127 const CssmData
&descData
,
128 CssmOwnedData
&encodedKey
);
130 CSSM_RETURN
DSASigEncode(
132 CssmOwnedData
&encodedSig
);
133 CSSM_RETURN
DSASigDecode(
138 CSSM_RETURN
DSAEncodeAlgParams(
139 NSS_DSAAlgParams
&algParams
,
140 CssmOwnedData
&encodedParams
);
141 CSSM_RETURN
DSADecodeAlgParams(
142 NSS_DSAAlgParams
&algParams
,
147 CSSM_RETURN
DHPrivateKeyDecode(
149 CSSM_KEYBLOB_FORMAT format
,
152 CSSM_RETURN
DHPrivateKeyEncode(
154 CSSM_KEYBLOB_FORMAT format
,
155 CssmOwnedData
&encodedKey
);
156 CSSM_RETURN
DHPublicKeyDecode(
158 CSSM_KEYBLOB_FORMAT format
,
161 CSSM_RETURN
DHPublicKeyEncode(
163 CSSM_KEYBLOB_FORMAT format
,
164 CssmOwnedData
&encodedKey
);
165 CSSM_RETURN
DHParamBlockDecode(
166 const CSSM_DATA
&encParam
,
167 NSS_DHParameterBlock
¶mBlock
,
170 CSSM_RETURN
generateDigestInfo(
171 const void *msgDigest
,
173 CSSM_ALGORITHMS digestAlg
, // CSSM_ALGID_SHA1, etc.
174 CssmOwnedData
&encodedInfo
,
175 size_t maxEncodedSize
);
181 #endif /* _OPENSSL_ASN1_H_ */