Sitelet https://github.com/erigontech/silkpre/commit/afa1c5fe652c769408000acc0861fe3faddc6d09
Skip to content

Commit afa1c5f

Browse files
authored
Fix uninitialized memory in SHA256 (#8)
1 parent bd54b9e commit afa1c5f

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

‎lib/silkpre/sha256.c‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,25 +181,25 @@ static inline ALWAYS_INLINE void sha_256_implementation(uint32_t h[8], const voi
181181

182182
const uint8_t* p = chunk;
183183

184+
/*
185+
* The w-array is really w[64], but since we only need
186+
* 16 of them at a time, we save stack by calculating
187+
* 16 at a time.
188+
*
189+
* This optimization was not there initially and the
190+
* rest of the comments about w[64] are kept in their
191+
* initial state.
192+
*/
193+
194+
/*
195+
* create a 64-entry message schedule array w[0..63] of 32-bit words
196+
* (The initial values in w[0..63] don't matter, so many implementations zero them here)
197+
* copy chunk into first 16 words w[0..15] of the message schedule array
198+
*/
199+
uint32_t w[16];
200+
184201
/* Compression function main loop: */
185202
for (i = 0; i < 4; i++) {
186-
/*
187-
* The w-array is really w[64], but since we only need
188-
* 16 of them at a time, we save stack by calculating
189-
* 16 at a time.
190-
*
191-
* This optimization was not there initially and the
192-
* rest of the comments about w[64] are kept in their
193-
* initial state.
194-
*/
195-
196-
/*
197-
* create a 64-entry message schedule array w[0..63] of 32-bit words
198-
* (The initial values in w[0..63] don't matter, so many implementations zero them here)
199-
* copy chunk into first 16 words w[0..15] of the message schedule array
200-
*/
201-
uint32_t w[16];
202-
203203
for (j = 0; j < 16; j++) {
204204
if (i == 0) {
205205
w[j] = (uint32_t)p[0] << 24 | (uint32_t)p[1] << 16 | (uint32_t)p[2] << 8 | (uint32_t)p[3];

0 commit comments

Comments
 (0)