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 <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/decrepit/blowfish/blowfish.c b/decrepit/blowfish/blowfish.c
index 120e365..186f486 100644
--- a/decrepit/blowfish/blowfish.c
+++ b/decrepit/blowfish/blowfish.c
@@ -152,18 +152,18 @@
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 @@
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 @@
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 @@
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 @@
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 0eb815d..bc37203 100644
--- a/decrepit/cast/cast.c
+++ b/decrepit/cast/cast.c
@@ -166,18 +166,18 @@
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 @@
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 @@
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 @@
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 @@
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 @@
// 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 ecf9d45..293b175 100644
--- a/include/openssl/blowfish.h
+++ b/include/openssl/blowfish.h
@@ -81,9 +81,9 @@
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 2978a67..1a0f82d 100644
--- a/include/openssl/cast.h
+++ b/include/openssl/cast.h
@@ -82,11 +82,11 @@
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