1
1

crypto: rename crypto_struct -> ssh_cipher_struct

Этот коммит содержится в:
Aris Adamantiadis 2011-09-17 00:20:45 +02:00
родитель ac41a083ef
Коммит af09313eac
7 изменённых файлов: 49 добавлений и 49 удалений

Просмотреть файл

@ -70,7 +70,7 @@ struct ssh_crypto_struct {
unsigned char *encryptMAC; unsigned char *encryptMAC;
unsigned char *decryptMAC; unsigned char *decryptMAC;
unsigned char hmacbuf[EVP_MAX_MD_SIZE]; unsigned char hmacbuf[EVP_MAX_MD_SIZE];
struct crypto_struct *in_cipher, *out_cipher; /* the cipher structures/objects */ struct ssh_cipher_struct *in_cipher, *out_cipher; /* the cipher structures/objects */
ssh_string server_pubkey; ssh_string server_pubkey;
const char *server_pubkey_type; const char *server_pubkey_type;
int do_compress_out; /* idem */ int do_compress_out; /* idem */
@ -87,7 +87,7 @@ struct ssh_crypto_struct {
enum ssh_mac_e mac_type; /* Mac operations to use for key gen */ enum ssh_mac_e mac_type; /* Mac operations to use for key gen */
}; };
struct crypto_struct { struct ssh_cipher_struct {
const char *name; /* ssh name of the algorithm */ const char *name; /* ssh name of the algorithm */
unsigned int blocksize; /* blocksize of the algo */ unsigned int blocksize; /* blocksize of the algo */
unsigned int keylen; /* length of the key structure */ unsigned int keylen; /* length of the key structure */
@ -99,11 +99,11 @@ struct crypto_struct {
#endif #endif
unsigned int keysize; /* bytes of key used. != keylen */ unsigned int keysize; /* bytes of key used. != keylen */
/* sets the new key for immediate use */ /* sets the new key for immediate use */
int (*set_encrypt_key)(struct crypto_struct *cipher, void *key, void *IV); int (*set_encrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
int (*set_decrypt_key)(struct crypto_struct *cipher, void *key, void *IV); int (*set_decrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
void (*cbc_encrypt)(struct crypto_struct *cipher, void *in, void *out, void (*cbc_encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
unsigned long len); unsigned long len);
void (*cbc_decrypt)(struct crypto_struct *cipher, void *in, void *out, void (*cbc_decrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
unsigned long len); unsigned long len);
}; };

Просмотреть файл

@ -72,7 +72,7 @@ SHA256CTX sha256_init(void);
void sha256_update(SHA256CTX c, const void *data, unsigned long len); void sha256_update(SHA256CTX c, const void *data, unsigned long len);
void sha256_final(unsigned char *md, SHA256CTX c); void sha256_final(unsigned char *md, SHA256CTX c);
struct crypto_struct *ssh_get_ciphertab(void); struct ssh_cipher_struct *ssh_get_ciphertab(void);
#endif /* HAVE_LIBCRYPTO */ #endif /* HAVE_LIBCRYPTO */

Просмотреть файл

@ -62,6 +62,6 @@ typedef gcry_mpi_t bignum;
#endif /* HAVE_LIBGCRYPT */ #endif /* HAVE_LIBGCRYPT */
struct crypto_struct *ssh_get_ciphertab(void); struct ssh_cipher_struct *ssh_get_ciphertab(void);
#endif /* LIBGCRYPT_H_ */ #endif /* LIBGCRYPT_H_ */

Просмотреть файл

@ -61,7 +61,7 @@ uint32_t packet_decrypt_len(ssh_session session, char *crypted){
} }
int packet_decrypt(ssh_session session, void *data,uint32_t len) { int packet_decrypt(ssh_session session, void *data,uint32_t len) {
struct crypto_struct *crypto = session->current_crypto->in_cipher; struct ssh_cipher_struct *crypto = session->current_crypto->in_cipher;
char *out = NULL; char *out = NULL;
if(len % session->current_crypto->in_cipher->blocksize != 0){ if(len % session->current_crypto->in_cipher->blocksize != 0){
ssh_set_error(session, SSH_FATAL, "Cryptographic functions must be set on at least one blocksize (received %d)",len); ssh_set_error(session, SSH_FATAL, "Cryptographic functions must be set on at least one blocksize (received %d)",len);
@ -90,7 +90,7 @@ int packet_decrypt(ssh_session session, void *data,uint32_t len) {
} }
unsigned char *packet_encrypt(ssh_session session, void *data, uint32_t len) { unsigned char *packet_encrypt(ssh_session session, void *data, uint32_t len) {
struct crypto_struct *crypto = NULL; struct ssh_cipher_struct *crypto = NULL;
HMACCTX ctx = NULL; HMACCTX ctx = NULL;
char *out = NULL; char *out = NULL;
unsigned int finallen; unsigned int finallen;

Просмотреть файл

@ -65,7 +65,7 @@ struct ssh_mac_ctx_struct {
} ctx; } ctx;
}; };
static int alloc_key(struct crypto_struct *cipher) { static int alloc_key(struct ssh_cipher_struct *cipher) {
cipher->key = malloc(cipher->keylen); cipher->key = malloc(cipher->keylen);
if (cipher->key == NULL) { if (cipher->key == NULL) {
return -1; return -1;
@ -234,7 +234,7 @@ void hmac_final(HMACCTX ctx, unsigned char *hashmacbuf, unsigned int *len) {
#ifdef HAS_BLOWFISH #ifdef HAS_BLOWFISH
/* the wrapper functions for blowfish */ /* the wrapper functions for blowfish */
static int blowfish_set_key(struct crypto_struct *cipher, void *key, void *IV){ static int blowfish_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV){
if (cipher->key == NULL) { if (cipher->key == NULL) {
if (alloc_key(cipher) < 0) { if (alloc_key(cipher) < 0) {
return -1; return -1;
@ -245,19 +245,19 @@ static int blowfish_set_key(struct crypto_struct *cipher, void *key, void *IV){
return 0; return 0;
} }
static void blowfish_encrypt(struct crypto_struct *cipher, void *in, static void blowfish_encrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
BF_cbc_encrypt(in, out, len, cipher->key, cipher->IV, BF_ENCRYPT); BF_cbc_encrypt(in, out, len, cipher->key, cipher->IV, BF_ENCRYPT);
} }
static void blowfish_decrypt(struct crypto_struct *cipher, void *in, static void blowfish_decrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
BF_cbc_encrypt(in, out, len, cipher->key, cipher->IV, BF_DECRYPT); BF_cbc_encrypt(in, out, len, cipher->key, cipher->IV, BF_DECRYPT);
} }
#endif /* HAS_BLOWFISH */ #endif /* HAS_BLOWFISH */
#ifdef HAS_AES #ifdef HAS_AES
static int aes_set_encrypt_key(struct crypto_struct *cipher, void *key, static int aes_set_encrypt_key(struct ssh_cipher_struct *cipher, void *key,
void *IV) { void *IV) {
if (cipher->key == NULL) { if (cipher->key == NULL) {
if (alloc_key(cipher) < 0) { if (alloc_key(cipher) < 0) {
@ -271,7 +271,7 @@ static int aes_set_encrypt_key(struct crypto_struct *cipher, void *key,
cipher->IV=IV; cipher->IV=IV;
return 0; return 0;
} }
static int aes_set_decrypt_key(struct crypto_struct *cipher, void *key, static int aes_set_decrypt_key(struct ssh_cipher_struct *cipher, void *key,
void *IV) { void *IV) {
if (cipher->key == NULL) { if (cipher->key == NULL) {
if (alloc_key(cipher) < 0) { if (alloc_key(cipher) < 0) {
@ -286,12 +286,12 @@ static int aes_set_decrypt_key(struct crypto_struct *cipher, void *key,
return 0; return 0;
} }
static void aes_encrypt(struct crypto_struct *cipher, void *in, void *out, static void aes_encrypt(struct ssh_cipher_struct *cipher, void *in, void *out,
unsigned long len) { unsigned long len) {
AES_cbc_encrypt(in, out, len, cipher->key, cipher->IV, AES_ENCRYPT); AES_cbc_encrypt(in, out, len, cipher->key, cipher->IV, AES_ENCRYPT);
} }
static void aes_decrypt(struct crypto_struct *cipher, void *in, void *out, static void aes_decrypt(struct ssh_cipher_struct *cipher, void *in, void *out,
unsigned long len) { unsigned long len) {
AES_cbc_encrypt(in, out, len, cipher->key, cipher->IV, AES_DECRYPT); AES_cbc_encrypt(in, out, len, cipher->key, cipher->IV, AES_DECRYPT);
} }
@ -306,7 +306,7 @@ static void aes_decrypt(struct crypto_struct *cipher, void *in, void *out,
* the size of the CTR counter and incidentally the blocksize, but not the keysize. * the size of the CTR counter and incidentally the blocksize, but not the keysize.
* @param len[in] must be a multiple of AES128 block size. * @param len[in] must be a multiple of AES128 block size.
*/ */
static void aes_ctr128_encrypt(struct crypto_struct *cipher, void *in, void *out, static void aes_ctr128_encrypt(struct ssh_cipher_struct *cipher, void *in, void *out,
unsigned long len) { unsigned long len) {
unsigned char tmp_buffer[128/8]; unsigned char tmp_buffer[128/8];
unsigned int num=0; unsigned int num=0;
@ -322,7 +322,7 @@ static void aes_ctr128_encrypt(struct crypto_struct *cipher, void *in, void *out
#endif /* HAS_AES */ #endif /* HAS_AES */
#ifdef HAS_DES #ifdef HAS_DES
static int des3_set_key(struct crypto_struct *cipher, void *key,void *IV) { static int des3_set_key(struct ssh_cipher_struct *cipher, void *key,void *IV) {
if (cipher->key == NULL) { if (cipher->key == NULL) {
if (alloc_key(cipher) < 0) { if (alloc_key(cipher) < 0) {
return -1; return -1;
@ -339,7 +339,7 @@ static int des3_set_key(struct crypto_struct *cipher, void *key,void *IV) {
return 0; return 0;
} }
static void des3_encrypt(struct crypto_struct *cipher, void *in, static void des3_encrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
DES_ede3_cbc_encrypt(in, out, len, cipher->key, DES_ede3_cbc_encrypt(in, out, len, cipher->key,
(void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)), (void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)),
@ -347,7 +347,7 @@ static void des3_encrypt(struct crypto_struct *cipher, void *in,
cipher->IV, 1); cipher->IV, 1);
} }
static void des3_decrypt(struct crypto_struct *cipher, void *in, static void des3_decrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
DES_ede3_cbc_encrypt(in, out, len, cipher->key, DES_ede3_cbc_encrypt(in, out, len, cipher->key,
(void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)), (void*)((uint8_t*)cipher->key + sizeof(DES_key_schedule)),
@ -355,7 +355,7 @@ static void des3_decrypt(struct crypto_struct *cipher, void *in,
cipher->IV, 0); cipher->IV, 0);
} }
static void des3_1_encrypt(struct crypto_struct *cipher, void *in, static void des3_1_encrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
#ifdef DEBUG_CRYPTO #ifdef DEBUG_CRYPTO
ssh_print_hexa("Encrypt IV before", cipher->IV, 24); ssh_print_hexa("Encrypt IV before", cipher->IV, 24);
@ -370,7 +370,7 @@ static void des3_1_encrypt(struct crypto_struct *cipher, void *in,
#endif #endif
} }
static void des3_1_decrypt(struct crypto_struct *cipher, void *in, static void des3_1_decrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
#ifdef DEBUG_CRYPTO #ifdef DEBUG_CRYPTO
ssh_print_hexa("Decrypt IV before", cipher->IV, 24); ssh_print_hexa("Decrypt IV before", cipher->IV, 24);
@ -392,10 +392,10 @@ static void des3_1_decrypt(struct crypto_struct *cipher, void *in,
/* /*
* The table of supported ciphers * The table of supported ciphers
* *
* WARNING: If you modify crypto_struct, you must make sure the order is * WARNING: If you modify ssh_cipher_struct, you must make sure the order is
* correct! * correct!
*/ */
static struct crypto_struct ssh_ciphertab[] = { static struct ssh_cipher_struct ssh_ciphertab[] = {
#ifdef HAS_BLOWFISH #ifdef HAS_BLOWFISH
{ {
"blowfish-cbc", "blowfish-cbc",
@ -527,7 +527,7 @@ static struct crypto_struct ssh_ciphertab[] = {
}; };
struct crypto_struct *ssh_get_ciphertab(void) struct ssh_cipher_struct *ssh_get_ciphertab(void)
{ {
return ssh_ciphertab; return ssh_ciphertab;
} }

Просмотреть файл

@ -36,7 +36,7 @@ struct ssh_mac_ctx_struct {
gcry_md_hd_t ctx; gcry_md_hd_t ctx;
}; };
static int alloc_key(struct crypto_struct *cipher) { static int alloc_key(struct ssh_cipher_struct *cipher) {
cipher->key = malloc(cipher->keylen); cipher->key = malloc(cipher->keylen);
if (cipher->key == NULL) { if (cipher->key == NULL) {
return -1; return -1;
@ -166,7 +166,7 @@ void hmac_final(HMACCTX c, unsigned char *hashmacbuf, unsigned int *len) {
} }
/* the wrapper functions for blowfish */ /* the wrapper functions for blowfish */
static int blowfish_set_key(struct crypto_struct *cipher, void *key, void *IV){ static int blowfish_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV){
if (cipher->key == NULL) { if (cipher->key == NULL) {
if (alloc_key(cipher) < 0) { if (alloc_key(cipher) < 0) {
return -1; return -1;
@ -190,17 +190,17 @@ static int blowfish_set_key(struct crypto_struct *cipher, void *key, void *IV){
return 0; return 0;
} }
static void blowfish_encrypt(struct crypto_struct *cipher, void *in, static void blowfish_encrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
gcry_cipher_encrypt(cipher->key[0], out, len, in, len); gcry_cipher_encrypt(cipher->key[0], out, len, in, len);
} }
static void blowfish_decrypt(struct crypto_struct *cipher, void *in, static void blowfish_decrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
gcry_cipher_decrypt(cipher->key[0], out, len, in, len); gcry_cipher_decrypt(cipher->key[0], out, len, in, len);
} }
static int aes_set_key(struct crypto_struct *cipher, void *key, void *IV) { static int aes_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV) {
int mode=GCRY_CIPHER_MODE_CBC; int mode=GCRY_CIPHER_MODE_CBC;
if (cipher->key == NULL) { if (cipher->key == NULL) {
if (alloc_key(cipher) < 0) { if (alloc_key(cipher) < 0) {
@ -252,17 +252,17 @@ static int aes_set_key(struct crypto_struct *cipher, void *key, void *IV) {
return 0; return 0;
} }
static void aes_encrypt(struct crypto_struct *cipher, void *in, void *out, static void aes_encrypt(struct ssh_cipher_struct *cipher, void *in, void *out,
unsigned long len) { unsigned long len) {
gcry_cipher_encrypt(cipher->key[0], out, len, in, len); gcry_cipher_encrypt(cipher->key[0], out, len, in, len);
} }
static void aes_decrypt(struct crypto_struct *cipher, void *in, void *out, static void aes_decrypt(struct ssh_cipher_struct *cipher, void *in, void *out,
unsigned long len) { unsigned long len) {
gcry_cipher_decrypt(cipher->key[0], out, len, in, len); gcry_cipher_decrypt(cipher->key[0], out, len, in, len);
} }
static int des3_set_key(struct crypto_struct *cipher, void *key, void *IV) { static int des3_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV) {
if (cipher->key == NULL) { if (cipher->key == NULL) {
if (alloc_key(cipher) < 0) { if (alloc_key(cipher) < 0) {
return -1; return -1;
@ -285,17 +285,17 @@ static int des3_set_key(struct crypto_struct *cipher, void *key, void *IV) {
return 0; return 0;
} }
static void des3_encrypt(struct crypto_struct *cipher, void *in, static void des3_encrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
gcry_cipher_encrypt(cipher->key[0], out, len, in, len); gcry_cipher_encrypt(cipher->key[0], out, len, in, len);
} }
static void des3_decrypt(struct crypto_struct *cipher, void *in, static void des3_decrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
gcry_cipher_decrypt(cipher->key[0], out, len, in, len); gcry_cipher_decrypt(cipher->key[0], out, len, in, len);
} }
static int des3_1_set_key(struct crypto_struct *cipher, void *key, void *IV) { static int des3_1_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV) {
if (cipher->key == NULL) { if (cipher->key == NULL) {
if (alloc_key(cipher) < 0) { if (alloc_key(cipher) < 0) {
return -1; return -1;
@ -346,14 +346,14 @@ static int des3_1_set_key(struct crypto_struct *cipher, void *key, void *IV) {
return 0; return 0;
} }
static void des3_1_encrypt(struct crypto_struct *cipher, void *in, static void des3_1_encrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
gcry_cipher_encrypt(cipher->key[0], out, len, in, len); gcry_cipher_encrypt(cipher->key[0], out, len, in, len);
gcry_cipher_decrypt(cipher->key[1], in, len, out, len); gcry_cipher_decrypt(cipher->key[1], in, len, out, len);
gcry_cipher_encrypt(cipher->key[2], out, len, in, len); gcry_cipher_encrypt(cipher->key[2], out, len, in, len);
} }
static void des3_1_decrypt(struct crypto_struct *cipher, void *in, static void des3_1_decrypt(struct ssh_cipher_struct *cipher, void *in,
void *out, unsigned long len) { void *out, unsigned long len) {
gcry_cipher_decrypt(cipher->key[2], out, len, in, len); gcry_cipher_decrypt(cipher->key[2], out, len, in, len);
gcry_cipher_encrypt(cipher->key[1], in, len, out, len); gcry_cipher_encrypt(cipher->key[1], in, len, out, len);
@ -361,7 +361,7 @@ static void des3_1_decrypt(struct crypto_struct *cipher, void *in,
} }
/* the table of supported ciphers */ /* the table of supported ciphers */
static struct crypto_struct ssh_ciphertab[] = { static struct ssh_cipher_struct ssh_ciphertab[] = {
{ {
.name = "blowfish-cbc", .name = "blowfish-cbc",
.blocksize = 8, .blocksize = 8,
@ -474,7 +474,7 @@ static struct crypto_struct ssh_ciphertab[] = {
} }
}; };
struct crypto_struct *ssh_get_ciphertab(void) struct ssh_cipher_struct *ssh_get_ciphertab(void)
{ {
return ssh_ciphertab; return ssh_ciphertab;
} }

Просмотреть файл

@ -49,10 +49,10 @@
#include "libssh/pki.h" #include "libssh/pki.h"
/* it allocates a new cipher structure based on its offset into the global table */ /* it allocates a new cipher structure based on its offset into the global table */
static struct crypto_struct *cipher_new(int offset) { static struct ssh_cipher_struct *cipher_new(int offset) {
struct crypto_struct *cipher = NULL; struct ssh_cipher_struct *cipher = NULL;
cipher = malloc(sizeof(struct crypto_struct)); cipher = malloc(sizeof(struct ssh_cipher_struct));
if (cipher == NULL) { if (cipher == NULL) {
return NULL; return NULL;
} }
@ -63,7 +63,7 @@ static struct crypto_struct *cipher_new(int offset) {
return cipher; return cipher;
} }
static void cipher_free(struct crypto_struct *cipher) { static void cipher_free(struct ssh_cipher_struct *cipher) {
#ifdef HAVE_LIBGCRYPT #ifdef HAVE_LIBGCRYPT
unsigned int i; unsigned int i;
#endif #endif
@ -164,7 +164,7 @@ static int crypt_set_algorithms2(ssh_session session){
const char *wanted; const char *wanted;
int i = 0; int i = 0;
int rc = SSH_ERROR; int rc = SSH_ERROR;
struct crypto_struct *ssh_ciphertab=ssh_get_ciphertab(); struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
enter_function(); enter_function();
/* we must scan the kex entries to find crypto algorithms and set their appropriate structure */ /* we must scan the kex entries to find crypto algorithms and set their appropriate structure */
@ -230,7 +230,7 @@ error:
static int crypt_set_algorithms1(ssh_session session) { static int crypt_set_algorithms1(ssh_session session) {
int i = 0; int i = 0;
struct crypto_struct *ssh_ciphertab=ssh_get_ciphertab(); struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
/* right now, we force 3des-cbc to be taken */ /* right now, we force 3des-cbc to be taken */
while (ssh_ciphertab[i].name && strcmp(ssh_ciphertab[i].name, while (ssh_ciphertab[i].name && strcmp(ssh_ciphertab[i].name,
@ -268,7 +268,7 @@ int crypt_set_algorithms_server(ssh_session session){
char *method = NULL; char *method = NULL;
int i = 0; int i = 0;
int rc = SSH_ERROR; int rc = SSH_ERROR;
struct crypto_struct *ssh_ciphertab=ssh_get_ciphertab(); struct ssh_cipher_struct *ssh_ciphertab=ssh_get_ciphertab();
if (session == NULL) { if (session == NULL) {
return SSH_ERROR; return SSH_ERROR;