From e67b625e43487d6aaf3dc36d4a14db57c59abd52 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Thu, 3 Jan 2019 15:14:41 -0600 Subject: [PATCH] Fix some size_t to long casts. Maybe someday we'll be able to turn on that warning. (The EVP_CIPHER hooks take size_t while the functions took long.) Change-Id: Ic4da44efca9419a7f703e232d3f92638eb4ab37a Reviewed-on: https://boringssl-review.googlesource.com/c/34084 Commit-Queue: Adam Langley Reviewed-by: Adam Langley --- decrepit/blowfish/blowfish.c | 18 ++++++++++-------- decrepit/cast/cast.c | 22 ++++++++++++---------- include/openssl/blowfish.h | 6 +++--- include/openssl/cast.h | 4 ++-- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/decrepit/blowfish/blowfish.c b/decrepit/blowfish/blowfish.c index 120e365d..186f4861 100644 --- a/decrepit/blowfish/blowfish.c +++ b/decrepit/blowfish/blowfish.c @@ -152,18 +152,18 @@ void BF_ecb_encrypt(const uint8_t *in, uint8_t *out, l2n(d[1], out); } -void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, +void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length, const BF_KEY *schedule, uint8_t *ivec, int encrypt) { uint32_t tin0, tin1; uint32_t tout0, tout1, xor0, xor1; - long l = length; + size_t l = length; uint32_t tin[2]; if (encrypt) { n2l(ivec, tout0); n2l(ivec, tout1); ivec -= 8; - for (l -= 8; l >= 0; l -= 8) { + while (l >= 8) { n2l(in, tin0); n2l(in, tin1); tin0 ^= tout0; @@ -175,9 +175,10 @@ void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, tout1 = tin[1]; l2n(tout0, out); l2n(tout1, out); + l -= 8; } - if (l != -8) { - n2ln(in, tin0, tin1, l + 8); + if (l != 0) { + n2ln(in, tin0, tin1, l); tin0 ^= tout0; tin1 ^= tout1; tin[0] = tin0; @@ -194,7 +195,7 @@ void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, n2l(ivec, xor0); n2l(ivec, xor1); ivec -= 8; - for (l -= 8; l >= 0; l -= 8) { + while (l >= 8) { n2l(in, tin0); n2l(in, tin1); tin[0] = tin0; @@ -206,8 +207,9 @@ void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, l2n(tout1, out); xor0 = tin0; xor1 = tin1; + l -= 8; } - if (l != -8) { + if (l != 0) { n2l(in, tin0); n2l(in, tin1); tin[0] = tin0; @@ -215,7 +217,7 @@ void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, BF_decrypt(tin, schedule); tout0 = tin[0] ^ xor0; tout1 = tin[1] ^ xor1; - l2nn(tout0, tout1, out, l + 8); + l2nn(tout0, tout1, out, l); xor0 = tin0; xor1 = tin1; } diff --git a/decrepit/cast/cast.c b/decrepit/cast/cast.c index 0eb815d6..bc372030 100644 --- a/decrepit/cast/cast.c +++ b/decrepit/cast/cast.c @@ -166,18 +166,18 @@ void CAST_decrypt(uint32_t *data, const CAST_KEY *key) { data[0] = r & 0xffffffffL; } -void CAST_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, +void CAST_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length, const CAST_KEY *ks, uint8_t *iv, int enc) { uint32_t tin0, tin1; uint32_t tout0, tout1, xor0, xor1; - long l = length; + size_t l = length; uint32_t tin[2]; if (enc) { n2l(iv, tout0); n2l(iv, tout1); iv -= 8; - for (l -= 8; l >= 0; l -= 8) { + while (l >= 8) { n2l(in, tin0); n2l(in, tin1); tin0 ^= tout0; @@ -189,9 +189,10 @@ void CAST_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, tout1 = tin[1]; l2n(tout0, out); l2n(tout1, out); + l -= 8; } - if (l != -8) { - n2ln(in, tin0, tin1, l + 8); + if (l != 0) { + n2ln(in, tin0, tin1, l); tin0 ^= tout0; tin1 ^= tout1; tin[0] = tin0; @@ -208,7 +209,7 @@ void CAST_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, n2l(iv, xor0); n2l(iv, xor1); iv -= 8; - for (l -= 8; l >= 0; l -= 8) { + while (l >= 8) { n2l(in, tin0); n2l(in, tin1); tin[0] = tin0; @@ -220,8 +221,9 @@ void CAST_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, l2n(tout1, out); xor0 = tin0; xor1 = tin1; + l -= 8; } - if (l != -8) { + if (l != 0) { n2l(in, tin0); n2l(in, tin1); tin[0] = tin0; @@ -229,7 +231,7 @@ void CAST_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, CAST_decrypt(tin, ks); tout0 = tin[0] ^ xor0; tout1 = tin[1] ^ xor1; - l2nn(tout0, tout1, out, l + 8); + l2nn(tout0, tout1, out, l); xor0 = tin0; xor1 = tin1; } @@ -354,12 +356,12 @@ void CAST_set_key(CAST_KEY *key, size_t len, const uint8_t *data) { // The input and output encrypted as though 64bit cfb mode is being used. The // extra state information to record how much of the 64bit block we have used // is contained in *num. -void CAST_cfb64_encrypt(const uint8_t *in, uint8_t *out, long length, +void CAST_cfb64_encrypt(const uint8_t *in, uint8_t *out, size_t length, const CAST_KEY *schedule, uint8_t *ivec, int *num, int enc) { uint32_t v0, v1, t; int n = *num; - long l = length; + size_t l = length; uint32_t ti[2]; uint8_t *iv, c, cc; diff --git a/include/openssl/blowfish.h b/include/openssl/blowfish.h index ecf9d456..293b1755 100644 --- a/include/openssl/blowfish.h +++ b/include/openssl/blowfish.h @@ -81,9 +81,9 @@ OPENSSL_EXPORT void BF_decrypt(uint32_t *data, const BF_KEY *key); OPENSSL_EXPORT void BF_ecb_encrypt(const uint8_t *in, uint8_t *out, const BF_KEY *key, int enc); -OPENSSL_EXPORT void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, - const BF_KEY *schedule, uint8_t *ivec, - int enc); +OPENSSL_EXPORT void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, + size_t length, const BF_KEY *schedule, + uint8_t *ivec, int enc); #ifdef __cplusplus diff --git a/include/openssl/cast.h b/include/openssl/cast.h index 2978a67e..1a0f82dd 100644 --- a/include/openssl/cast.h +++ b/include/openssl/cast.h @@ -82,11 +82,11 @@ OPENSSL_EXPORT void CAST_ecb_encrypt(const uint8_t *in, uint8_t *out, OPENSSL_EXPORT void CAST_encrypt(uint32_t *data, const CAST_KEY *key); OPENSSL_EXPORT void CAST_decrypt(uint32_t *data, const CAST_KEY *key); OPENSSL_EXPORT void CAST_cbc_encrypt(const uint8_t *in, uint8_t *out, - long length, const CAST_KEY *ks, + size_t length, const CAST_KEY *ks, uint8_t *iv, int enc); OPENSSL_EXPORT void CAST_cfb64_encrypt(const uint8_t *in, uint8_t *out, - long length, const CAST_KEY *schedule, + size_t length, const CAST_KEY *schedule, uint8_t *ivec, int *num, int enc); #ifdef __cplusplus