libssh  0.6.5
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_log(SSH_LOG_FUNCTIONS, __func__, __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 const char *pki_key_ecdsa_nid_to_name(int nid);
38 
39 /* SSH Key Functions */
40 ssh_key pki_key_dup(const ssh_key key, int demote);
41 int pki_key_generate_rsa(ssh_key key, int parameter);
42 int pki_key_generate_dss(ssh_key key, int parameter);
43 int pki_key_generate_ecdsa(ssh_key key, int parameter);
44 int pki_key_compare(const ssh_key k1,
45  const ssh_key k2,
46  enum ssh_keycmp_e what);
47 
48 /* SSH Private Key Functions */
49 enum ssh_keytypes_e pki_privatekey_type_from_string(const char *privkey);
50 ssh_key pki_private_key_from_base64(const char *b64_key,
51  const char *passphrase,
52  ssh_auth_callback auth_fn,
53  void *auth_data);
54 
55 ssh_string pki_private_key_to_pem(const ssh_key key,
56  const char *passphrase,
57  ssh_auth_callback auth_fn,
58  void *auth_data);
59 
60 /* SSH Public Key Functions */
61 int pki_pubkey_build_dss(ssh_key key,
62  ssh_string p,
63  ssh_string q,
64  ssh_string g,
65  ssh_string pubkey);
66 int pki_pubkey_build_rsa(ssh_key key,
67  ssh_string e,
68  ssh_string n);
69 int pki_pubkey_build_ecdsa(ssh_key key, int nid, ssh_string e);
70 ssh_string pki_publickey_to_blob(const ssh_key key);
71 int pki_export_pubkey_rsa1(const ssh_key key,
72  const char *host,
73  char *rsa1,
74  size_t rsa1_len);
75 
76 /* SSH Signature Functions */
77 ssh_string pki_signature_to_blob(const ssh_signature sign);
78 ssh_signature pki_signature_from_blob(const ssh_key pubkey,
79  const ssh_string sig_blob,
80  enum ssh_keytypes_e type);
81 int pki_signature_verify(ssh_session session,
82  const ssh_signature sig,
83  const ssh_key key,
84  const unsigned char *hash,
85  size_t hlen);
86 
87 /* SSH Signing Functions */
88 ssh_signature pki_do_sign(const ssh_key privkey,
89  const unsigned char *hash,
90  size_t hlen);
91 ssh_signature pki_do_sign_sessionid(const ssh_key key,
92  const unsigned char *hash,
93  size_t hlen);
94 #endif /* PKI_PRIV_H_ */