mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 20:19:23 +00:00
Cleanup
This commit is contained in:
parent
3003c067d3
commit
29f2dd4b9e
4 changed files with 22 additions and 27 deletions
|
@ -126,13 +126,11 @@ bool CBlockTemplate::Init(const String& blockTemplate)
|
||||||
void CBlockTemplate::CalculateMinerTxHash(uint8_t* hash)
|
void CBlockTemplate::CalculateMinerTxHash(uint8_t* hash)
|
||||||
{
|
{
|
||||||
uint8_t hashes[HASH_SIZE * 3];
|
uint8_t hashes[HASH_SIZE * 3];
|
||||||
uint8_t md[200];
|
|
||||||
|
|
||||||
// Calculate 3 partial hashes
|
// Calculate 3 partial hashes
|
||||||
|
|
||||||
// 1. Prefix
|
// 1. Prefix
|
||||||
keccak(raw_blob.data() + miner_tx_prefix_begin_index, miner_tx_prefix_end_index - miner_tx_prefix_begin_index, md);
|
keccak(raw_blob.data() + miner_tx_prefix_begin_index, miner_tx_prefix_end_index - miner_tx_prefix_begin_index, hashes, HASH_SIZE);
|
||||||
memcpy(hashes, md, HASH_SIZE);
|
|
||||||
|
|
||||||
// 2. Base RCT, single 0 byte in miner tx
|
// 2. Base RCT, single 0 byte in miner tx
|
||||||
static const uint8_t known_second_hash[HASH_SIZE] = {
|
static const uint8_t known_second_hash[HASH_SIZE] = {
|
||||||
|
@ -144,23 +142,18 @@ void CBlockTemplate::CalculateMinerTxHash(uint8_t* hash)
|
||||||
memset(hashes + HASH_SIZE * 2, 0, HASH_SIZE);
|
memset(hashes + HASH_SIZE * 2, 0, HASH_SIZE);
|
||||||
|
|
||||||
// Calculate miner transaction hash
|
// Calculate miner transaction hash
|
||||||
keccak(hashes, sizeof(hashes), md);
|
keccak(hashes, sizeof(hashes), hash, HASH_SIZE);
|
||||||
|
|
||||||
memcpy(hash, md, HASH_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CBlockTemplate::CalculateMerkleTreeHash(const uint8_t* hashes, size_t count, uint8_t* root_hash)
|
void CBlockTemplate::CalculateMerkleTreeHash(const uint8_t* hashes, size_t count, uint8_t* root_hash)
|
||||||
{
|
{
|
||||||
uint8_t md[200];
|
|
||||||
|
|
||||||
if (count == 1) {
|
if (count == 1) {
|
||||||
memcpy(root_hash, hashes, HASH_SIZE);
|
memcpy(root_hash, hashes, HASH_SIZE);
|
||||||
}
|
}
|
||||||
else if (count == 2) {
|
else if (count == 2) {
|
||||||
keccak(hashes, HASH_SIZE * 2, md);
|
keccak(hashes, HASH_SIZE * 2, root_hash, HASH_SIZE);
|
||||||
memcpy(root_hash, md, HASH_SIZE);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
|
@ -172,20 +165,17 @@ void CBlockTemplate::CalculateMerkleTreeHash(const uint8_t* hashes, size_t count
|
||||||
memcpy(ints.data(), hashes, (cnt * 2 - count) * HASH_SIZE);
|
memcpy(ints.data(), hashes, (cnt * 2 - count) * HASH_SIZE);
|
||||||
|
|
||||||
for (i = cnt * 2 - count, j = cnt * 2 - count; j < cnt; i += 2, ++j) {
|
for (i = cnt * 2 - count, j = cnt * 2 - count; j < cnt; i += 2, ++j) {
|
||||||
keccak(hashes + i * HASH_SIZE, HASH_SIZE * 2, md);
|
keccak(hashes + i * HASH_SIZE, HASH_SIZE * 2, ints.data() + j * HASH_SIZE, HASH_SIZE);
|
||||||
memcpy(ints.data() + j * HASH_SIZE, md, HASH_SIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (cnt > 2) {
|
while (cnt > 2) {
|
||||||
cnt >>= 1;
|
cnt >>= 1;
|
||||||
for (i = 0, j = 0; j < cnt; i += 2, ++j) {
|
for (i = 0, j = 0; j < cnt; i += 2, ++j) {
|
||||||
keccak(ints.data() + i * HASH_SIZE, HASH_SIZE * 2, md);
|
keccak(ints.data() + i * HASH_SIZE, HASH_SIZE * 2, ints.data() + j * HASH_SIZE, HASH_SIZE);
|
||||||
memcpy(ints.data() + j * HASH_SIZE, md, HASH_SIZE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keccak(ints.data(), HASH_SIZE * 2, md);
|
keccak(ints.data(), HASH_SIZE * 2, root_hash, HASH_SIZE);
|
||||||
memcpy(root_hash, md, HASH_SIZE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,13 @@
|
||||||
|
|
||||||
#include "base/crypto/keccak.h"
|
#include "base/crypto/keccak.h"
|
||||||
#include "base/tools/cryptonote/Signatures.h"
|
#include "base/tools/cryptonote/Signatures.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
#include "base/tools/cryptonote/crypto-ops.h"
|
#include "base/tools/cryptonote/crypto-ops.h"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#include "base/tools/Cvt.h"
|
#include "base/tools/Cvt.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,9 +79,7 @@ static void random_scalar(ec_scalar& res)
|
||||||
|
|
||||||
static void hash_to_scalar(const void* data, size_t length, ec_scalar& res)
|
static void hash_to_scalar(const void* data, size_t length, ec_scalar& res)
|
||||||
{
|
{
|
||||||
uint8_t md[200];
|
xmrig::keccak((const uint8_t*) data, length, (uint8_t*) &res, sizeof(res));
|
||||||
xmrig::keccak((const char*) data, length, md);
|
|
||||||
memcpy(&res, md, sizeof(res));
|
|
||||||
sc_reduce32((uint8_t*) &res);
|
sc_reduce32((uint8_t*) &res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,4 +197,11 @@ void derive_secret_key(const uint8_t* derivation, size_t output_index, const uin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void derive_view_secret_key(const uint8_t* spend_secret_key, uint8_t* view_secret_key)
|
||||||
|
{
|
||||||
|
keccak(spend_secret_key, 32, view_secret_key, 32);
|
||||||
|
sc_reduce32(view_secret_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} /* namespace xmrig */
|
} /* namespace xmrig */
|
||||||
|
|
|
@ -34,6 +34,8 @@ bool check_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8
|
||||||
bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* derivation);
|
bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* derivation);
|
||||||
void derive_secret_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key);
|
void derive_secret_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key);
|
||||||
|
|
||||||
|
void derive_view_secret_key(const uint8_t* spend_secret_key, uint8_t* view_secret_key);
|
||||||
|
|
||||||
} /* namespace xmrig */
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* From fe.h */
|
/* From fe.h */
|
||||||
|
|
||||||
typedef int32_t fe[10];
|
typedef int32_t fe[10];
|
||||||
|
@ -167,7 +163,3 @@ void fe_tobytes(unsigned char *, const fe);
|
||||||
void fe_invert(fe out, const fe z);
|
void fe_invert(fe out, const fe z);
|
||||||
|
|
||||||
int ge_p3_is_point_at_infinity(const ge_p3 *p);
|
int ge_p3_is_point_at_infinity(const ge_p3 *p);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in a new issue