Fix indentation.
This commit is contained in:
parent
91e496ff41
commit
75b5e06773
64
src/crypt.c
64
src/crypt.c
@ -61,21 +61,22 @@ static LIBSSH2_CRYPT_METHOD libssh2_crypt_method_none = {
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAKE_INIT(name, cipher) \
|
#define MAKE_INIT(name, cipher) \
|
||||||
static int name (LIBSSH2_SESSION *session, \
|
static int name (LIBSSH2_SESSION *session, \
|
||||||
unsigned char *iv, int *free_iv, \
|
unsigned char *iv, int *free_iv, \
|
||||||
unsigned char *secret, int *free_secret, \
|
unsigned char *secret, int *free_secret, \
|
||||||
int encrypt, void **abstract) \
|
int encrypt, void **abstract) \
|
||||||
{ \
|
{ \
|
||||||
EVP_CIPHER_CTX *ctx = LIBSSH2_ALLOC(session, sizeof(EVP_CIPHER_CTX)); \
|
EVP_CIPHER_CTX *ctx = LIBSSH2_ALLOC(session, sizeof(EVP_CIPHER_CTX)); \
|
||||||
if (!ctx) \
|
if (!ctx) { \
|
||||||
return -1; \
|
return -1; \
|
||||||
EVP_CIPHER_CTX_init(ctx); \
|
} \
|
||||||
EVP_CipherInit(ctx, cipher, secret, iv, encrypt); \
|
EVP_CIPHER_CTX_init(ctx); \
|
||||||
*abstract = ctx; \
|
EVP_CipherInit(ctx, cipher, secret, iv, encrypt); \
|
||||||
*free_iv = 1; \
|
*abstract = ctx; \
|
||||||
*free_secret = 1; \
|
*free_iv = 1; \
|
||||||
return 0; \
|
*free_secret = 1; \
|
||||||
|
return 0; \
|
||||||
}
|
}
|
||||||
|
|
||||||
MAKE_INIT(aes256_init, EVP_aes_256_cbc())
|
MAKE_INIT(aes256_init, EVP_aes_256_cbc())
|
||||||
@ -88,27 +89,30 @@ MAKE_INIT(des3_init, EVP_des_ede3_cbc())
|
|||||||
|
|
||||||
int crypt(LIBSSH2_SESSION *session, unsigned char *block, void **abstract)
|
int crypt(LIBSSH2_SESSION *session, unsigned char *block, void **abstract)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX *ctx = *(EVP_CIPHER_CTX **)abstract;
|
EVP_CIPHER_CTX *ctx = *(EVP_CIPHER_CTX **)abstract;
|
||||||
int blocksize = ctx->cipher->block_size;
|
int blocksize = ctx->cipher->block_size;
|
||||||
unsigned char buf[EVP_MAX_BLOCK_LENGTH];
|
unsigned char buf[EVP_MAX_BLOCK_LENGTH];
|
||||||
int ret;
|
int ret;
|
||||||
if (blocksize == 1) /* Hack for arcfour. */
|
|
||||||
blocksize = 8;
|
if (blocksize == 1) {
|
||||||
ret = EVP_Cipher(ctx, buf, block, blocksize);
|
/* Hack for arcfour. */
|
||||||
if (ret == 1)
|
blocksize = 8;
|
||||||
memcpy(block, buf, blocksize);
|
}
|
||||||
return ret == 1 ? 0 : 1;
|
ret = EVP_Cipher(ctx, buf, block, blocksize);
|
||||||
|
if (ret == 1) {
|
||||||
|
memcpy(block, buf, blocksize);
|
||||||
|
}
|
||||||
|
return ret == 1 ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dtor(LIBSSH2_SESSION *session, void **abstract)
|
int dtor(LIBSSH2_SESSION *session, void **abstract)
|
||||||
{
|
{
|
||||||
EVP_CIPHER_CTX **ctx = (EVP_CIPHER_CTX **)abstract;
|
EVP_CIPHER_CTX **ctx = (EVP_CIPHER_CTX **)abstract;
|
||||||
if (ctx && *ctx)
|
if (ctx && *ctx) {
|
||||||
{
|
EVP_CIPHER_CTX_cleanup(*ctx);
|
||||||
EVP_CIPHER_CTX_cleanup(*ctx);
|
LIBSSH2_FREE(session, *ctx);
|
||||||
LIBSSH2_FREE(session, *ctx);
|
*abstract = NULL;
|
||||||
*abstract = NULL;
|
}
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ static int libssh2_kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_S
|
|||||||
|
|
||||||
/* Cleanup any existing cipher */
|
/* Cleanup any existing cipher */
|
||||||
if (session->local.crypt->dtor) {
|
if (session->local.crypt->dtor) {
|
||||||
session->local.crypt->dtor(session, &session->local.crypt_abstract);
|
session->local.crypt->dtor(session, &session->local.crypt_abstract);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate IV/Secret/Key for each direction */
|
/* Calculate IV/Secret/Key for each direction */
|
||||||
@ -364,8 +364,8 @@ static int libssh2_kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_S
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (session->remote.crypt->dtor) {
|
if (session->remote.crypt->dtor) {
|
||||||
/* Cleanup any existing cipher */
|
/* Cleanup any existing cipher */
|
||||||
session->remote.crypt->dtor(session, &session->remote.crypt_abstract);
|
session->remote.crypt->dtor(session, &session->remote.crypt_abstract);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session->remote.crypt->init) {
|
if (session->remote.crypt->init) {
|
||||||
|
12
src/packet.c
12
src/packet.c
@ -777,8 +777,8 @@ int libssh2_packet_read(LIBSSH2_SESSION *session, int should_block)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (session->remote.crypt->crypt(session, block, &session->remote.crypt_abstract)) {
|
if (session->remote.crypt->crypt(session, block, &session->remote.crypt_abstract)) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_DECRYPT, "Error decrypting packet preamble", 0);
|
libssh2_error(session, LIBSSH2_ERROR_DECRYPT, "Error decrypting packet preamble", 0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
packet_len = libssh2_ntohu32(block);
|
packet_len = libssh2_ntohu32(block);
|
||||||
@ -830,9 +830,9 @@ int libssh2_packet_read(LIBSSH2_SESSION *session, int should_block)
|
|||||||
memcpy(block, s, blocksize);
|
memcpy(block, s, blocksize);
|
||||||
|
|
||||||
if (session->remote.crypt->crypt(session, block, &session->remote.crypt_abstract)) {
|
if (session->remote.crypt->crypt(session, block, &session->remote.crypt_abstract)) {
|
||||||
libssh2_error(session, LIBSSH2_ERROR_DECRYPT, "Error decrypting packet preamble", 0);
|
libssh2_error(session, LIBSSH2_ERROR_DECRYPT, "Error decrypting packet preamble", 0);
|
||||||
LIBSSH2_FREE(session, payload);
|
LIBSSH2_FREE(session, payload);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(s, block, blocksize);
|
memcpy(s, block, blocksize);
|
||||||
|
|
||||||
@ -1234,7 +1234,7 @@ int libssh2_packet_write(LIBSSH2_SESSION *session, unsigned char *data, unsigned
|
|||||||
|
|
||||||
/* Encrypt data */
|
/* Encrypt data */
|
||||||
for(s = encbuf; (s - encbuf) < (4 + packet_length) ; s += session->local.crypt->blocksize) {
|
for(s = encbuf; (s - encbuf) < (4 + packet_length) ; s += session->local.crypt->blocksize) {
|
||||||
session->local.crypt->crypt(session, s, &session->local.crypt_abstract);
|
session->local.crypt->crypt(session, s, &session->local.crypt_abstract);
|
||||||
}
|
}
|
||||||
|
|
||||||
session->local.seqno++;
|
session->local.seqno++;
|
||||||
|
@ -411,7 +411,7 @@ LIBSSH2_API void libssh2_session_free(LIBSSH2_SESSION *session)
|
|||||||
/* Client to Server */
|
/* Client to Server */
|
||||||
/* crypt */
|
/* crypt */
|
||||||
if (session->local.crypt && session->local.crypt->dtor) {
|
if (session->local.crypt && session->local.crypt->dtor) {
|
||||||
session->local.crypt->dtor(session, &session->local.crypt_abstract);
|
session->local.crypt->dtor(session, &session->local.crypt_abstract);
|
||||||
}
|
}
|
||||||
/* comp */
|
/* comp */
|
||||||
if (session->local.comp && session->local.comp->dtor) {
|
if (session->local.comp && session->local.comp->dtor) {
|
||||||
@ -425,7 +425,7 @@ LIBSSH2_API void libssh2_session_free(LIBSSH2_SESSION *session)
|
|||||||
/* Server to Client */
|
/* Server to Client */
|
||||||
/* crypt */
|
/* crypt */
|
||||||
if (session->remote.crypt && session->remote.crypt->dtor) {
|
if (session->remote.crypt && session->remote.crypt->dtor) {
|
||||||
session->remote.crypt->dtor(session, &session->remote.crypt_abstract);
|
session->remote.crypt->dtor(session, &session->remote.crypt_abstract);
|
||||||
}
|
}
|
||||||
/* comp */
|
/* comp */
|
||||||
if (session->remote.comp && session->remote.comp->dtor) {
|
if (session->remote.comp && session->remote.comp->dtor) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user