libssh  0.5.4
keys.h
1 /*
2  * This file is part of the SSH Library
3  *
4  * Copyright (c) 2009 by Aris Adamantiadis
5  *
6  * The SSH Library is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or (at your
9  * option) any later version.
10  *
11  * The SSH Library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with the SSH Library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19  * MA 02111-1307, USA.
20  */
21 
22 #ifndef KEYS_H_
23 #define KEYS_H_
24 
25 #include "config.h"
26 #include "libssh/libssh.h"
27 #include "libssh/wrapper.h"
28 
29 struct ssh_public_key_struct {
30  int type;
31  const char *type_c; /* Don't free it ! it is static */
32 #ifdef HAVE_LIBGCRYPT
33  gcry_sexp_t dsa_pub;
34  gcry_sexp_t rsa_pub;
35 #elif HAVE_LIBCRYPTO
36  DSA *dsa_pub;
37  RSA *rsa_pub;
38 #endif
39 };
40 
41 struct ssh_private_key_struct {
42  int type;
43 #ifdef HAVE_LIBGCRYPT
44  gcry_sexp_t dsa_priv;
45  gcry_sexp_t rsa_priv;
46 #elif defined HAVE_LIBCRYPTO
47  DSA *dsa_priv;
48  RSA *rsa_priv;
49 #endif
50 };
51 
52 typedef struct signature_struct {
53  int type;
54 #ifdef HAVE_LIBGCRYPT
55  gcry_sexp_t dsa_sign;
56  gcry_sexp_t rsa_sign;
57 #elif defined HAVE_LIBCRYPTO
58  DSA_SIG *dsa_sign;
59  ssh_string rsa_sign;
60 #endif
61 } SIGNATURE;
62 
63 const char *ssh_type_to_char(int type);
64 int ssh_type_from_name(const char *name);
65 ssh_buffer ssh_userauth_build_digest(ssh_session session, ssh_message msg, char *service);
66 
67 ssh_private_key privatekey_make_dss(ssh_session session, ssh_buffer buffer);
68 ssh_private_key privatekey_make_rsa(ssh_session session, ssh_buffer buffer,
69  const char *type);
70 ssh_private_key privatekey_from_string(ssh_session session, ssh_string privkey_s);
71 
72 ssh_public_key publickey_make_dss(ssh_session session, ssh_buffer buffer);
73 ssh_public_key publickey_make_rsa(ssh_session session, ssh_buffer buffer, int type);
74 ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s);
75 SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,ssh_public_key pubkey,int needed_type);
76 void signature_free(SIGNATURE *sign);
77 ssh_string ssh_do_sign_with_agent(struct ssh_session_struct *session,
78  struct ssh_buffer_struct *buf, struct ssh_public_key_struct *publickey);
79 ssh_string ssh_do_sign(ssh_session session,ssh_buffer sigbuf,
80  ssh_private_key privatekey);
81 ssh_string ssh_sign_session_id(ssh_session session, ssh_private_key privatekey);
82 ssh_string ssh_encrypt_rsa1(ssh_session session, ssh_string data, ssh_public_key key);
83 
84 #endif /* KEYS_H_ */