diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f839b5..bf11cc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,21 @@ # Copyright (c) 2019, The Monero Project -# +# # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without modification, are # permitted provided that the following conditions are met: -# +# # 1. Redistributions of source code must retain the above copyright notice, this list of # conditions and the following disclaimer. -# +# # 2. Redistributions in binary form must reproduce the above copyright notice, this list # of conditions and the following disclaimer in the documentation and/or other # materials provided with the distribution. -# +# # 3. Neither the name of the copyright holder nor the names of its contributors may be # used to endorse or promote products derived from this software without specific # prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL @@ -34,6 +34,7 @@ set(CMAKE_VERBOSE_MAKEFILE ON) set(randomx_sources src/aes_hash.cpp +src/aes_hash_bindgen.cpp src/argon2_ref.c src/argon2_ssse3.c src/argon2_avx2.c diff --git a/src/aes_hash_bindgen.cpp b/src/aes_hash_bindgen.cpp index a0674a6..22f3ff2 100644 --- a/src/aes_hash_bindgen.cpp +++ b/src/aes_hash_bindgen.cpp @@ -1,6 +1,8 @@ #include "aes_hash.hpp" +#include "aes_hash_bindgen.h" extern "C" { + void hashAes1Rx4_soft(const void *input, size_t inputSize, void *hash) { hashAes1Rx4(input, inputSize, hash); } @@ -32,4 +34,5 @@ extern "C" { void hashAndFillAes1Rx4_hard(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state) { hashAndFillAes1Rx4(scratchpad, scratchpadSize, hash, fill_state); } + } diff --git a/src/aes_hash_bindgen.h b/src/aes_hash_bindgen.h index 06a799d..421c894 100644 --- a/src/aes_hash_bindgen.h +++ b/src/aes_hash_bindgen.h @@ -2,9 +2,9 @@ #define AES_HASH_BINDGEN_H #endif -#include +#include "stddef.h" -#ifdef __cplusplus +#if defined(__cplusplus) extern "C" { #endif @@ -20,6 +20,6 @@ void fillAes4Rx4_hard(void *state, size_t outputSize, void *buffer); void hashAndFillAes1Rx4_soft(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state); void hashAndFillAes1Rx4_hard(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state); -#ifdef __cplusplus +#if defined(__cplusplus) } #endif diff --git a/src/randomx.cpp b/src/randomx.cpp index eb7dde9..381317d 100644 --- a/src/randomx.cpp +++ b/src/randomx.cpp @@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "vm_compiled.hpp" #include "vm_compiled_light.hpp" #include "blake2/blake2.h" +#include "aes_hash_bindgen.h" #include "cpu.hpp" #include #include @@ -442,12 +443,15 @@ extern "C" { fegetenv(&fpstate); #endif + alignas(16) uint64_t tempHash[8]; + memcpy(tempHash, inHash, sizeof(tempHash)); int blakeResult; for (int chain = 0; chain < randomxProgramCount; ++chain) { - machine->run(inHash); - blakeResult = randomx_blake2b(inHash, sizeof(inHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile), nullptr, 0); + machine->run(tempHash); + blakeResult = randomx_blake2b(tempHash, sizeof(tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile), nullptr, 0); assert(blakeResult == 0); } + memcpy(inHash, tempHash, sizeof(tempHash)); #ifdef USE_CSR_INTRINSICS _mm_setcsr(fpstate);