libssh 0.12.0
The SSH library
Loading...
Searching...
No Matches
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
26#include <stdbool.h>
27
28#include "libssh/libcrypto.h"
29#include "libssh/libgcrypt.h"
30#include "libssh/libmbedcrypto.h"
31#include "libssh/libssh.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37enum ssh_kdf_digest {
38 SSH_KDF_SHA1=1,
39 SSH_KDF_SHA256,
40 SSH_KDF_SHA384,
41 SSH_KDF_SHA512
42};
43
44enum ssh_hmac_e {
45 SSH_HMAC_SHA1 = 1,
46 SSH_HMAC_SHA256,
47 SSH_HMAC_SHA512,
48 SSH_HMAC_MD5,
49 SSH_HMAC_AEAD_POLY1305,
50 SSH_HMAC_AEAD_GCM,
51 SSH_HMAC_NONE,
52};
53
54enum ssh_des_e {
55 SSH_3DES,
56 SSH_DES
57};
58
59struct ssh_hmac_struct {
60 const char* name;
61 enum ssh_hmac_e hmac_type;
62 bool etm;
63};
64
65enum ssh_crypto_direction_e {
66 SSH_DIRECTION_IN = 1,
67 SSH_DIRECTION_OUT = 2,
68 SSH_DIRECTION_BOTH = 3,
69};
70
71struct ssh_cipher_struct;
72struct ssh_crypto_struct;
73
74typedef struct ssh_mac_ctx_struct *ssh_mac_ctx;
75MD5CTX md5_init(void);
76void md5_ctx_free(MD5CTX);
77int md5_update(MD5CTX c, const void *data, size_t len);
78int md5_final(unsigned char *md, MD5CTX c);
79int md5(const unsigned char *digest, size_t len, unsigned char *hash);
80
81SHACTX sha1_init(void);
82void sha1_ctx_free(SHACTX);
83int sha1_update(SHACTX c, const void *data, size_t len);
84int sha1_final(unsigned char *md,SHACTX c);
85int sha1(const unsigned char *digest,size_t len, unsigned char *hash);
86
87SHA256CTX sha256_init(void);
88void sha256_ctx_free(SHA256CTX);
89int sha256_update(SHA256CTX c, const void *data, size_t len);
90int sha256_final(unsigned char *md,SHA256CTX c);
91int sha256(const unsigned char *digest, size_t len, unsigned char *hash);
92
93SHA384CTX sha384_init(void);
94void sha384_ctx_free(SHA384CTX);
95int sha384_update(SHA384CTX c, const void *data, size_t len);
96int sha384_final(unsigned char *md,SHA384CTX c);
97int sha384(const unsigned char *digest, size_t len, unsigned char *hash);
98
99SHA512CTX sha512_init(void);
100void sha512_ctx_free(SHA512CTX);
101int sha512_update(SHA512CTX c, const void *data, size_t len);
102int sha512_final(unsigned char *md,SHA512CTX c);
103int sha512(const unsigned char *digest, size_t len, unsigned char *hash);
104
105HMACCTX hmac_init(const void *key,size_t len, enum ssh_hmac_e type);
106int hmac_update(HMACCTX c, const void *data, size_t len);
107int hmac_final(HMACCTX ctx, unsigned char *hashmacbuf, size_t *len);
108size_t hmac_digest_len(enum ssh_hmac_e type);
109
110int ssh_kdf(struct ssh_crypto_struct *crypto,
111 unsigned char *key, size_t key_len,
112 uint8_t key_type, unsigned char *output,
113 size_t requested_len);
114
115int crypt_set_algorithms_client(ssh_session session);
116int crypt_set_algorithms_server(ssh_session session);
117struct ssh_crypto_struct *crypto_new(void);
118void crypto_free(struct ssh_crypto_struct *crypto);
119
120void ssh_reseed(void);
121int ssh_crypto_init(void);
122void ssh_crypto_finalize(void);
123
124void ssh_cipher_clear(struct ssh_cipher_struct *cipher);
125struct ssh_hmac_struct *ssh_get_hmactab(void);
126struct ssh_cipher_struct *ssh_get_ciphertab(void);
127const char *ssh_hmac_type_to_string(enum ssh_hmac_e hmac_type, bool etm);
128
129#if defined(HAVE_LIBCRYPTO) && OPENSSL_VERSION_NUMBER >= 0x30000000L
130int evp_build_pkey(const char* name, OSSL_PARAM_BLD *param_bld, EVP_PKEY **pkey, int selection);
131int evp_dup_dsa_pkey(const ssh_key key, ssh_key new_key, int demote);
132int evp_dup_rsa_pkey(const ssh_key key, ssh_key new_key, int demote);
133int evp_dup_ecdsa_pkey(const ssh_key key, ssh_key new_key, int demote);
134int evp_dup_ed25519_pkey(const ssh_key key, ssh_key new_key, int demote);
135#endif /* HAVE_LIBCRYPTO && OPENSSL_VERSION_NUMBER */
136
137#ifdef __cplusplus
138}
139#endif
140
141#endif /* WRAPPER_H_ */