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