mirror of
https://github.com/xmrig/xmrig.git
synced 2025-03-12 09:37:35 +00:00
Update signing algorithm
This commit is contained in:
parent
3967badc55
commit
cf104ebdc5
8 changed files with 20 additions and 34 deletions
|
@ -282,7 +282,7 @@ void xmrig::CpuWorker<N>::start()
|
|||
if (first) {
|
||||
first = false;
|
||||
if (job.hasMinerSignature()) {
|
||||
job.generateMinerSignature(m_job.currentJob().timestamp() + *m_job.nonce(), miner_signature_ptr);
|
||||
job.generateMinerSignature(m_job.blob(), job.size(), miner_signature_ptr);
|
||||
}
|
||||
randomx_calculate_hash_first(m_vm, tempHash, m_job.blob(), job.size());
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ void xmrig::CpuWorker<N>::start()
|
|||
|
||||
if (job.hasMinerSignature()) {
|
||||
memcpy(miner_signature_saved, miner_signature_ptr, sizeof(miner_signature_saved));
|
||||
job.generateMinerSignature(m_job.currentJob().timestamp() + *m_job.nonce(), miner_signature_ptr);
|
||||
job.generateMinerSignature(m_job.blob(), job.size(), miner_signature_ptr);
|
||||
}
|
||||
randomx_calculate_hash_next(m_vm, tempHash, m_job.blob(), job.size(), m_hash);
|
||||
}
|
||||
|
|
|
@ -444,17 +444,6 @@ bool xmrig::Client::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
uint8_t signatureKeyBuf[32 * 2];
|
||||
if (Cvt::fromHex(signatureKeyBuf, sizeof(signatureKeyBuf), Json::getValue(params, "sig_key"))) {
|
||||
job.setEphemeralKeys(signatureKeyBuf, signatureKeyBuf + 32);
|
||||
|
||||
uint8_t major_version = 0;
|
||||
uint8_t minor_version = 0;
|
||||
uint64_t timestamp = 0;
|
||||
|
||||
CBlobReader ar(job.blob(), job.size());
|
||||
ar(major_version);
|
||||
ar(minor_version);
|
||||
ar(timestamp);
|
||||
|
||||
job.setTimestamp(timestamp);
|
||||
}
|
||||
# endif
|
||||
|
||||
|
|
|
@ -356,7 +356,6 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
derive_secret_key(derivation, 0, secret_spendkey, eph_secret_key);
|
||||
|
||||
job.setEphemeralKeys(m_blocktemplate.raw_blob.data() + m_blocktemplate.eph_public_key_index, eph_secret_key);
|
||||
job.setTimestamp(m_blocktemplate.timestamp);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
|
|
@ -185,8 +185,6 @@ void xmrig::Job::copy(const Job &other)
|
|||
# else
|
||||
memcpy(m_ephPublicKey, other.m_ephPublicKey, sizeof(m_ephPublicKey));
|
||||
memcpy(m_ephSecretKey, other.m_ephSecretKey, sizeof(m_ephSecretKey));
|
||||
|
||||
m_timestamp = other.m_timestamp;
|
||||
# endif
|
||||
|
||||
m_hasMinerSignature = other.m_hasMinerSignature;
|
||||
|
@ -238,8 +236,6 @@ void xmrig::Job::move(Job &&other)
|
|||
# else
|
||||
memcpy(m_ephPublicKey, other.m_ephPublicKey, sizeof(m_ephPublicKey));
|
||||
memcpy(m_ephSecretKey, other.m_ephSecretKey, sizeof(m_ephSecretKey));
|
||||
|
||||
m_timestamp = other.m_timestamp;
|
||||
# endif
|
||||
|
||||
m_hasMinerSignature = other.m_hasMinerSignature;
|
||||
|
@ -296,26 +292,25 @@ void xmrig::Job::generateHashingBlob(String& blob, String& signatureData) const
|
|||
xmrig::BlockTemplate::CalculateRootHash(p, p + m_minerTxPrefix.size(), m_minerTxMerkleTreeBranch, root_hash);
|
||||
|
||||
blob = rawBlob();
|
||||
xmrig::Cvt::toHex(blob.data() + (nonceOffset() + nonceSize() + 64) * 2, 64, root_hash, 32);
|
||||
const uint64_t offset = nonceOffset() + nonceSize() + BlockTemplate::SIGNATURE_SIZE + 2 /* vote */;
|
||||
xmrig::Cvt::toHex(blob.data() + offset * 2, 64, root_hash, 32);
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
void xmrig::Job::generateMinerSignature(uint64_t data, uint8_t* sig) const
|
||||
void xmrig::Job::generateMinerSignature(const uint8_t* blob, size_t size, uint8_t* out_sig) const
|
||||
{
|
||||
uint8_t sig_data[32];
|
||||
int k = sizeof(sig_data);
|
||||
do {
|
||||
sig_data[--k] = "0123456789"[data % 10];
|
||||
data /= 10;
|
||||
} while (data);
|
||||
uint8_t tmp[kMaxBlobSize];
|
||||
memcpy(tmp, blob, size);
|
||||
|
||||
// Fill signature with zeros
|
||||
memset(tmp + nonceOffset() + nonceSize(), 0, BlockTemplate::SIGNATURE_SIZE);
|
||||
|
||||
uint8_t prefix_hash[32];
|
||||
xmrig::keccak(sig_data + k, sizeof(sig_data) - k, prefix_hash, sizeof(prefix_hash));
|
||||
|
||||
xmrig::generate_signature(prefix_hash, m_ephPublicKey, m_ephSecretKey, sig);
|
||||
xmrig::keccak(tmp, static_cast<int>(size), prefix_hash, sizeof(prefix_hash));
|
||||
xmrig::generate_signature(prefix_hash, m_ephPublicKey, m_ephSecretKey, out_sig);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -122,7 +122,6 @@ public:
|
|||
void generateHashingBlob(String& blob, String& signatureData) const;
|
||||
# else
|
||||
inline const uint8_t* ephSecretKey() const { return m_hasMinerSignature ? m_ephSecretKey : nullptr; }
|
||||
inline uint64_t timestamp() const { return m_timestamp; }
|
||||
|
||||
inline void setEphemeralKeys(uint8_t* pub_key, uint8_t* sec_key)
|
||||
{
|
||||
|
@ -131,9 +130,7 @@ public:
|
|||
memcpy(m_ephSecretKey, sec_key, sizeof(m_ephSecretKey));
|
||||
}
|
||||
|
||||
inline void setTimestamp(uint64_t timestamp) { m_timestamp = timestamp; }
|
||||
|
||||
void generateMinerSignature(uint64_t data, uint8_t* sig) const;
|
||||
void generateMinerSignature(const uint8_t* blob, size_t size, uint8_t* out_sig) const;
|
||||
# endif
|
||||
|
||||
inline bool hasMinerSignature() const { return m_hasMinerSignature; }
|
||||
|
@ -175,7 +172,6 @@ private:
|
|||
// Miner signatures
|
||||
uint8_t m_ephPublicKey[32]{};
|
||||
uint8_t m_ephSecretKey[32]{};
|
||||
uint64_t m_timestamp = 0;
|
||||
# endif
|
||||
|
||||
bool m_hasMinerSignature = false;
|
||||
|
|
|
@ -45,6 +45,7 @@ bool BlockTemplate::Init(const String& blockTemplate, Coin coin)
|
|||
has_miner_signature = (coin == Coin::WOWNERO) && (major_version >= 18);
|
||||
if (has_miner_signature) {
|
||||
ar(miner_signature);
|
||||
ar(vote);
|
||||
}
|
||||
|
||||
// Miner transaction begin
|
||||
|
|
|
@ -54,6 +54,7 @@ struct BlockTemplate
|
|||
|
||||
bool has_miner_signature;
|
||||
uint8_t miner_signature[SIGNATURE_SIZE];
|
||||
uint8_t vote[2];
|
||||
|
||||
// Miner tx
|
||||
uint64_t tx_version;
|
||||
|
|
|
@ -29,7 +29,12 @@ extern "C" {
|
|||
}
|
||||
|
||||
#include "base/tools/Cvt.h"
|
||||
|
||||
#ifdef XMRIG_PROXY_PROJECT
|
||||
#define PROFILE_SCOPE(x)
|
||||
#else
|
||||
#include "crypto/rx/Profiler.h"
|
||||
#endif
|
||||
|
||||
|
||||
struct ec_scalar { char data[32]; };
|
||||
|
|
Loading…
Reference in a new issue