Skip to content
This repository was archived by the owner on Sep 8, 2026. It is now read-only.

Commit e3da8f0

Browse files
committed
Backport upstream CryptoNight slow-hash width/index fixes to resolve cn_lite_slow_hash_v1 mismatch
1 parent 0f87f3a commit e3da8f0

4 files changed

Lines changed: 29 additions & 29 deletions

File tree

‎include/hash-ops.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ void cn_slow_hash(
7777
int light,
7878
int variant,
7979
int prehashed,
80-
uint64_t page_size,
81-
uint64_t scratchpad,
82-
uint64_t iterations,
80+
uint32_t page_size,
81+
uint32_t scratchpad,
82+
uint32_t iterations,
8383
uint64_t mask);
8484

8585
void hash_extra_blake(const void *data, size_t length, char *hash);

‎src/slow-hash-arm.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,14 @@ void cn_slow_hash(
257257
int light,
258258
int variant,
259259
int prehashed,
260-
uint64_t page_size,
261-
uint64_t scratchpad,
262-
uint64_t iterations,
260+
uint32_t page_size,
261+
uint32_t scratchpad,
262+
uint32_t iterations,
263263
uint64_t mask)
264264
{
265-
uint64_t TOTALBLOCKS = (page_size / AES_BLOCK_SIZE);
266-
uint64_t init_rounds = (scratchpad / INIT_SIZE_BYTE);
267-
uint64_t aes_rounds = (iterations / 2);
265+
uint32_t TOTALBLOCKS = (page_size / AES_BLOCK_SIZE);
266+
uint32_t init_rounds = (scratchpad / INIT_SIZE_BYTE);
267+
uint32_t aes_rounds = (iterations / 2);
268268

269269
RDATA_ALIGN16 uint8_t expandedKey[240];
270270

@@ -500,13 +500,13 @@ void cn_slow_hash(
500500
int light,
501501
int variant,
502502
int prehashed,
503-
uint64_t page_size,
504-
uint64_t scratchpad,
505-
uint64_t iterations,
503+
uint32_t page_size,
504+
uint32_t scratchpad,
505+
uint32_t iterations,
506506
uint64_t mask)
507507
{
508-
uint64_t init_rounds = (scratchpad / INIT_SIZE_BYTE);
509-
uint64_t aes_rounds = (iterations / 2);
508+
uint32_t init_rounds = (scratchpad / INIT_SIZE_BYTE);
509+
uint32_t aes_rounds = (iterations / 2);
510510

511511
uint8_t text[INIT_SIZE_BYTE];
512512
uint8_t a[AES_BLOCK_SIZE];

‎src/slow-hash-portable.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ void cn_slow_hash(
115115
int light,
116116
int variant,
117117
int prehashed,
118-
uint64_t page_size,
119-
uint64_t scratchpad,
120-
uint64_t iterations,
118+
uint32_t page_size,
119+
uint32_t scratchpad,
120+
uint32_t iterations,
121121
uint64_t mask)
122122
{
123-
uint64_t init_rounds = (scratchpad / INIT_SIZE_BYTE);
124-
uint64_t aes_rounds = (iterations / 2);
123+
uint32_t init_rounds = (scratchpad / INIT_SIZE_BYTE);
124+
uint32_t aes_rounds = (iterations / 2);
125125

126126
uint8_t text[INIT_SIZE_BYTE];
127127
uint8_t a[AES_BLOCK_SIZE];
@@ -182,7 +182,7 @@ void cn_slow_hash(
182182
for (i = 0; i < aes_rounds; i++)
183183
{
184184
// Iteration 1
185-
j = U64(a)[0] & mask;
185+
j = (*(uint32_t *)a) & mask;
186186
p = &long_state[j];
187187
aesb_single_round(p, p, a);
188188
copy_block(c1, p);
@@ -192,7 +192,7 @@ void cn_slow_hash(
192192
VARIANT1_1(p);
193193

194194
// Iteration 2
195-
j = U64(c1)[0] & mask;
195+
j = (*(uint32_t *)c1) & mask;
196196
p = &long_state[j];
197197
copy_block(c, p);
198198

‎src/slow-hash-x86.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ BOOL SetLockPagesPrivilege(HANDLE hProcess, BOOL bEnable)
408408
* the allocated buffer.
409409
*/
410410

411-
void slow_hash_allocate_state(uint64_t page_size)
411+
void slow_hash_allocate_state(uint32_t page_size)
412412
{
413413
if (hp_state != NULL)
414414
{
@@ -444,7 +444,7 @@ void slow_hash_allocate_state(uint64_t page_size)
444444
*@brief frees the state allocated by slow_hash_allocate_state
445445
*/
446446

447-
void slow_hash_free_state(uint64_t page_size)
447+
void slow_hash_free_state(uint32_t page_size)
448448
{
449449
if (hp_state == NULL)
450450
{
@@ -505,14 +505,14 @@ void cn_slow_hash(
505505
int light,
506506
int variant,
507507
int prehashed,
508-
uint64_t page_size,
509-
uint64_t scratchpad,
510-
uint64_t iterations,
508+
uint32_t page_size,
509+
uint32_t scratchpad,
510+
uint32_t iterations,
511511
uint64_t mask)
512512
{
513-
uint64_t TOTALBLOCKS = (page_size / AES_BLOCK_SIZE);
514-
uint64_t init_rounds = (scratchpad / INIT_SIZE_BYTE);
515-
uint64_t aes_rounds = (iterations / 2);
513+
uint32_t TOTALBLOCKS = (page_size / AES_BLOCK_SIZE);
514+
uint32_t init_rounds = (scratchpad / INIT_SIZE_BYTE);
515+
uint32_t aes_rounds = (iterations / 2);
516516

517517
RDATA_ALIGN16 uint8_t expandedKey[240]; /* These buffers are aligned to use later with SSE functions */
518518

0 commit comments

Comments
 (0)