summaryrefslogtreecommitdiff
path: root/openbsd-compat/sha1.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2019-06-08 09:07:04 +1000
committerDarren Tucker <dtucker@dtucker.net>2019-06-14 14:22:39 +1000
commitadcaf40fd0a180e6cb5798317fdf479b52e3c09a (patch)
tree8397465cd83462c7c8dd78e1d6796734052ef3ea /openbsd-compat/sha1.c
parent7689048e6103d3c34cba24ac5aeea7bf8405d19a (diff)
upstream rev 1.27: fix integer overflow.
Cast bitcount to u_in64_t before bit shifting to prevent integer overflow on 32bit platforms which cause incorrect results when adding a block >=512M in size. sha1 patch from ante84 at gmail.com via openssh github, sha2 with djm@, ok tedu@
Diffstat (limited to 'openbsd-compat/sha1.c')
-rw-r--r--openbsd-compat/sha1.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/openbsd-compat/sha1.c b/openbsd-compat/sha1.c
index 2089ec340..73f897485 100644
--- a/openbsd-compat/sha1.c
+++ b/openbsd-compat/sha1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha1.c,v 1.26 2015/09/11 09:18:27 guenther Exp $ */ 1/* $OpenBSD: sha1.c,v 1.27 2019/06/07 22:56:36 dtucker Exp $ */
2 2
3/* 3/*
4 * SHA-1 in C 4 * SHA-1 in C
@@ -131,7 +131,7 @@ SHA1Update(SHA1_CTX *context, const u_int8_t *data, size_t len)
131 size_t i, j; 131 size_t i, j;
132 132
133 j = (size_t)((context->count >> 3) & 63); 133 j = (size_t)((context->count >> 3) & 63);
134 context->count += (len << 3); 134 context->count += ((u_int64_t)len << 3);
135 if ((j + len) > 63) { 135 if ((j + len) > 63) {
136 (void)memcpy(&context->buffer[j], data, (i = 64-j)); 136 (void)memcpy(&context->buffer[j], data, (i = 64-j));
137 SHA1Transform(context->state, context->buffer); 137 SHA1Transform(context->state, context->buffer);