Skip to content

Commit

Permalink
fix jh_hash function optimize bug in gcc11.4
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg committed Oct 27, 2023
1 parent 1993560 commit e8cde15
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion consensus/cryptonight-rs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ fn main() {
config.flag("-maes").flag("-msse2");
}
if target_os.contains("linux") || target_os.contains("macos") {
config.flag("-fexceptions").flag("-std=gnu99");
config
.flag("-Ofast")
.flag("-fexceptions")
.flag("-std=gnu99");
}
config.compile("cryptonight");
}
9 changes: 5 additions & 4 deletions consensus/cryptonight-rs/ext/c_jh.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,17 @@ static void E8(hashState *state)
/*The compression function F8 */
static void F8(hashState *state)
{
uint64 i;
uint64_t* x = (uint64_t*)state->x;
const uint64_t* buf = (uint64*)state->buffer;

/*xor the 512-bit message with the fist half of the 1024-bit hash state*/
for (i = 0; i < 8; i++) state->x[i >> 1][i & 1] ^= ((uint64*)state->buffer)[i];
/*xor the 512-bit message with the fist half of the 1024-bit hash state*/
for (int i = 0; i < 8; ++i) x[i] ^= buf[i];

/*the bijective function E8 */
E8(state);

/*xor the 512-bit message with the second half of the 1024-bit hash state*/
for (i = 0; i < 8; i++) state->x[(8+i) >> 1][(8+i) & 1] ^= ((uint64*)state->buffer)[i];
for (int i = 0; i < 8; ++i) x[i + 8] ^= buf[i];
}

/*before hashing a message, initialize the hash state as H0 */
Expand Down

0 comments on commit e8cde15

Please sign in to comment.