]>
git.saurik.com Git - apple/security.git/blob - Security/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 * Encode/decode the FEE private and public keys. We malloc returned data via
72 * falloc(); caller must free via ffree().
73 * These use a DER format which is custom to this module.
75 feeReturn
feeDEREncodePublicKey(
77 const curveParams
*cp
,
80 giant plusY
, // may be NULL
81 unsigned char **keyBlob
, // fmallocd and RETURNED
82 unsigned *keyBlobLen
); // RETURNED
84 feeReturn
feeDEREncodePrivateKey(
86 const curveParams
*cp
,
88 unsigned char **keyBlob
, // fmallocd and RETURNED
89 unsigned *keyBlobLen
); // RETURNED
91 feeReturn
feeDERDecodePublicKey(
92 const unsigned char *keyBlob
,
94 int *version
, // this and remainder RETURNED
98 giant
*plusY
); // always valid, may be (giant)0
100 feeReturn
feeDERDecodePrivateKey(
101 const unsigned char *keyBlob
,
103 int *version
, // this and remainder RETURNED
105 giant
*privData
); // RETURNED
107 /* obtain the max size of a DER-encoded signature (either ElGamal or ECDSA) */
108 unsigned feeSizeOfDERSig(
113 * Encode/decode public key in X.509 format.
115 feeReturn
feeDEREncodeX509PublicKey(
116 const unsigned char *pubBlob
, /* x and y octet string */
119 unsigned char **x509Blob
, /* fmallocd and RETURNED */
120 unsigned *x509BlobLen
); /* RETURNED */
122 feeReturn
feeDERDecodeX509PublicKey(
123 const unsigned char *x509Blob
,
124 unsigned x509BlobLen
,
125 feeDepth
*depth
, /* RETURNED */
126 unsigned char **pubBlob
, /* x and y octet string RETURNED */
127 unsigned *pubBlobLen
); /* RETURNED */
130 * Encode private, and decode private or public key, in unencrypted OpenSSL format.
132 feeReturn
feeDEREncodeOpenSSLPrivateKey(
133 const unsigned char *privBlob
, /* private data octet string */
134 unsigned privBlobLen
,
135 const unsigned char *pubBlob
, /* public key, optional */
138 unsigned char **openBlob
, /* fmallocd and RETURNED */
139 unsigned *openBlobLen
); /* RETURNED */
141 feeReturn
feeDERDecodeOpenSSLKey(
142 const unsigned char *osBlob
,
144 feeDepth
*depth
, /* RETURNED */
145 unsigned char **privBlob
, /* private data octet string RETURNED */
146 unsigned *privBlobLen
, /* RETURNED */
147 unsigned char **pubBlob
, /* public data octet string optionally RETURNED */
148 unsigned *pubBlobLen
);
151 * Encode/decode private key in unencrypted PKCS8 format.
153 feeReturn
feeDEREncodePKCS8PrivateKey(
154 const unsigned char *privBlob
, /* private data octet string */
155 unsigned privBlobLen
,
156 const unsigned char *pubBlob
, /* public blob, optional */
159 unsigned char **pkcs8Blob
, /* fmallocd and RETURNED */
160 unsigned *pkcs8BlobLen
); /* RETURNED */
162 feeReturn
feeDERDecodePKCS8PrivateKey(
163 const unsigned char *pkcs8Blob
,
164 unsigned pkcs8BlobLen
,
165 feeDepth
*depth
, /* RETURNED */
166 unsigned char **privBlob
, /* private data octet string RETURNED */
167 unsigned *privBlobLen
, /* RETURNED */
168 unsigned char **pubBlob
, /* optionally returned, if it's there */
169 unsigned *pubBlobLen
);
176 #endif /* CRYPTKIT_DER_ENABLE */
177 #endif /* _CRYPTKIT_DER_H_ */