mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 18:50:28 +09:00
Improve packet_decrypt().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@479 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -55,24 +55,30 @@ u32 packet_decrypt_len(SSH_SESSION *session, char *crypted){
|
|||||||
return ntohl(decrypted);
|
return ntohl(decrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
int packet_decrypt(SSH_SESSION *session, void *data,u32 len){
|
int packet_decrypt(SSH_SESSION *session, void *data,u32 len) {
|
||||||
struct crypto_struct *crypto=session->current_crypto->in_cipher;
|
struct crypto_struct *crypto = session->current_crypto->in_cipher;
|
||||||
char *out=malloc(len);
|
char *out = NULL;
|
||||||
if (out == NULL) {
|
|
||||||
return -1;
|
out = malloc(len);
|
||||||
}
|
if (out == NULL) {
|
||||||
ssh_log(session,SSH_LOG_PACKET,"Decrypting %d bytes",len);
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssh_log(session,SSH_LOG_PACKET, "Decrypting %d bytes", len);
|
||||||
|
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
crypto->set_decrypt_key(crypto,session->current_crypto->decryptkey,session->current_crypto->decryptIV);
|
crypto->set_decrypt_key(crypto,session->current_crypto->decryptkey,session->current_crypto->decryptIV);
|
||||||
crypto->cbc_decrypt(crypto,data,out,len);
|
crypto->cbc_decrypt(crypto,data,out,len);
|
||||||
#elif defined HAVE_LIBCRYPTO
|
#elif defined HAVE_LIBCRYPTO
|
||||||
crypto->set_decrypt_key(crypto,session->current_crypto->decryptkey);
|
crypto->set_decrypt_key(crypto,session->current_crypto->decryptkey);
|
||||||
crypto->cbc_decrypt(crypto,data,out,len,session->current_crypto->decryptIV);
|
crypto->cbc_decrypt(crypto,data,out,len,session->current_crypto->decryptIV);
|
||||||
#endif
|
#endif
|
||||||
memcpy(data,out,len);
|
|
||||||
memset(out,0,len);
|
memcpy(data,out,len);
|
||||||
free(out);
|
memset(out,0,len);
|
||||||
return 0;
|
|
||||||
|
SAFE_FREE(out);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char * packet_encrypt(SSH_SESSION *session,void *data,u32 len){
|
unsigned char * packet_encrypt(SSH_SESSION *session,void *data,u32 len){
|
||||||
|
|||||||
Reference in New Issue
Block a user