]>
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 #if CRYPTKIT_DER_ENABLE
32 #include <security_cryptkit/feeTypes.h>
33 #include <security_cryptkit/feePublicKey.h>
34 #include <security_cryptkit/giantIntegers.h>
35 #include <security_cryptkit/falloc.h>
36 #include <security_cryptkit/curveParams.h>
43 * Encode/decode the two FEE signature types. We malloc returned data via
44 * falloc(); caller must free via ffree().
46 feeReturn
feeDEREncodeElGamalSignature(
49 unsigned char **encodedSig
, // fallocd and RETURNED
50 unsigned *encodedSigLen
); // RETURNED
52 feeReturn
feeDEREncodeECDSASignature(
55 unsigned char **encodedSig
, // fallocd and RETURNED
56 unsigned *encodedSigLen
); // RETURNED
58 feeReturn
feeDERDecodeElGamalSignature(
59 const unsigned char *encodedSig
,
61 giant
*u
, // newGiant'd and RETURNED
62 giant
*PmX
); // newGiant'd and RETURNED
64 feeReturn
feeDERDecodeECDSASignature(
65 const unsigned char *encodedSig
,
67 giant
*c
, // newGiant'd and RETURNED
68 giant
*d
); // newGiant'd and RETURNED
71 * RAW format for ECDSA signatures
73 feeReturn
feeRAWEncodeECDSASignature(
74 unsigned groupBytesLen
,
77 unsigned char **encodedSig
, // fallocd and RETURNED
78 unsigned *encodedSigLen
); // RETURNED
80 feeReturn
feeRAWDecodeECDSASignature(
81 unsigned groupBytesLen
,
82 const unsigned char *encodedSig
,
84 giant
*c
, // newGiant'd and RETURNED
85 giant
*d
); // newGiant'd and RETURNED
90 * Encode/decode the FEE private and public keys. We malloc returned data via
91 * falloc(); caller must free via ffree().
92 * These use a DER format which is custom to this module.
94 feeReturn
feeDEREncodePublicKey(
96 const curveParams
*cp
,
99 giant plusY
, // may be NULL
100 unsigned char **keyBlob
, // fmallocd and RETURNED
101 unsigned *keyBlobLen
); // RETURNED
103 feeReturn
feeDEREncodePrivateKey(
105 const curveParams
*cp
,
106 const giant privData
,
107 unsigned char **keyBlob
, // fmallocd and RETURNED
108 unsigned *keyBlobLen
); // RETURNED
110 feeReturn
feeDERDecodePublicKey(
111 const unsigned char *keyBlob
,
113 int *version
, // this and remainder RETURNED
117 giant
*plusY
); // always valid, may be (giant)0
119 feeReturn
feeDERDecodePrivateKey(
120 const unsigned char *keyBlob
,
122 int *version
, // this and remainder RETURNED
124 giant
*privData
); // RETURNED
126 /* obtain the max size of a DER-encoded signature (either ElGamal or ECDSA) */
127 unsigned feeSizeOfDERSig(
132 * Encode/decode public key in X.509 format.
134 feeReturn
feeDEREncodeX509PublicKey(
135 const unsigned char *pubBlob
, /* x and y octet string */
138 unsigned char **x509Blob
, /* fmallocd and RETURNED */
139 unsigned *x509BlobLen
); /* RETURNED */
141 feeReturn
feeDERDecodeX509PublicKey(
142 const unsigned char *x509Blob
,
143 unsigned x509BlobLen
,
144 feeDepth
*depth
, /* RETURNED */
145 unsigned char **pubBlob
, /* x and y octet string RETURNED */
146 unsigned *pubBlobLen
); /* RETURNED */
149 * Encode private, and decode private or public key, in unencrypted OpenSSL format.
151 feeReturn
feeDEREncodeOpenSSLPrivateKey(
152 const unsigned char *privBlob
, /* private data octet string */
153 unsigned privBlobLen
,
154 const unsigned char *pubBlob
, /* public key, optional */
157 unsigned char **openBlob
, /* fmallocd and RETURNED */
158 unsigned *openBlobLen
); /* RETURNED */
160 feeReturn
feeDERDecodeOpenSSLKey(
161 const unsigned char *osBlob
,
163 feeDepth
*depth
, /* RETURNED */
164 unsigned char **privBlob
, /* private data octet string RETURNED */
165 unsigned *privBlobLen
, /* RETURNED */
166 unsigned char **pubBlob
, /* public data octet string optionally RETURNED */
167 unsigned *pubBlobLen
);
170 * Encode/decode private key in unencrypted PKCS8 format.
172 feeReturn
feeDEREncodePKCS8PrivateKey(
173 const unsigned char *privBlob
, /* private data octet string */
174 unsigned privBlobLen
,
175 const unsigned char *pubBlob
, /* public blob, optional */
178 unsigned char **pkcs8Blob
, /* fmallocd and RETURNED */
179 unsigned *pkcs8BlobLen
); /* RETURNED */
181 feeReturn
feeDERDecodePKCS8PrivateKey(
182 const unsigned char *pkcs8Blob
,
183 unsigned pkcs8BlobLen
,
184 feeDepth
*depth
, /* RETURNED */
185 unsigned char **privBlob
, /* private data octet string RETURNED */
186 unsigned *privBlobLen
, /* RETURNED */
187 unsigned char **pubBlob
, /* optionally returned, if it's there */
188 unsigned *pubBlobLen
);
195 #endif /* CRYPTKIT_DER_ENABLE */
196 #endif /* _CRYPTKIT_DER_H_ */