libssh  0.8.0
wrapper.h
1 /*
2  * This file is part of the SSH Library
3  *
4  * Copyright (c) 2009 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 WRAPPER_H_
22 #define WRAPPER_H_
23 
24 #include "config.h"
25 #include "libssh/libssh.h"
26 #include "libssh/libcrypto.h"
27 #include "libssh/libgcrypt.h"
28 
29 enum ssh_mac_e {
30  SSH_MAC_SHA1=1,
31  SSH_MAC_SHA256,
32  SSH_MAC_SHA384,
33  SSH_MAC_SHA512
34 };
35 
36 enum ssh_hmac_e {
37  SSH_HMAC_SHA1 = 1,
38  SSH_HMAC_SHA256,
39  SSH_HMAC_SHA384,
40  SSH_HMAC_SHA512,
41  SSH_HMAC_MD5
42 };
43 
44 enum ssh_des_e {
45  SSH_3DES,
46  SSH_DES
47 };
48 
49 struct ssh_hmac_struct {
50  const char* name;
51  enum ssh_hmac_e hmac_type;
52 };
53 
54 typedef struct ssh_mac_ctx_struct *ssh_mac_ctx;
55 MD5CTX md5_init(void);
56 void md5_ctx_free(MD5CTX);
57 int md5_update(MD5CTX c, const void *data, unsigned long len);
58 int md5_final(unsigned char *md,MD5CTX c);
59 
60 SHACTX sha1_init(void);
61 void sha1_ctx_free(SHACTX);
62 int sha1_update(SHACTX c, const void *data, unsigned long len);
63 int sha1_final(unsigned char *md,SHACTX c);
64 int sha1(unsigned char *digest,int len,unsigned char *hash);
65 
66 SHA256CTX sha256_init(void);
67 void sha256_ctx_free(SHA256CTX);
68 int sha256_update(SHA256CTX c, const void *data, unsigned long len);
69 int sha256_final(unsigned char *md,SHA256CTX c);
70 int sha256(unsigned char *digest, int len, unsigned char *hash);
71 
72 SHA384CTX sha384_init(void);
73 void sha384_ctx_free(SHA384CTX);
74 int sha384_update(SHA384CTX c, const void *data, unsigned long len);
75 int sha384_final(unsigned char *md,SHA384CTX c);
76 int sha384(unsigned char *digest, int len, unsigned char *hash);
77 
78 SHA512CTX sha512_init(void);
79 void sha512_ctx_free(SHA512CTX);
80 int sha512_update(SHA512CTX c, const void *data, unsigned long len);
81 int sha512_final(unsigned char *md,SHA512CTX c);
82 int sha512(unsigned char *digest, int len, unsigned char *hash);
83 
84 void evp(int nid, unsigned char *digest, int len, unsigned char *hash, unsigned int *hlen);
85 EVPCTX evp_init(int nid);
86 void evp_update(EVPCTX ctx, const void *data, unsigned long len);
87 void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen);
88 
89 ssh_mac_ctx ssh_mac_ctx_init(enum ssh_mac_e type);
90 void ssh_mac_ctx_free(ssh_mac_ctx ctx);
91 int ssh_mac_update(ssh_mac_ctx ctx, const void *data, unsigned long len);
92 int ssh_mac_final(unsigned char *md, ssh_mac_ctx ctx);
93 
94 HMACCTX hmac_init(const void *key,int len, enum ssh_hmac_e type);
95 void hmac_update(HMACCTX c, const void *data, unsigned long len);
96 void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
97 
98 size_t hmac_digest_len(enum ssh_hmac_e type);
99 
100 int crypt_set_algorithms(ssh_session session, enum ssh_des_e des_type);
101 int crypt_set_algorithms_server(ssh_session session);
102 struct ssh_crypto_struct *crypto_new(void);
103 void crypto_free(struct ssh_crypto_struct *crypto);
104 
105 void ssh_reseed(void);
106 
107 void ssh_cipher_clear(struct ssh_cipher_struct *cipher);
108 struct ssh_hmac_struct *ssh_get_hmactab(void);
109 const char *ssh_hmac_type_to_string(enum ssh_hmac_e hmac_type);
110 
111 #endif /* WRAPPER_H_ */