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>kris/onging/CECPQ3_patch15
@@ -152,18 +152,18 @@ void BF_ecb_encrypt(const uint8_t *in, uint8_t *out, | |||||
l2n(d[1], 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) { | const BF_KEY *schedule, uint8_t *ivec, int encrypt) { | ||||
uint32_t tin0, tin1; | uint32_t tin0, tin1; | ||||
uint32_t tout0, tout1, xor0, xor1; | uint32_t tout0, tout1, xor0, xor1; | ||||
long l = length; | |||||
size_t l = length; | |||||
uint32_t tin[2]; | uint32_t tin[2]; | ||||
if (encrypt) { | if (encrypt) { | ||||
n2l(ivec, tout0); | n2l(ivec, tout0); | ||||
n2l(ivec, tout1); | n2l(ivec, tout1); | ||||
ivec -= 8; | ivec -= 8; | ||||
for (l -= 8; l >= 0; l -= 8) { | |||||
while (l >= 8) { | |||||
n2l(in, tin0); | n2l(in, tin0); | ||||
n2l(in, tin1); | n2l(in, tin1); | ||||
tin0 ^= tout0; | tin0 ^= tout0; | ||||
@@ -175,9 +175,10 @@ void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, | |||||
tout1 = tin[1]; | tout1 = tin[1]; | ||||
l2n(tout0, out); | l2n(tout0, out); | ||||
l2n(tout1, 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; | tin0 ^= tout0; | ||||
tin1 ^= tout1; | tin1 ^= tout1; | ||||
tin[0] = tin0; | 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, xor0); | ||||
n2l(ivec, xor1); | n2l(ivec, xor1); | ||||
ivec -= 8; | ivec -= 8; | ||||
for (l -= 8; l >= 0; l -= 8) { | |||||
while (l >= 8) { | |||||
n2l(in, tin0); | n2l(in, tin0); | ||||
n2l(in, tin1); | n2l(in, tin1); | ||||
tin[0] = tin0; | tin[0] = tin0; | ||||
@@ -206,8 +207,9 @@ void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, | |||||
l2n(tout1, out); | l2n(tout1, out); | ||||
xor0 = tin0; | xor0 = tin0; | ||||
xor1 = tin1; | xor1 = tin1; | ||||
l -= 8; | |||||
} | } | ||||
if (l != -8) { | |||||
if (l != 0) { | |||||
n2l(in, tin0); | n2l(in, tin0); | ||||
n2l(in, tin1); | n2l(in, tin1); | ||||
tin[0] = tin0; | tin[0] = tin0; | ||||
@@ -215,7 +217,7 @@ void BF_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, | |||||
BF_decrypt(tin, schedule); | BF_decrypt(tin, schedule); | ||||
tout0 = tin[0] ^ xor0; | tout0 = tin[0] ^ xor0; | ||||
tout1 = tin[1] ^ xor1; | tout1 = tin[1] ^ xor1; | ||||
l2nn(tout0, tout1, out, l + 8); | |||||
l2nn(tout0, tout1, out, l); | |||||
xor0 = tin0; | xor0 = tin0; | ||||
xor1 = tin1; | xor1 = tin1; | ||||
} | } | ||||
@@ -166,18 +166,18 @@ void CAST_decrypt(uint32_t *data, const CAST_KEY *key) { | |||||
data[0] = r & 0xffffffffL; | 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) { | const CAST_KEY *ks, uint8_t *iv, int enc) { | ||||
uint32_t tin0, tin1; | uint32_t tin0, tin1; | ||||
uint32_t tout0, tout1, xor0, xor1; | uint32_t tout0, tout1, xor0, xor1; | ||||
long l = length; | |||||
size_t l = length; | |||||
uint32_t tin[2]; | uint32_t tin[2]; | ||||
if (enc) { | if (enc) { | ||||
n2l(iv, tout0); | n2l(iv, tout0); | ||||
n2l(iv, tout1); | n2l(iv, tout1); | ||||
iv -= 8; | iv -= 8; | ||||
for (l -= 8; l >= 0; l -= 8) { | |||||
while (l >= 8) { | |||||
n2l(in, tin0); | n2l(in, tin0); | ||||
n2l(in, tin1); | n2l(in, tin1); | ||||
tin0 ^= tout0; | tin0 ^= tout0; | ||||
@@ -189,9 +189,10 @@ void CAST_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, | |||||
tout1 = tin[1]; | tout1 = tin[1]; | ||||
l2n(tout0, out); | l2n(tout0, out); | ||||
l2n(tout1, 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; | tin0 ^= tout0; | ||||
tin1 ^= tout1; | tin1 ^= tout1; | ||||
tin[0] = tin0; | 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, xor0); | ||||
n2l(iv, xor1); | n2l(iv, xor1); | ||||
iv -= 8; | iv -= 8; | ||||
for (l -= 8; l >= 0; l -= 8) { | |||||
while (l >= 8) { | |||||
n2l(in, tin0); | n2l(in, tin0); | ||||
n2l(in, tin1); | n2l(in, tin1); | ||||
tin[0] = tin0; | tin[0] = tin0; | ||||
@@ -220,8 +221,9 @@ void CAST_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, | |||||
l2n(tout1, out); | l2n(tout1, out); | ||||
xor0 = tin0; | xor0 = tin0; | ||||
xor1 = tin1; | xor1 = tin1; | ||||
l -= 8; | |||||
} | } | ||||
if (l != -8) { | |||||
if (l != 0) { | |||||
n2l(in, tin0); | n2l(in, tin0); | ||||
n2l(in, tin1); | n2l(in, tin1); | ||||
tin[0] = tin0; | tin[0] = tin0; | ||||
@@ -229,7 +231,7 @@ void CAST_cbc_encrypt(const uint8_t *in, uint8_t *out, long length, | |||||
CAST_decrypt(tin, ks); | CAST_decrypt(tin, ks); | ||||
tout0 = tin[0] ^ xor0; | tout0 = tin[0] ^ xor0; | ||||
tout1 = tin[1] ^ xor1; | tout1 = tin[1] ^ xor1; | ||||
l2nn(tout0, tout1, out, l + 8); | |||||
l2nn(tout0, tout1, out, l); | |||||
xor0 = tin0; | xor0 = tin0; | ||||
xor1 = tin1; | 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 | // 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 | // extra state information to record how much of the 64bit block we have used | ||||
// is contained in *num. | // 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, | const CAST_KEY *schedule, uint8_t *ivec, int *num, | ||||
int enc) { | int enc) { | ||||
uint32_t v0, v1, t; | uint32_t v0, v1, t; | ||||
int n = *num; | int n = *num; | ||||
long l = length; | |||||
size_t l = length; | |||||
uint32_t ti[2]; | uint32_t ti[2]; | ||||
uint8_t *iv, c, cc; | uint8_t *iv, c, cc; | ||||
@@ -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, | OPENSSL_EXPORT void BF_ecb_encrypt(const uint8_t *in, uint8_t *out, | ||||
const BF_KEY *key, int enc); | 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 | #ifdef __cplusplus | ||||
@@ -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_encrypt(uint32_t *data, const CAST_KEY *key); | ||||
OPENSSL_EXPORT void CAST_decrypt(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, | 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); | uint8_t *iv, int enc); | ||||
OPENSSL_EXPORT void CAST_cfb64_encrypt(const uint8_t *in, uint8_t *out, | 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); | uint8_t *ivec, int *num, int enc); | ||||
#ifdef __cplusplus | #ifdef __cplusplus | ||||