diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-25 10:33:56 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-25 10:40:14 +0800 |
commit | ad79f448cb5e82cf6dfcf2ec7052add87edfc5a3 (patch) | |
tree | 6534dbdb10ad11fc5130e3a467f2573a74556489 /wasm/solver.c | |
parent | Indent -linux (diff) | |
download | powxy-ad79f448cb5e82cf6dfcf2ec7052add87edfc5a3.tar.gz powxy-ad79f448cb5e82cf6dfcf2ec7052add87edfc5a3.tar.zst powxy-ad79f448cb5e82cf6dfcf2ec7052add87edfc5a3.zip |
More C style changesv0.1.80
Diffstat (limited to '')
-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++; } |