]> git.saurik.com Git - apple/security.git/blob - AppleCSP/open_ssl/opensslUtils/opensslAsn1.h
Security-164.1.tar.gz
[apple/security.git] / AppleCSP / open_ssl / opensslUtils / opensslAsn1.h
1 /*
2 * Copyright (c) 2003 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 * 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.h>
28 #include <openssl/dsa.h>
29 #include <openssl/dh.h>
30 #include <opensslUtils/osKeyTemplates.h>
31 #include <Security/cssmtype.h>
32 #include <Security/cssmdata.h>
33 #include <SecurityNssAsn1/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 CssmOwnedData &encodedKey);
71 CSSM_RETURN RSAPrivateKeyDecode(
72 RSA *openKey,
73 CSSM_KEYBLOB_FORMAT format,
74 void *p,
75 size_t length);
76 CSSM_RETURN RSAPrivateKeyEncode(
77 RSA *openKey,
78 CSSM_KEYBLOB_FORMAT format,
79 CssmOwnedData &encodedKey);
80 CSSM_RETURN generateDigestInfo(
81 const void *messageDigest,
82 size_t digestLen,
83 CSSM_ALGORITHMS digestAlg, // CSSM_ALGID_SHA1, etc.
84 CssmOwnedData &encodedInfo,
85 size_t maxEncodedSize);
86 CSSM_RETURN DSAPublicKeyDecode(
87 DSA *openKey,
88 CSSM_KEYBLOB_FORMAT format,
89 void *p,
90 size_t length);
91 CSSM_RETURN DSAPublicKeyEncode(
92 DSA *openKey,
93 CSSM_KEYBLOB_FORMAT format,
94 CssmOwnedData &encodedKey);
95 CSSM_RETURN DSAPrivateKeyDecode(
96 DSA *openKey,
97 CSSM_KEYBLOB_FORMAT format,
98 void *p,
99 size_t length);
100 CSSM_RETURN DSAPrivateKeyEncode(
101 DSA *openKey,
102 CSSM_KEYBLOB_FORMAT format,
103 CssmOwnedData &encodedKey);
104
105 CSSM_RETURN DSASigEncode(
106 DSA_SIG *openSig,
107 CssmOwnedData &encodedSig);
108 CSSM_RETURN DSASigDecode(
109 DSA_SIG *openSig,
110 const void *p,
111 unsigned length);
112
113 CSSM_RETURN DSAEncodeAlgParams(
114 NSS_DSAAlgParams &algParams,
115 CssmOwnedData &encodedParams);
116 CSSM_RETURN DSADecodeAlgParams(
117 NSS_DSAAlgParams &algParams,
118 const void *p,
119 unsigned len,
120 SecNssCoder &coder);
121
122 CSSM_RETURN DHPrivateKeyDecode(
123 DH *openKey,
124 CSSM_KEYBLOB_FORMAT format,
125 unsigned char *p,
126 unsigned length);
127 CSSM_RETURN DHPrivateKeyEncode(
128 DH *openKey,
129 CSSM_KEYBLOB_FORMAT format,
130 CssmOwnedData &encodedKey);
131 CSSM_RETURN DHPublicKeyDecode(
132 DH *openKey,
133 CSSM_KEYBLOB_FORMAT format,
134 unsigned char *p,
135 unsigned length);
136 CSSM_RETURN DHPublicKeyEncode(
137 DH *openKey,
138 CSSM_KEYBLOB_FORMAT format,
139 CssmOwnedData &encodedKey);
140 CSSM_RETURN DHParamBlockDecode(
141 const CSSM_DATA &encParam,
142 NSS_DHParameterBlock &paramBlock,
143 SecNssCoder &coder);
144
145 CSSM_RETURN generateDigestInfo(
146 const void *msgDigest,
147 size_t digestLen,
148 CSSM_ALGORITHMS digestAlg, // CSSM_ALGID_SHA1, etc.
149 CssmOwnedData &encodedInfo,
150 size_t maxEncodedSize);
151
152 #ifdef __cplusplus
153 }
154 #endif
155
156 #endif /* _OPENSSL_ASN1_H_ */