Cleanup MoneroOcean patchset
This commit is contained in:
parent
42235a56da
commit
30fdc92884
28 changed files with 6138 additions and 6122 deletions
|
@ -47,6 +47,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <cassert>
|
||||
|
||||
extern "C" {
|
||||
#include "crypto/defyx/yescrypt.h"
|
||||
#include "crypto/defyx/KangarooTwelve.h"
|
||||
}
|
||||
#define YESCRYPT_FLAGS YESCRYPT_RW
|
||||
#define YESCRYPT_BASE_N 2048
|
||||
#define YESCRYPT_R 8
|
||||
#define YESCRYPT_P 1
|
||||
|
||||
RandomX_ConfigurationWownero::RandomX_ConfigurationWownero()
|
||||
{
|
||||
ArgonSalt = "RandomWOW\x01";
|
||||
|
@ -108,6 +117,24 @@ RandomX_ConfigurationKeva::RandomX_ConfigurationKeva()
|
|||
ScratchpadL3_Size = 1048576;
|
||||
}
|
||||
|
||||
RandomX_ConfigurationScala::RandomX_ConfigurationScala()
|
||||
{
|
||||
ArgonMemory = 131072;
|
||||
ArgonIterations = 2;
|
||||
ArgonSalt = "DefyXScala\x13";
|
||||
CacheAccesses = 2;
|
||||
DatasetBaseSize = 33554432;
|
||||
ScratchpadL1_Size = 65536;
|
||||
ScratchpadL2_Size = 131072;
|
||||
ScratchpadL3_Size = 262144;
|
||||
ProgramSize = 64;
|
||||
ProgramIterations = 1024;
|
||||
ProgramCount = 4;
|
||||
|
||||
RANDOMX_FREQ_IADD_RS = 25;
|
||||
RANDOMX_FREQ_CBRANCH = 16;
|
||||
}
|
||||
|
||||
RandomX_ConfigurationBase::RandomX_ConfigurationBase()
|
||||
: ArgonMemory(262144)
|
||||
, ArgonIterations(3)
|
||||
|
@ -311,11 +338,37 @@ RandomX_ConfigurationLoki RandomX_LokiConfig;
|
|||
RandomX_ConfigurationArqma RandomX_ArqmaConfig;
|
||||
RandomX_ConfigurationSafex RandomX_SafexConfig;
|
||||
RandomX_ConfigurationKeva RandomX_KevaConfig;
|
||||
RandomX_ConfigurationScala RandomX_ScalaConfig;
|
||||
|
||||
alignas(64) RandomX_ConfigurationBase RandomX_CurrentConfig;
|
||||
|
||||
static std::mutex vm_pool_mutex;
|
||||
|
||||
int sipesh(void *out, size_t outlen, const void *in, size_t inlen)
|
||||
{
|
||||
const void *salt = in;
|
||||
size_t saltlen = inlen;
|
||||
unsigned int t_cost = 0;
|
||||
unsigned int m_cost = 0;
|
||||
yescrypt_local_t local;
|
||||
int retval;
|
||||
|
||||
if (yescrypt_init_local(&local))
|
||||
return -1;
|
||||
retval = yescrypt_kdf(NULL, &local, (const uint8_t*)in, inlen, (const uint8_t*)salt, saltlen,
|
||||
(uint64_t)YESCRYPT_BASE_N << m_cost, YESCRYPT_R, YESCRYPT_P,
|
||||
t_cost, 0, YESCRYPT_FLAGS, (uint8_t*)out, outlen);
|
||||
if (yescrypt_free_local(&local))
|
||||
return -1;
|
||||
return retval;
|
||||
}
|
||||
|
||||
int k12(void *hash, const void *data, size_t length)
|
||||
{
|
||||
int kDo = KangarooTwelve((const unsigned char *)data, length, (unsigned char *)hash, 32, 0, 0);
|
||||
return kDo;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
randomx_cache *randomx_create_cache(randomx_flags flags, uint8_t *memory) {
|
||||
|
@ -550,4 +603,40 @@ extern "C" {
|
|||
machine->hashAndFill(output, RANDOMX_HASH_SIZE, tempHash);
|
||||
}
|
||||
|
||||
void defyx_calculate_hash(randomx_vm *machine, const void *input, size_t inputSize, void *output) {
|
||||
assert(machine != nullptr);
|
||||
assert(inputSize == 0 || input != nullptr);
|
||||
assert(output != nullptr);
|
||||
alignas(16) uint64_t tempHash[8];
|
||||
sipesh(tempHash, sizeof(tempHash), input, inputSize);
|
||||
k12(tempHash, input, inputSize);
|
||||
machine->initScratchpad(&tempHash);
|
||||
machine->resetRoundingMode();
|
||||
for (uint32_t chain = 0; chain < RandomX_CurrentConfig.ProgramCount - 1; ++chain) {
|
||||
machine->run(&tempHash);
|
||||
rx_blake2b(tempHash, sizeof(tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile), nullptr, 0);
|
||||
}
|
||||
machine->run(&tempHash);
|
||||
machine->getFinalResult(output, RANDOMX_HASH_SIZE);
|
||||
}
|
||||
|
||||
void defyx_calculate_hash_first(randomx_vm* machine, uint64_t (&tempHash)[8], const void* input, size_t inputSize) {
|
||||
sipesh(tempHash, sizeof(tempHash), input, inputSize);
|
||||
k12(tempHash, input, inputSize);
|
||||
machine->initScratchpad(tempHash);
|
||||
}
|
||||
|
||||
void defyx_calculate_hash_next(randomx_vm* machine, uint64_t (&tempHash)[8], const void* nextInput, size_t nextInputSize, void* output) {
|
||||
machine->resetRoundingMode();
|
||||
for (uint32_t chain = 0; chain < RandomX_CurrentConfig.ProgramCount - 1; ++chain) {
|
||||
machine->run(&tempHash);
|
||||
rx_blake2b(tempHash, sizeof(tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile), nullptr, 0);
|
||||
}
|
||||
machine->run(&tempHash);
|
||||
|
||||
// Finish current hash and fill the scratchpad for the next hash at the same time
|
||||
sipesh(tempHash, sizeof(tempHash), nextInput, nextInputSize);
|
||||
k12(tempHash, nextInput, nextInputSize);
|
||||
machine->hashAndFill(output, RANDOMX_HASH_SIZE, tempHash);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue