summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2020-10-29 20:04:20 +0100
committerNiels Möller <nisse@lysator.liu.se>2020-10-29 20:04:20 +0100
commit4c8b0cdd97ffec3ae3f8d995afdfccbc261b3c79 (patch)
tree7bfadda6723826b053d69bd464999a2db42b4da1
parent2f3c633e94f09cd03a94ffd8f7ddac4020da81e7 (diff)
downloadnettle-4c8b0cdd97ffec3ae3f8d995afdfccbc261b3c79.tar.gz
blowfish: Add casts to uint32_t.
Avoids undefined behavior, since shifting an 8-bit value left by 24 bits overflows the range of signed int. Reported by Guido Vranken.
-rw-r--r--ChangeLog6
-rw-r--r--blowfish.c6
2 files changed, 10 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 57d121be..6626c6ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-10-29 Niels Möller <nisse@lysator.liu.se>
+
+ * blowfish.c (blowfish_set_key): Add casts to uint32_t. Avoids
+ undefined behavior, since shifting an 8-bit value left by 24 bits
+ overflows the range of signed int. Reported by Guido Vranken.
+
2020-10-28 Niels Möller <nisse@lysator.liu.se>
* gmp-glue.h (cnd_add_n, cnd_sub_n, cnd_swap): Deleted, use
diff --git a/blowfish.c b/blowfish.c
index e73caffe..3d546694 100644
--- a/blowfish.c
+++ b/blowfish.c
@@ -385,8 +385,10 @@ blowfish_set_key (struct blowfish_ctx *ctx,
for (i = j = 0; i < _BLOWFISH_ROUNDS + 2; i++)
{
- data = (key[j] << 24) | (key[(j+1) % length] << 16)
- | (key[(j+2) % length] << 8) | key[(j+3) % length];
+ data = ((uint32_t) key[j] << 24)
+ | ((uint32_t) key[(j+1) % length] << 16)
+ | ((uint32_t) key[(j+2) % length] << 8)
+ | (uint32_t) key[(j+3) % length];
ctx->p[i] ^= data;
j = (j + 4) % length;
}