diff options
author | Niels Möller <nisse@lysator.liu.se> | 2020-10-29 20:04:20 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2020-10-29 20:04:20 +0100 |
commit | 4c8b0cdd97ffec3ae3f8d995afdfccbc261b3c79 (patch) | |
tree | 7bfadda6723826b053d69bd464999a2db42b4da1 | |
parent | 2f3c633e94f09cd03a94ffd8f7ddac4020da81e7 (diff) | |
download | nettle-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-- | ChangeLog | 6 | ||||
-rw-r--r-- | blowfish.c | 6 |
2 files changed, 10 insertions, 2 deletions
@@ -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 @@ -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; } |