libssh  0.9.0
The SSH library
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 <stdbool.h>
25 
26 #include "config.h"
27 #include "libssh/libssh.h"
28 #include "libssh/libcrypto.h"
29 #include "libssh/libgcrypt.h"
30 #include "libssh/libmbedcrypto.h"
31 
32 enum ssh_digest_e {
33  SSH_DIGEST_AUTO=0,
34  SSH_DIGEST_SHA1=1,
35  SSH_DIGEST_SHA256,
36  SSH_DIGEST_SHA384,
37  SSH_DIGEST_SHA512,
38 };
39 
40 enum ssh_kdf_digest {
41  SSH_KDF_SHA1=1,
42  SSH_KDF_SHA256,
43  SSH_KDF_SHA384,
44  SSH_KDF_SHA512
45 };
46 
47 enum ssh_hmac_e {
48  SSH_HMAC_SHA1 = 1,
49  SSH_HMAC_SHA256,
50  SSH_HMAC_SHA512,
51  SSH_HMAC_MD5,
52  SSH_HMAC_AEAD_POLY1305,
53  SSH_HMAC_AEAD_GCM
54 };
55 
56 enum ssh_des_e {
57  SSH_3DES,
58  SSH_DES
59 };
60 
62  const char* name;
63  enum ssh_hmac_e hmac_type;
64  bool etm;
65 };
66 
67 enum ssh_crypto_direction_e {
68  SSH_DIRECTION_IN = 1,
69  SSH_DIRECTION_OUT = 2,
70  SSH_DIRECTION_BOTH = 3,
71 };
72 
73 struct ssh_cipher_struct;
74 struct ssh_crypto_struct;
75 
76 typedef struct ssh_mac_ctx_struct *ssh_mac_ctx;
77 MD5CTX md5_init(void);
78 void md5_update(MD5CTX c, const void *data, unsigned long len);
79 void md5_final(unsigned char *md,MD5CTX c);
80 
81 SHACTX sha1_init(void);
82 void sha1_update(SHACTX c, const void *data, unsigned long len);
83 void sha1_final(unsigned char *md,SHACTX c);
84 void sha1(const unsigned char *digest,int len,unsigned char *hash);
85 
86 SHA256CTX sha256_init(void);
87 void sha256_update(SHA256CTX c, const void *data, unsigned long len);
88 void sha256_final(unsigned char *md,SHA256CTX c);
89 void sha256(const unsigned char *digest, int len, unsigned char *hash);
90 
91 SHA384CTX sha384_init(void);
92 void sha384_update(SHA384CTX c, const void *data, unsigned long len);
93 void sha384_final(unsigned char *md,SHA384CTX c);
94 void sha384(const unsigned char *digest, int len, unsigned char *hash);
95 
96 SHA512CTX sha512_init(void);
97 void sha512_update(SHA512CTX c, const void *data, unsigned long len);
98 void sha512_final(unsigned char *md,SHA512CTX c);
99 void sha512(const unsigned char *digest, int len, unsigned char *hash);
100 
101 void evp(int nid, unsigned char *digest, int len, unsigned char *hash, unsigned int *hlen);
102 EVPCTX evp_init(int nid);
103 void evp_update(EVPCTX ctx, const void *data, unsigned long len);
104 void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen);
105 
106 HMACCTX hmac_init(const void *key,int len, enum ssh_hmac_e type);
107 void hmac_update(HMACCTX c, const void *data, unsigned long len);
108 void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
109 size_t hmac_digest_len(enum ssh_hmac_e type);
110 
111 int ssh_kdf(struct ssh_crypto_struct *crypto,
112  unsigned char *key, size_t key_len,
113  int key_type, unsigned char *output,
114  size_t requested_len);
115 
116 int crypt_set_algorithms_client(ssh_session session);
117 int crypt_set_algorithms_server(ssh_session session);
118 struct ssh_crypto_struct *crypto_new(void);
119 void crypto_free(struct ssh_crypto_struct *crypto);
120 
121 void ssh_reseed(void);
122 int ssh_crypto_init(void);
123 void ssh_crypto_finalize(void);
124 
125 void ssh_cipher_clear(struct ssh_cipher_struct *cipher);
126 struct ssh_hmac_struct *ssh_get_hmactab(void);
127 struct ssh_cipher_struct *ssh_get_ciphertab(void);
128 const char *ssh_hmac_type_to_string(enum ssh_hmac_e hmac_type, bool etm);
129 
130 #endif /* WRAPPER_H_ */
Definition: crypto.h:104
Definition: session.h:109
Definition: wrapper.h:61
Definition: kdf.c:43
Definition: crypto.h:157