summaryrefslogtreecommitdiff
path: root/src/protocol/internal/ssh_cipher.h
blob: f39eea20894b399557afb5e133348ffbc40a8740 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef SSH_CIPHER_H
#define SSH_CIPHER_H

#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <openssl/evp.h>

#ifdef __cplusplus
extern "C" {
#endif

	typedef struct ssh_cipher_t SSH_CIPHER;
	typedef int (*crypt_t)(SSH_CIPHER*, const uint8_t*, uint8_t*, size_t);
	typedef int (*init_t)(SSH_CIPHER*, const uint8_t*, const uint8_t*);
	typedef void (*cleanup_t)(SSH_CIPHER*);

	struct ssh_cipher_t
	{
		/*
		 * priv is used for things like EVP_CIPHER_CTX and EVP_CIPHER
		 *
		 * We use only one crypt function for encrypt or decrypt.
		 *
		 * Before using the crypto function, IV and key must
		 * be set and then init function must be called
		 */
		const char *name;
		void *priv; /* IV and key should be placed in priv */
		crypt_t crypt;
		init_t init;
		cleanup_t cleanup;
		size_t blkSize;
		size_t keySize;
		size_t IVSize;
		bool started;
	};

	typedef const EVP_CIPHER*(*SSH_EVP)(void);
	typedef SSH_CIPHER*(*NEW_CIPHER)(int);

	SSH_CIPHER* new_ssh_cipher_evp(SSH_EVP, size_t key, size_t iv, size_t blk, int enc);
	SSH_CIPHER* new_3des_ssh1(int);
	/* all_ciphers.c */
	extern const char all_ciphers_list[];
	extern SSH_CIPHER ssh_cipher_dummy;
	NEW_CIPHER search_cipher(const char *s);

#ifdef __cplusplus
}
#endif

#endif