]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cryptkit/lib/CryptKitDER.h
2 * Copyright (c) 2001,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 #ifndef _CRYPTKIT_DER_H_
26 #define _CRYPTKIT_DER_H_
28 #include <security_cryptkit/ckconfig.h>
30 #include <security_cryptkit/feeTypes.h>
31 #include <security_cryptkit/feePublicKey.h>
32 #include <security_cryptkit/giantIntegers.h>
33 #include <security_cryptkit/falloc.h>
34 #include <security_cryptkit/curveParams.h>
41 * Encode/decode the two FEE signature types. We malloc returned data via
42 * falloc(); caller must free via ffree().
44 feeReturn
feeDEREncodeElGamalSignature(
47 unsigned char **encodedSig
, // fallocd and RETURNED
48 unsigned *encodedSigLen
); // RETURNED
50 feeReturn
feeDEREncodeECDSASignature(
53 unsigned char **encodedSig
, // fallocd and RETURNED
54 unsigned *encodedSigLen
); // RETURNED
56 feeReturn
feeDERDecodeElGamalSignature(
57 const unsigned char *encodedSig
,
59 giant
*u
, // newGiant'd and RETURNED
60 giant
*PmX
); // newGiant'd and RETURNED
62 feeReturn
feeDERDecodeECDSASignature(
63 const unsigned char *encodedSig
,
65 giant
*c
, // newGiant'd and RETURNED
66 giant
*d
); // newGiant'd and RETURNED
69 * RAW format for ECDSA signatures
71 feeReturn
feeRAWEncodeECDSASignature(
72 unsigned groupBytesLen
,
75 unsigned char **encodedSig
, // fallocd and RETURNED
76 unsigned *encodedSigLen
); // RETURNED
78 feeReturn
feeRAWDecodeECDSASignature(
79 unsigned groupBytesLen
,
80 const unsigned char *encodedSig
,
82 giant
*c
, // newGiant'd and RETURNED
83 giant
*d
); // newGiant'd and RETURNED
88 * Encode/decode the FEE private and public keys. We malloc returned data via
89 * falloc(); caller must free via ffree().
90 * These use a DER format which is custom to this module.
92 feeReturn
feeDEREncodePublicKey(
94 const curveParams
*cp
,
97 giant plusY
, // may be NULL
98 unsigned char **keyBlob
, // fmallocd and RETURNED
99 unsigned *keyBlobLen
); // RETURNED
101 feeReturn
feeDEREncodePrivateKey(
103 const curveParams
*cp
,
104 const giant privData
,
105 unsigned char **keyBlob
, // fmallocd and RETURNED
106 unsigned *keyBlobLen
); // RETURNED
108 feeReturn
feeDERDecodePublicKey(
109 const unsigned char *keyBlob
,
111 int *version
, // this and remainder RETURNED
115 giant
*plusY
); // always valid, may be (giant)0
117 feeReturn
feeDERDecodePrivateKey(
118 const unsigned char *keyBlob
,
120 int *version
, // this and remainder RETURNED
122 giant
*privData
); // RETURNED
124 /* obtain the max size of a DER-encoded signature (either ElGamal or ECDSA) */
125 unsigned feeSizeOfDERSig(
130 * Encode/decode public key in X.509 format.
132 feeReturn
feeDEREncodeX509PublicKey(
133 const unsigned char *pubBlob
, /* x and y octet string */
136 unsigned char **x509Blob
, /* fmallocd and RETURNED */
137 unsigned *x509BlobLen
); /* RETURNED */
139 feeReturn
feeDERDecodeX509PublicKey(
140 const unsigned char *x509Blob
,
141 unsigned x509BlobLen
,
142 feeDepth
*depth
, /* RETURNED */
143 unsigned char **pubBlob
, /* x and y octet string RETURNED */
144 unsigned *pubBlobLen
); /* RETURNED */
147 * Encode private, and decode private or public key, in unencrypted OpenSSL format.
149 feeReturn
feeDEREncodeOpenSSLPrivateKey(
150 const unsigned char *privBlob
, /* private data octet string */
151 unsigned privBlobLen
,
152 const unsigned char *pubBlob
, /* public key, optional */
155 unsigned char **openBlob
, /* fmallocd and RETURNED */
156 unsigned *openBlobLen
); /* RETURNED */
158 feeReturn
feeDERDecodeOpenSSLKey(
159 const unsigned char *osBlob
,
161 feeDepth
*depth
, /* RETURNED */
162 unsigned char **privBlob
, /* private data octet string RETURNED */
163 unsigned *privBlobLen
, /* RETURNED */
164 unsigned char **pubBlob
, /* public data octet string optionally RETURNED */
165 unsigned *pubBlobLen
);
168 * Encode/decode private key in unencrypted PKCS8 format.
170 feeReturn
feeDEREncodePKCS8PrivateKey(
171 const unsigned char *privBlob
, /* private data octet string */
172 unsigned privBlobLen
,
173 const unsigned char *pubBlob
, /* public blob, optional */
176 unsigned char **pkcs8Blob
, /* fmallocd and RETURNED */
177 unsigned *pkcs8BlobLen
); /* RETURNED */
179 feeReturn
feeDERDecodePKCS8PrivateKey(
180 const unsigned char *pkcs8Blob
,
181 unsigned pkcs8BlobLen
,
182 feeDepth
*depth
, /* RETURNED */
183 unsigned char **privBlob
, /* private data octet string RETURNED */
184 unsigned *privBlobLen
, /* RETURNED */
185 unsigned char **pubBlob
, /* optionally returned, if it's there */
186 unsigned *pubBlobLen
);
193 #endif /* _CRYPTKIT_DER_H_ */