libssh  0.6.3
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 #define RSA_HEADER_BEGIN "-----BEGIN RSA PRIVATE KEY-----"
25 #define RSA_HEADER_END "-----END RSA PRIVATE KEY-----"
26 #define DSA_HEADER_BEGIN "-----BEGIN DSA PRIVATE KEY-----"
27 #define DSA_HEADER_END "-----END DSA PRIVATE KEY-----"
28 #define ECDSA_HEADER_BEGIN "-----BEGIN EC PRIVATE KEY-----"
29 #define ECDSA_HEADER_END "-----END EC PRIVATE KEY-----"
30 
31 #define ssh_pki_log(...) \
32  _ssh_pki_log(__FUNCTION__, __VA_ARGS__)
33 void _ssh_pki_log(const char *function,
34  const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
35 
36 int pki_key_ecdsa_nid_from_name(const char *name);
37 
38 /* SSH Key Functions */
39 ssh_key pki_key_dup(const ssh_key key, int demote);
40 int pki_key_generate_rsa(ssh_key key, int parameter);
41 int pki_key_generate_dss(ssh_key key, int parameter);
42 int pki_key_generate_ecdsa(ssh_key key, int parameter);
43 int pki_key_compare(const ssh_key k1,
44  const ssh_key k2,
45  enum ssh_keycmp_e what);
46 
47 /* SSH Private Key Functions */
48 enum ssh_keytypes_e pki_privatekey_type_from_string(const char *privkey);
49 ssh_key pki_private_key_from_base64(const char *b64_key,
50  const char *passphrase,
51  ssh_auth_callback auth_fn,
52  void *auth_data);
53 
54 ssh_string pki_private_key_to_pem(const ssh_key key,
55  const char *passphrase,
56  ssh_auth_callback auth_fn,
57  void *auth_data);
58 
59 /* SSH Public Key Functions */
60 int pki_pubkey_build_dss(ssh_key key,
61  ssh_string p,
62  ssh_string q,
63  ssh_string g,
64  ssh_string pubkey);
65 int pki_pubkey_build_rsa(ssh_key key,
66  ssh_string e,
67  ssh_string n);
68 int pki_pubkey_build_ecdsa(ssh_key key, int nid, ssh_string e);
69 ssh_string pki_publickey_to_blob(const ssh_key key);
70 int pki_export_pubkey_rsa1(const ssh_key key,
71  const char *host,
72  char *rsa1,
73  size_t rsa1_len);
74 
75 /* SSH Signature Functions */
76 ssh_string pki_signature_to_blob(const ssh_signature sign);
77 ssh_signature pki_signature_from_blob(const ssh_key pubkey,
78  const ssh_string sig_blob,
79  enum ssh_keytypes_e type);
80 int pki_signature_verify(ssh_session session,
81  const ssh_signature sig,
82  const ssh_key key,
83  const unsigned char *hash,
84  size_t hlen);
85 
86 /* SSH Signing Functions */
87 ssh_signature pki_do_sign(const ssh_key privkey,
88  const unsigned char *hash,
89  size_t hlen);
90 ssh_signature pki_do_sign_sessionid(const ssh_key key,
91  const unsigned char *hash,
92  size_t hlen);
93 #endif /* PKI_PRIV_H_ */