mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-30 13:01:23 +03:00
crypto: Use size_t for len argument in encrypt and decrpyt fn
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
@@ -165,10 +165,14 @@ struct ssh_cipher_struct {
|
|||||||
/* sets the new key for immediate use */
|
/* sets the new key for immediate use */
|
||||||
int (*set_encrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
|
int (*set_encrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
|
||||||
int (*set_decrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
|
int (*set_decrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
|
||||||
void (*encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
|
void (*encrypt)(struct ssh_cipher_struct *cipher,
|
||||||
unsigned long len);
|
void *in,
|
||||||
void (*decrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
|
void *out,
|
||||||
unsigned long len);
|
size_t len);
|
||||||
|
void (*decrypt)(struct ssh_cipher_struct *cipher,
|
||||||
|
void *in,
|
||||||
|
void *out,
|
||||||
|
size_t len);
|
||||||
void (*aead_encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
|
void (*aead_encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
|
||||||
size_t len, uint8_t *mac, uint64_t seq);
|
size_t len, uint8_t *mac, uint64_t seq);
|
||||||
int (*aead_decrypt_length)(struct ssh_cipher_struct *cipher, void *in,
|
int (*aead_decrypt_length)(struct ssh_cipher_struct *cipher, void *in,
|
||||||
|
|||||||
@@ -598,18 +598,23 @@ static int evp_cipher_set_decrypt_key(struct ssh_cipher_struct *cipher,
|
|||||||
static void evp_cipher_encrypt(struct ssh_cipher_struct *cipher,
|
static void evp_cipher_encrypt(struct ssh_cipher_struct *cipher,
|
||||||
void *in,
|
void *in,
|
||||||
void *out,
|
void *out,
|
||||||
unsigned long len) {
|
size_t len)
|
||||||
|
{
|
||||||
int outlen = 0;
|
int outlen = 0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
rc = EVP_EncryptUpdate(cipher->ctx, (unsigned char *)out, &outlen, (unsigned char *)in, len);
|
rc = EVP_EncryptUpdate(cipher->ctx,
|
||||||
|
(unsigned char *)out,
|
||||||
|
&outlen,
|
||||||
|
(unsigned char *)in,
|
||||||
|
(int)len);
|
||||||
if (rc != 1){
|
if (rc != 1){
|
||||||
SSH_LOG(SSH_LOG_WARNING, "EVP_EncryptUpdate failed");
|
SSH_LOG(SSH_LOG_WARNING, "EVP_EncryptUpdate failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (outlen != (int)len){
|
if (outlen != (int)len){
|
||||||
SSH_LOG(SSH_LOG_WARNING,
|
SSH_LOG(SSH_LOG_WARNING,
|
||||||
"EVP_EncryptUpdate: output size %d for %lu in",
|
"EVP_EncryptUpdate: output size %d for %zu in",
|
||||||
outlen,
|
outlen,
|
||||||
len);
|
len);
|
||||||
return;
|
return;
|
||||||
@@ -619,18 +624,23 @@ static void evp_cipher_encrypt(struct ssh_cipher_struct *cipher,
|
|||||||
static void evp_cipher_decrypt(struct ssh_cipher_struct *cipher,
|
static void evp_cipher_decrypt(struct ssh_cipher_struct *cipher,
|
||||||
void *in,
|
void *in,
|
||||||
void *out,
|
void *out,
|
||||||
unsigned long len) {
|
size_t len)
|
||||||
|
{
|
||||||
int outlen = 0;
|
int outlen = 0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
rc = EVP_DecryptUpdate(cipher->ctx, (unsigned char *)out, &outlen, (unsigned char *)in, len);
|
rc = EVP_DecryptUpdate(cipher->ctx,
|
||||||
|
(unsigned char *)out,
|
||||||
|
&outlen,
|
||||||
|
(unsigned char *)in,
|
||||||
|
(int)len);
|
||||||
if (rc != 1){
|
if (rc != 1){
|
||||||
SSH_LOG(SSH_LOG_WARNING, "EVP_DecryptUpdate failed");
|
SSH_LOG(SSH_LOG_WARNING, "EVP_DecryptUpdate failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (outlen != (int)len){
|
if (outlen != (int)len){
|
||||||
SSH_LOG(SSH_LOG_WARNING,
|
SSH_LOG(SSH_LOG_WARNING,
|
||||||
"EVP_DecryptUpdate: output size %d for %lu in",
|
"EVP_DecryptUpdate: output size %d for %zu in",
|
||||||
outlen,
|
outlen,
|
||||||
len);
|
len);
|
||||||
return;
|
return;
|
||||||
@@ -747,8 +757,8 @@ evp_cipher_aead_encrypt(struct ssh_cipher_struct *cipher,
|
|||||||
NULL,
|
NULL,
|
||||||
&outlen,
|
&outlen,
|
||||||
(unsigned char *)in,
|
(unsigned char *)in,
|
||||||
aadlen);
|
(int)aadlen);
|
||||||
if (rc == 0 || outlen != aadlen) {
|
if (rc == 0 || outlen != (int)aadlen) {
|
||||||
SSH_LOG(SSH_LOG_WARNING, "Failed to pass authenticated data");
|
SSH_LOG(SSH_LOG_WARNING, "Failed to pass authenticated data");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -759,7 +769,7 @@ evp_cipher_aead_encrypt(struct ssh_cipher_struct *cipher,
|
|||||||
(unsigned char *)out + aadlen,
|
(unsigned char *)out + aadlen,
|
||||||
&outlen,
|
&outlen,
|
||||||
(unsigned char *)in + aadlen,
|
(unsigned char *)in + aadlen,
|
||||||
len - aadlen);
|
(int)len - aadlen);
|
||||||
if (rc != 1 || outlen != len - aadlen) {
|
if (rc != 1 || outlen != len - aadlen) {
|
||||||
SSH_LOG(SSH_LOG_WARNING, "EVP_EncryptUpdate failed");
|
SSH_LOG(SSH_LOG_WARNING, "EVP_EncryptUpdate failed");
|
||||||
return;
|
return;
|
||||||
@@ -826,7 +836,7 @@ evp_cipher_aead_decrypt(struct ssh_cipher_struct *cipher,
|
|||||||
NULL,
|
NULL,
|
||||||
&outlen,
|
&outlen,
|
||||||
(unsigned char *)complete_packet,
|
(unsigned char *)complete_packet,
|
||||||
aadlen);
|
(int)aadlen);
|
||||||
if (rc == 0) {
|
if (rc == 0) {
|
||||||
SSH_LOG(SSH_LOG_WARNING, "Failed to pass authenticated data");
|
SSH_LOG(SSH_LOG_WARNING, "Failed to pass authenticated data");
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
|
|||||||
@@ -405,13 +405,19 @@ static int aes_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void aes_encrypt(struct ssh_cipher_struct *cipher, void *in, void *out,
|
static void aes_encrypt(struct ssh_cipher_struct *cipher,
|
||||||
unsigned long len) {
|
void *in,
|
||||||
|
void *out,
|
||||||
|
size_t 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 ssh_cipher_struct *cipher, void *in, void *out,
|
static void aes_decrypt(struct ssh_cipher_struct *cipher,
|
||||||
unsigned long len) {
|
void *in,
|
||||||
|
void *out,
|
||||||
|
size_t len)
|
||||||
|
{
|
||||||
gcry_cipher_decrypt(cipher->key[0], out, len, in, len);
|
gcry_cipher_decrypt(cipher->key[0], out, len, in, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -708,8 +708,10 @@ error:
|
|||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cipher_encrypt(struct ssh_cipher_struct *cipher, void *in, void *out,
|
static void cipher_encrypt(struct ssh_cipher_struct *cipher,
|
||||||
unsigned long len)
|
void *in,
|
||||||
|
void *out,
|
||||||
|
size_t len)
|
||||||
{
|
{
|
||||||
size_t outlen = 0;
|
size_t outlen = 0;
|
||||||
size_t total_len = 0;
|
size_t total_len = 0;
|
||||||
@@ -763,8 +765,10 @@ static void cipher_encrypt_cbc(struct ssh_cipher_struct *cipher, void *in, void
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cipher_decrypt(struct ssh_cipher_struct *cipher, void *in, void *out,
|
static void cipher_decrypt(struct ssh_cipher_struct *cipher,
|
||||||
unsigned long len)
|
void *in,
|
||||||
|
void *out,
|
||||||
|
size_t len)
|
||||||
{
|
{
|
||||||
size_t outlen = 0;
|
size_t outlen = 0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user