Skip to content

Commit 85152db

Browse files
committed
Fix non-accelerated SHA1 writing to input buffer
Spotted by @Blebowski in #1184
1 parent eae02a4 commit 85152db

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

thirdparty/sha1.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef union {
6262
* Hash a single 512-bit block. This is the core of the algorithm.
6363
*/
6464
static void
65-
SHA1Transform(uint32_t state[5], const unsigned char buffer[64])
65+
SHA1Transform(uint32_t state[5], unsigned char buffer[64])
6666
{
6767
uint32_t a, b, c, d, e;
6868
CHAR64LONG16 *block;
@@ -494,13 +494,13 @@ static void sha1_process_arm(uint32_t state[5], const uint8_t data[], uint32_t l
494494
__attribute__((always_inline))
495495
static inline void
496496
sha1_transform_generic(uint32_t state[5],
497-
const unsigned char *buffer,
497+
const unsigned char *data,
498498
size_t length)
499499
{
500500
assert(length % 64 == 0);
501501

502502
#ifdef HAVE_SSE_SHA
503-
#if __GNUC__ >= 11
503+
#if __GNUC__ >= 11 || __clang_major__ >= 19
504504
const bool have_sha = __builtin_cpu_supports("sha");
505505
#else
506506
static int have_sha = -1;
@@ -514,18 +514,21 @@ sha1_transform_generic(uint32_t state[5],
514514
#endif
515515

516516
if (have_sha) {
517-
sha1_process_x86(state, buffer, length);
517+
sha1_process_x86(state, data, length);
518518
return;
519519
}
520520
#endif
521521

522522
#ifdef HAVE_ARM_CRYPTO
523-
sha1_process_arm(state, buffer, length);
523+
sha1_process_arm(state, data, length);
524524
return;
525525
#endif
526526

527-
for (int i = 0; i < length; i += 64)
528-
SHA1Transform(state, buffer + i);
527+
unsigned char buffer[64];
528+
for (int i = 0; i < length; i += 64) {
529+
memcpy(buffer, data + i, 64);
530+
SHA1Transform(state, buffer);
531+
}
529532
}
530533

531534
/*

0 commit comments

Comments
 (0)