diff options
Diffstat (limited to 'wasm/solver.c')
-rw-r--r-- | wasm/solver.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/wasm/solver.c b/wasm/solver.c index 890a34c..2eb39c5 100644 --- a/wasm/solver.c +++ b/wasm/solver.c @@ -11,16 +11,13 @@ char validate_hash(unsigned char *hash, unsigned char zero_bit_count) unsigned char q = zero_bit_count / 8; unsigned char r = zero_bit_count % 8; - for (unsigned char i = 0; i < q; i++) { - if (hash[i] != 0) { + for (unsigned char i = 0; i < q; i++) + if (hash[i] != 0) return 0; - } - } if (r > 0) { unsigned char mask = (unsigned char)(0xFF << (8 - r)); - if (hash[q] & mask) { + if (hash[q] & mask) return 0; - } } return 1; @@ -40,16 +37,15 @@ unsigned long long solve(unsigned char difficulty) nonce = 0; - while (1) { + for (;;) { sha256_init(&context); sha256_update(&context, challenge, sizeof(challenge)); sha256_update(&context, (unsigned char *)(&nonce), sizeof(nonce)); sha256_final(&context, hash); - if (validate_hash(hash, difficulty)) { + if (validate_hash(hash, difficulty)) break; - } nonce++; } |