mirror of
				https://git.wownero.com/wownero/RandomWOW.git
				synced 2024-08-15 00:23:14 +00:00 
			
		
		
		
	Merge pull request #170 from tevador/pr-temphash
Hide tempHash from the public API
This commit is contained in:
		
						commit
						f872ce0b94
					
				
					 4 changed files with 17 additions and 17 deletions
				
			
		|  | @ -363,21 +363,21 @@ extern "C" { | ||||||
| 		machine->getFinalResult(output, RANDOMX_HASH_SIZE); | 		machine->getFinalResult(output, RANDOMX_HASH_SIZE); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	void randomx_calculate_hash_first(randomx_vm* machine, uint64_t *tempHash, const void* input, size_t inputSize) { | 	void randomx_calculate_hash_first(randomx_vm* machine, const void* input, size_t inputSize) { | ||||||
| 		blake2b(tempHash, sizeof(uint64_t) * 8, input, inputSize, nullptr, 0); | 		blake2b(machine->tempHash, sizeof(machine->tempHash), input, inputSize, nullptr, 0); | ||||||
| 		machine->initScratchpad(tempHash); | 		machine->initScratchpad(machine->tempHash); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	void randomx_calculate_hash_next(randomx_vm* machine, uint64_t *tempHash, const void* nextInput, size_t nextInputSize, void* output) { | 	void randomx_calculate_hash_next(randomx_vm* machine, const void* nextInput, size_t nextInputSize, void* output) { | ||||||
| 		machine->resetRoundingMode(); | 		machine->resetRoundingMode(); | ||||||
| 		for (uint32_t chain = 0; chain < RANDOMX_PROGRAM_COUNT - 1; ++chain) { | 		for (uint32_t chain = 0; chain < RANDOMX_PROGRAM_COUNT - 1; ++chain) { | ||||||
| 			machine->run(tempHash); | 			machine->run(machine->tempHash); | ||||||
| 			blake2b(tempHash, sizeof(uint64_t) * 8, machine->getRegisterFile(), sizeof(randomx::RegisterFile), nullptr, 0); | 			blake2b(machine->tempHash, sizeof(machine->tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile), nullptr, 0); | ||||||
| 		} | 		} | ||||||
| 		machine->run(tempHash); | 		machine->run(machine->tempHash); | ||||||
| 
 | 
 | ||||||
| 		// Finish current hash and fill the scratchpad for the next hash at the same time
 | 		// Finish current hash and fill the scratchpad for the next hash at the same time
 | ||||||
| 		blake2b(tempHash, sizeof(uint64_t) * 8, nextInput, nextInputSize, nullptr, 0); | 		blake2b(machine->tempHash, sizeof(machine->tempHash), nextInput, nextInputSize, nullptr, 0); | ||||||
| 		machine->hashAndFill(output, RANDOMX_HASH_SIZE, tempHash); | 		machine->hashAndFill(output, RANDOMX_HASH_SIZE, machine->tempHash); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -240,10 +240,11 @@ RANDOMX_EXPORT void randomx_destroy_vm(randomx_vm *machine); | ||||||
| RANDOMX_EXPORT void randomx_calculate_hash(randomx_vm *machine, const void *input, size_t inputSize, void *output); | RANDOMX_EXPORT void randomx_calculate_hash(randomx_vm *machine, const void *input, size_t inputSize, void *output); | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Paired functions used to calculate multiple RandomX hashes during mining for example. |  * Paired functions used to calculate multiple RandomX hashes more efficiently. | ||||||
|  |  * randomx_calculate_hash_first is called for the first input value. | ||||||
|  |  * randomx_calculate_hash_next will output the hash value of the previous input. | ||||||
|  * |  * | ||||||
|  * @param machine is a pointer to a randomx_vm structure. Must not be NULL. |  * @param machine is a pointer to a randomx_vm structure. Must not be NULL. | ||||||
|  * @param tempHash an array of 8 64-bit values used to store intermediate data between calls to randomx_calculate_hash_first and randomx_calculate_hash_next. |  | ||||||
|  * @param input is a pointer to memory to be hashed. Must not be NULL. |  * @param input is a pointer to memory to be hashed. Must not be NULL. | ||||||
|  * @param inputSize is the number of bytes to be hashed. |  * @param inputSize is the number of bytes to be hashed. | ||||||
|  * @param nextInput is a pointer to memory to be hashed for the next hash. Must not be NULL. |  * @param nextInput is a pointer to memory to be hashed for the next hash. Must not be NULL. | ||||||
|  | @ -251,8 +252,8 @@ RANDOMX_EXPORT void randomx_calculate_hash(randomx_vm *machine, const void *inpu | ||||||
|  * @param output is a pointer to memory where the hash will be stored. Must not |  * @param output is a pointer to memory where the hash will be stored. Must not | ||||||
|  *        be NULL and at least RANDOMX_HASH_SIZE bytes must be available for writing. |  *        be NULL and at least RANDOMX_HASH_SIZE bytes must be available for writing. | ||||||
| */ | */ | ||||||
| RANDOMX_EXPORT void randomx_calculate_hash_first(randomx_vm* machine, uint64_t *tempHash, const void* input, size_t inputSize); | RANDOMX_EXPORT void randomx_calculate_hash_first(randomx_vm* machine, const void* input, size_t inputSize); | ||||||
| RANDOMX_EXPORT void randomx_calculate_hash_next(randomx_vm* machine, uint64_t *tempHash, const void* nextInput, size_t nextInputSize, void* output); | RANDOMX_EXPORT void randomx_calculate_hash_next(randomx_vm* machine, const void* nextInput, size_t nextInputSize, void* output); | ||||||
| 
 | 
 | ||||||
| #if defined(__cplusplus) | #if defined(__cplusplus) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -122,15 +122,13 @@ void mine(randomx_vm* vm, std::atomic<uint32_t>& atomicNonce, AtomicHash& result | ||||||
| 	void* noncePtr = blockTemplate + 39; | 	void* noncePtr = blockTemplate + 39; | ||||||
| 	auto nonce = atomicNonce.fetch_add(1); | 	auto nonce = atomicNonce.fetch_add(1); | ||||||
| 
 | 
 | ||||||
| 	uint64_t tempHash[8]; |  | ||||||
| 
 |  | ||||||
| 	store32(noncePtr, nonce); | 	store32(noncePtr, nonce); | ||||||
| 	randomx_calculate_hash_first(vm, tempHash, blockTemplate, sizeof(blockTemplate)); | 	randomx_calculate_hash_first(vm, blockTemplate, sizeof(blockTemplate)); | ||||||
| 
 | 
 | ||||||
| 	while (nonce < noncesCount) { | 	while (nonce < noncesCount) { | ||||||
| 		nonce = atomicNonce.fetch_add(1); | 		nonce = atomicNonce.fetch_add(1); | ||||||
| 		store32(noncePtr, nonce); | 		store32(noncePtr, nonce); | ||||||
| 		randomx_calculate_hash_next(vm, tempHash, blockTemplate, sizeof(blockTemplate), &hash); | 		randomx_calculate_hash_next(vm, blockTemplate, sizeof(blockTemplate), &hash); | ||||||
| 		result.xorWith(hash); | 		result.xorWith(hash); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -68,6 +68,7 @@ protected: | ||||||
| 	uint64_t datasetOffset; | 	uint64_t datasetOffset; | ||||||
| public: | public: | ||||||
| 	std::string cacheKey; | 	std::string cacheKey; | ||||||
|  | 	alignas(16) uint64_t tempHash[8]; //8 64-bit values used to store intermediate data
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| namespace randomx { | namespace randomx { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue