]>
git.saurik.com Git - apple/security.git/blob - libsecurity_cryptkit/lib/CryptKitDER.h
2 * CryptKitDER.h - snacc-based routines to create and parse DER-encoded FEE
5 * Created 3/12/2001 by dmitch.
8 #ifndef _CRYPTKIT_DER_H_
9 #define _CRYPTKIT_DER_H_
11 #include <security_cryptkit/ckconfig.h>
13 #if CRYPTKIT_DER_ENABLE
15 #include <security_cryptkit/feeTypes.h>
16 #include <security_cryptkit/feePublicKey.h>
17 #include <security_cryptkit/giantIntegers.h>
18 #include <security_cryptkit/falloc.h>
19 #include <security_cryptkit/curveParams.h>
26 * Encode/decode the two FEE signature types. We malloc returned data via
27 * falloc(); caller must free via ffree().
29 feeReturn
feeDEREncodeElGamalSignature(
32 unsigned char **encodedSig
, // fallocd and RETURNED
33 unsigned *encodedSigLen
); // RETURNED
35 feeReturn
feeDEREncodeECDSASignature(
38 unsigned char **encodedSig
, // fallocd and RETURNED
39 unsigned *encodedSigLen
); // RETURNED
41 feeReturn
feeDERDecodeElGamalSignature(
42 const unsigned char *encodedSig
,
44 giant
*u
, // newGiant'd and RETURNED
45 giant
*PmX
); // newGiant'd and RETURNED
47 feeReturn
feeDERDecodeECDSASignature(
48 const unsigned char *encodedSig
,
50 giant
*c
, // newGiant'd and RETURNED
51 giant
*d
); // newGiant'd and RETURNED
54 * Encode/decode the FEE private and public keys. We malloc returned data via
55 * falloc(); caller must free via ffree().
56 * These use a DER format which is custom to this module.
58 feeReturn
feeDEREncodePublicKey(
60 const curveParams
*cp
,
63 giant plusY
, // may be NULL
64 unsigned char **keyBlob
, // fmallocd and RETURNED
65 unsigned *keyBlobLen
); // RETURNED
67 feeReturn
feeDEREncodePrivateKey(
69 const curveParams
*cp
,
71 unsigned char **keyBlob
, // fmallocd and RETURNED
72 unsigned *keyBlobLen
); // RETURNED
74 feeReturn
feeDERDecodePublicKey(
75 const unsigned char *keyBlob
,
77 int *version
, // this and remainder RETURNED
81 giant
*plusY
); // always valid, may be (giant)0
83 feeReturn
feeDERDecodePrivateKey(
84 const unsigned char *keyBlob
,
86 int *version
, // this and remainder RETURNED
88 giant
*privData
); // RETURNED
90 /* obtain the max size of a DER-encoded signature (either ElGamal or ECDSA) */
91 unsigned feeSizeOfDERSig(
96 * Encode/decode public key in X.509 format.
98 feeReturn
feeDEREncodeX509PublicKey(
99 const unsigned char *pubBlob
, /* x and y octet string */
102 unsigned char **x509Blob
, /* fmallocd and RETURNED */
103 unsigned *x509BlobLen
); /* RETURNED */
105 feeReturn
feeDERDecodeX509PublicKey(
106 const unsigned char *x509Blob
,
107 unsigned x509BlobLen
,
108 feeDepth
*depth
, /* RETURNED */
109 unsigned char **pubBlob
, /* x and y octet string RETURNED */
110 unsigned *pubBlobLen
); /* RETURNED */
113 * Encode private, and decode private or public key, in unencrypted OpenSSL format.
115 feeReturn
feeDEREncodeOpenSSLPrivateKey(
116 const unsigned char *privBlob
, /* private data octet string */
117 unsigned privBlobLen
,
118 const unsigned char *pubBlob
, /* public key, optional */
121 unsigned char **openBlob
, /* fmallocd and RETURNED */
122 unsigned *openBlobLen
); /* RETURNED */
124 feeReturn
feeDERDecodeOpenSSLKey(
125 const unsigned char *osBlob
,
127 feeDepth
*depth
, /* RETURNED */
128 unsigned char **privBlob
, /* private data octet string RETURNED */
129 unsigned *privBlobLen
, /* RETURNED */
130 unsigned char **pubBlob
, /* public data octet string optionally RETURNED */
131 unsigned *pubBlobLen
);
134 * Encode/decode private key in unencrypted PKCS8 format.
136 feeReturn
feeDEREncodePKCS8PrivateKey(
137 const unsigned char *privBlob
, /* private data octet string */
138 unsigned privBlobLen
,
139 const unsigned char *pubBlob
, /* public blob, optional */
142 unsigned char **pkcs8Blob
, /* fmallocd and RETURNED */
143 unsigned *pkcs8BlobLen
); /* RETURNED */
145 feeReturn
feeDERDecodePKCS8PrivateKey(
146 const unsigned char *pkcs8Blob
,
147 unsigned pkcs8BlobLen
,
148 feeDepth
*depth
, /* RETURNED */
149 unsigned char **privBlob
, /* private data octet string RETURNED */
150 unsigned *privBlobLen
, /* RETURNED */
151 unsigned char **pubBlob
, /* optionally returned, if it's there */
152 unsigned *pubBlobLen
);
159 #endif /* CRYPTKIT_DER_ENABLE */
160 #endif /* _CRYPTKIT_DER_H_ */