]> git.saurik.com Git - apple/security.git/blob - libsecurity_apple_csp/lib/opensshCoding.h
Security-55163.44.tar.gz
[apple/security.git] / libsecurity_apple_csp / lib / opensshCoding.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * opensshCoding.h - Encoding and decoding of OpenSSH format public keys.
26 *
27 * Created 8/29/2006 by dmitch.
28 */
29
30 #ifndef _OPENSSH_CODING_H_
31 #define _OPENSSH_CODING_H_
32
33 #include <openssl/rsa.h>
34 #include <openssl/dsa.h>
35 #include <Security/cssmtype.h>
36 #include <security_cdsa_utilities/cssmdata.h>
37 #include <CoreFoundation/CFData.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 void appendUint32(
44 CFMutableDataRef cfOut,
45 uint32_t ui);
46 uint32_t readUint32(
47 const unsigned char *&cp, // IN/OUT
48 unsigned &len); // IN/OUT
49
50 extern CSSM_RETURN RSAPublicKeyEncodeOpenSSH1(
51 RSA *openKey,
52 const CssmData &descData,
53 CssmOwnedData &encodedKey);
54
55 extern CSSM_RETURN RSAPublicKeyDecodeOpenSSH1(
56 RSA *openKey,
57 void *p,
58 size_t length);
59
60 extern CSSM_RETURN RSAPrivateKeyEncodeOpenSSH1(
61 RSA *openKey,
62 const CssmData &descData,
63 CssmOwnedData &encodedKey);
64
65 extern CSSM_RETURN RSAPrivateKeyDecodeOpenSSH1(
66 RSA *openKey,
67 void *p,
68 size_t length);
69
70 extern CSSM_RETURN RSAPublicKeyEncodeOpenSSH2(
71 RSA *openKey,
72 const CssmData &descData,
73 CssmOwnedData &encodedKey);
74
75 extern CSSM_RETURN RSAPublicKeyDecodeOpenSSH2(
76 RSA *openKey,
77 void *p,
78 size_t length);
79
80 extern CSSM_RETURN DSAPublicKeyEncodeOpenSSH2(
81 DSA *openKey,
82 const CssmData &descData,
83 CssmOwnedData &encodedKey);
84
85 extern CSSM_RETURN DSAPublicKeyDecodeOpenSSH2(
86 DSA *openKey,
87 void *p,
88 size_t length);
89
90 /* In opensshWrap.cpp */
91
92 /* Encode OpenSSHv1 private key, with or without encryption */
93 extern CSSM_RETURN encodeOpenSSHv1PrivKey(
94 RSA *r,
95 const uint8 *comment, /* optional */
96 unsigned commentLen,
97 const uint8 *encryptKey, /* optional; if present, it's 16 bytes of MD5(password) */
98 CFDataRef *encodedKey); /* RETURNED */
99
100 extern CSSM_RETURN decodeOpenSSHv1PrivKey(
101 const unsigned char *encodedKey,
102 unsigned encodedKeyLen,
103 RSA *r,
104 const uint8 *decryptKey, /* optional; if present, it's 16 bytes of MD5(password) */
105 uint8 **comment, /* mallocd and RETURNED */
106 unsigned *commentLen); /* RETURNED */
107
108 #ifdef __cplusplus
109 }
110 #endif
111
112 #endif /* _OPENSSH_CODING_H_ */