aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-11-30 17:23:37 +0100
committerAndreas Schneider <asn@cryptomilk.org>2018-11-30 18:25:12 +0100
commitc6ca62d7e166271a8470fa7e327b03845a0c1f3f (patch)
tree590dab12dca4f6976d37f0c384d6ff85e65677c5 /src
parent6d3672911bcd5fbe85967f8e16ac29aca53d6549 (diff)
downloadlibssh-c6ca62d7e166271a8470fa7e327b03845a0c1f3f.tar.gz
libssh-c6ca62d7e166271a8470fa7e327b03845a0c1f3f.tar.xz
libssh-c6ca62d7e166271a8470fa7e327b03845a0c1f3f.zip
crypto: Use size_t for len argument in encrypt and decrpyt fn
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r--src/libcrypto.c38
-rw-r--r--src/libgcrypt.c18
-rw-r--r--src/libmbedcrypto.c12
3 files changed, 44 insertions, 24 deletions
diff --git a/src/libcrypto.c b/src/libcrypto.c
index d1f93978..fb77c89f 100644
--- a/src/libcrypto.c
+++ b/src/libcrypto.c
@@ -596,20 +596,25 @@ static int evp_cipher_set_decrypt_key(struct ssh_cipher_struct *cipher,
/* EVP wrapper function for encrypt/decrypt */
static void evp_cipher_encrypt(struct ssh_cipher_struct *cipher,
- void *in,
- void *out,
- unsigned long len) {
+ void *in,
+ void *out,
+ size_t len)
+{
int outlen = 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){
SSH_LOG(SSH_LOG_WARNING, "EVP_EncryptUpdate failed");
return;
}
if (outlen != (int)len){
SSH_LOG(SSH_LOG_WARNING,
- "EVP_EncryptUpdate: output size %d for %lu in",
+ "EVP_EncryptUpdate: output size %d for %zu in",
outlen,
len);
return;
@@ -617,20 +622,25 @@ static void evp_cipher_encrypt(struct ssh_cipher_struct *cipher,
}
static void evp_cipher_decrypt(struct ssh_cipher_struct *cipher,
- void *in,
- void *out,
- unsigned long len) {
+ void *in,
+ void *out,
+ size_t len)
+{
int outlen = 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){
SSH_LOG(SSH_LOG_WARNING, "EVP_DecryptUpdate failed");
return;
}
if (outlen != (int)len){
SSH_LOG(SSH_LOG_WARNING,
- "EVP_DecryptUpdate: output size %d for %lu in",
+ "EVP_DecryptUpdate: output size %d for %zu in",
outlen,
len);
return;
@@ -747,8 +757,8 @@ evp_cipher_aead_encrypt(struct ssh_cipher_struct *cipher,
NULL,
&outlen,
(unsigned char *)in,
- aadlen);
- if (rc == 0 || outlen != aadlen) {
+ (int)aadlen);
+ if (rc == 0 || outlen != (int)aadlen) {
SSH_LOG(SSH_LOG_WARNING, "Failed to pass authenticated data");
return;
}
@@ -759,7 +769,7 @@ evp_cipher_aead_encrypt(struct ssh_cipher_struct *cipher,
(unsigned char *)out + aadlen,
&outlen,
(unsigned char *)in + aadlen,
- len - aadlen);
+ (int)len - aadlen);
if (rc != 1 || outlen != len - aadlen) {
SSH_LOG(SSH_LOG_WARNING, "EVP_EncryptUpdate failed");
return;
@@ -826,7 +836,7 @@ evp_cipher_aead_decrypt(struct ssh_cipher_struct *cipher,
NULL,
&outlen,
(unsigned char *)complete_packet,
- aadlen);
+ (int)aadlen);
if (rc == 0) {
SSH_LOG(SSH_LOG_WARNING, "Failed to pass authenticated data");
return SSH_ERROR;
diff --git a/src/libgcrypt.c b/src/libgcrypt.c
index 3201434b..c7c80f03 100644
--- a/src/libgcrypt.c
+++ b/src/libgcrypt.c
@@ -405,14 +405,20 @@ static int aes_set_key(struct ssh_cipher_struct *cipher, void *key, void *IV) {
return 0;
}
-static void aes_encrypt(struct ssh_cipher_struct *cipher, void *in, void *out,
- unsigned long len) {
- gcry_cipher_encrypt(cipher->key[0], out, len, in, len);
+static void aes_encrypt(struct ssh_cipher_struct *cipher,
+ void *in,
+ void *out,
+ size_t len)
+{
+ gcry_cipher_encrypt(cipher->key[0], out, len, in, len);
}
-static void aes_decrypt(struct ssh_cipher_struct *cipher, void *in, void *out,
- unsigned long len) {
- gcry_cipher_decrypt(cipher->key[0], out, len, in, len);
+static void aes_decrypt(struct ssh_cipher_struct *cipher,
+ void *in,
+ void *out,
+ size_t len)
+{
+ gcry_cipher_decrypt(cipher->key[0], out, len, in, len);
}
static int
diff --git a/src/libmbedcrypto.c b/src/libmbedcrypto.c
index d8799eef..4b814598 100644
--- a/src/libmbedcrypto.c
+++ b/src/libmbedcrypto.c
@@ -708,8 +708,10 @@ error:
return SSH_ERROR;
}
-static void cipher_encrypt(struct ssh_cipher_struct *cipher, void *in, void *out,
- unsigned long len)
+static void cipher_encrypt(struct ssh_cipher_struct *cipher,
+ void *in,
+ void *out,
+ size_t len)
{
size_t outlen = 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,
- unsigned long len)
+static void cipher_decrypt(struct ssh_cipher_struct *cipher,
+ void *in,
+ void *out,
+ size_t len)
{
size_t outlen = 0;
int rc = 0;