Skip to content

Commit 99ac8d5

Browse files
author
Ricky Cheung
committed
avr: Merge both DUCO-S1A hasher functions
This change simplifies the code without causing much performance degradation. Signed-off-by: Ricky Cheung <[email protected]>
1 parent 20a5358 commit 99ac8d5

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

Arduino_Code/Arduino_Code.ino

+6-10
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,19 @@ void lowercase_hex_to_bytes(char const * hexDigest, uint8_t * rawDigest) {
108108
}
109109

110110
// DUCO-S1A hasher
111-
uint32_t ducos1a(char const * prevBlockHash, char const * targetBlockHash, uint32_t difficulty) {
111+
uint32_t ducos1a() {
112112
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
113113
// If the difficulty is too high for AVR architecture then return 0
114-
if (difficulty > 655) return 0;
114+
if (job->difficulty > 655) return 0;
115115
#endif
116116

117117
uint8_t target[SHA1_HASH_LEN];
118-
lowercase_hex_to_bytes(targetBlockHash, target);
118+
lowercase_hex_to_bytes(job->newBlockHash, target);
119119

120-
uint32_t const maxNonce = difficulty * 100 + 1;
121-
return ducos1a_mine(prevBlockHash, target, maxNonce);
122-
}
123-
124-
uint32_t ducos1a_mine(char const * prevBlockHash, uint8_t const * target, uint32_t maxNonce) {
125120
static duco_hash_state_t hash;
126-
duco_hash_init(&hash, prevBlockHash);
121+
duco_hash_init(&hash, job->lastBlockHash);
127122

123+
uint32_t const maxNonce = job->difficulty * 100 + 1;
128124
char nonceStr[10 + 1];
129125
for (uint32_t nonce = 0; nonce < maxNonce; nonce++) {
130126
ultoa(nonce, nonceStr, 10);
@@ -187,7 +183,7 @@ void hashEvent() {
187183
uint32_t startTime = micros();
188184

189185
// Call DUCO-S1A hasher
190-
uint32_t ducos1result = ducos1a(job->lastBlockHash, job->newBlockHash, job->difficulty);
186+
uint32_t ducos1result = ducos1a();
191187

192188
// Calculate elapsed time
193189
uint32_t elapsedTime = micros() - startTime;

0 commit comments

Comments
 (0)