libssh  0.9.3
The SSH library
pki_priv.h
1/*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2010 by Aris Adamantiadis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef PKI_PRIV_H_
22#define PKI_PRIV_H_
23
24#include "libssh/pki.h"
25
26/* defined in bcrypt_pbkdf.c */
27int bcrypt_pbkdf(const char *pass,
28 size_t passlen,
29 const uint8_t *salt,
30 size_t saltlen,
31 uint8_t *key,
32 size_t keylen,
33 unsigned int rounds);
34
35#define RSA_HEADER_BEGIN "-----BEGIN RSA PRIVATE KEY-----"
36#define RSA_HEADER_END "-----END RSA PRIVATE KEY-----"
37#define DSA_HEADER_BEGIN "-----BEGIN DSA PRIVATE KEY-----"
38#define DSA_HEADER_END "-----END DSA PRIVATE KEY-----"
39#define ECDSA_HEADER_BEGIN "-----BEGIN EC PRIVATE KEY-----"
40#define ECDSA_HEADER_END "-----END EC PRIVATE KEY-----"
41#define OPENSSH_HEADER_BEGIN "-----BEGIN OPENSSH PRIVATE KEY-----"
42#define OPENSSH_HEADER_END "-----END OPENSSH PRIVATE KEY-----"
43/* Magic defined in OpenSSH/PROTOCOL.key */
44#define OPENSSH_AUTH_MAGIC "openssh-key-v1"
45
46int pki_key_ecdsa_nid_from_name(const char *name);
47const char *pki_key_ecdsa_nid_to_name(int nid);
48const char *ssh_key_signature_to_char(enum ssh_keytypes_e type,
49 enum ssh_digest_e hash_type);
50enum ssh_digest_e ssh_key_type_to_hash(ssh_session session,
51 enum ssh_keytypes_e type);
52
53/* SSH Key Functions */
54ssh_key pki_key_dup(const ssh_key key, int demote);
55int pki_key_generate_rsa(ssh_key key, int parameter);
56int pki_key_generate_dss(ssh_key key, int parameter);
57int pki_key_generate_ecdsa(ssh_key key, int parameter);
58int pki_key_generate_ed25519(ssh_key key);
59
60int pki_key_compare(const ssh_key k1,
61 const ssh_key k2,
62 enum ssh_keycmp_e what);
63
64int pki_key_check_hash_compatible(ssh_key key,
65 enum ssh_digest_e hash_type);
66/* SSH Private Key Functions */
67enum ssh_keytypes_e pki_privatekey_type_from_string(const char *privkey);
68ssh_key pki_private_key_from_base64(const char *b64_key,
69 const char *passphrase,
70 ssh_auth_callback auth_fn,
71 void *auth_data);
72
73ssh_string pki_private_key_to_pem(const ssh_key key,
74 const char *passphrase,
75 ssh_auth_callback auth_fn,
76 void *auth_data);
77int pki_import_privkey_buffer(enum ssh_keytypes_e type,
78 ssh_buffer buffer,
79 ssh_key *pkey);
80
81/* SSH Public Key Functions */
82int pki_pubkey_build_dss(ssh_key key,
83 ssh_string p,
84 ssh_string q,
85 ssh_string g,
86 ssh_string pubkey);
87int pki_pubkey_build_rsa(ssh_key key,
88 ssh_string e,
89 ssh_string n);
90int pki_pubkey_build_ecdsa(ssh_key key, int nid, ssh_string e);
91ssh_string pki_publickey_to_blob(const ssh_key key);
92
93/* SSH Private Key Functions */
94int pki_privkey_build_dss(ssh_key key,
95 ssh_string p,
96 ssh_string q,
97 ssh_string g,
98 ssh_string pubkey,
99 ssh_string privkey);
100int pki_privkey_build_rsa(ssh_key key,
101 ssh_string n,
102 ssh_string e,
103 ssh_string d,
104 ssh_string iqmp,
105 ssh_string p,
106 ssh_string q);
107int pki_privkey_build_ecdsa(ssh_key key,
108 int nid,
109 ssh_string e,
110 ssh_string exp);
111ssh_string pki_publickey_to_blob(const ssh_key key);
112
113/* SSH Signature Functions */
114ssh_signature pki_sign_data(const ssh_key privkey,
115 enum ssh_digest_e hash_type,
116 const unsigned char *input,
117 size_t input_len);
118int pki_verify_data_signature(ssh_signature signature,
119 const ssh_key pubkey,
120 const unsigned char *input,
121 size_t input_len);
122ssh_string pki_signature_to_blob(const ssh_signature sign);
123ssh_signature pki_signature_from_blob(const ssh_key pubkey,
124 const ssh_string sig_blob,
125 enum ssh_keytypes_e type,
126 enum ssh_digest_e hash_type);
127
128/* SSH Signing Functions */
129ssh_signature pki_do_sign(const ssh_key privkey,
130 const unsigned char *input,
131 size_t input_len,
132 enum ssh_digest_e hash_type);
133ssh_signature pki_do_sign_hash(const ssh_key privkey,
134 const unsigned char *hash,
135 size_t hlen,
136 enum ssh_digest_e hash_type);
137int pki_ed25519_sign(const ssh_key privkey, ssh_signature sig,
138 const unsigned char *hash, size_t hlen);
139int pki_ed25519_verify(const ssh_key pubkey, ssh_signature sig,
140 const unsigned char *hash, size_t hlen);
141int pki_ed25519_key_cmp(const ssh_key k1,
142 const ssh_key k2,
143 enum ssh_keycmp_e what);
144int pki_ed25519_key_dup(ssh_key new, const ssh_key key);
145int pki_ed25519_public_key_to_blob(ssh_buffer buffer, ssh_key key);
146ssh_string pki_ed25519_signature_to_blob(ssh_signature sig);
147int pki_signature_from_ed25519_blob(ssh_signature sig, ssh_string sig_blob);
148int pki_privkey_build_ed25519(ssh_key key,
149 ssh_string pubkey,
150 ssh_string privkey);
151
152/* PKI Container OpenSSH */
153ssh_key ssh_pki_openssh_pubkey_import(const char *text_key);
154ssh_key ssh_pki_openssh_privkey_import(const char *text_key,
155 const char *passphrase, ssh_auth_callback auth_fn, void *auth_data);
156ssh_string ssh_pki_openssh_privkey_export(const ssh_key privkey,
157 const char *passphrase, ssh_auth_callback auth_fn, void *auth_data);
158
159#endif /* PKI_PRIV_H_ */
const char * ssh_key_signature_to_char(enum ssh_keytypes_e type, enum ssh_digest_e hash_type)
Convert a signature type to a string.
Definition: pki.c:226
enum ssh_digest_e ssh_key_type_to_hash(ssh_session session, enum ssh_keytypes_e type)
Convert a key type to a hash type. This is usually unambiguous for all the key types,...
Definition: pki.c:390
Definition: buffer.c:47
Definition: pki.h:50
Definition: session.h:109
Definition: pki.h:83
Definition: string.h:29