aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--static/solver.c2
-rw-r--r--wasm/sha256.c22
-rw-r--r--wasm/sha256.h14
-rw-r--r--wasm/solver.c14
4 files changed, 13 insertions, 39 deletions
diff --git a/static/solver.c b/static/solver.c
index a06140e..73fb98f 100644
--- a/static/solver.c
+++ b/static/solver.c
@@ -106,7 +106,7 @@ int main(int argc, char **argv)
unsigned char digest[len];
size_t next = 0;
- while (1) {
+ for (;;) {
if (EVP_DigestInit_ex(mdctx, EVP_sha256(), NULL) != 1) {
fprintf(stderr, "EVP_DigestInit_ex\n");
EVP_MD_CTX_free(mdctx);
diff --git a/wasm/sha256.c b/wasm/sha256.c
index 3d6e9f1..f641cbd 100644
--- a/wasm/sha256.c
+++ b/wasm/sha256.c
@@ -1,21 +1,9 @@
-/*********************************************************************
-* Filename: sha256.c
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright: Identified to be public domain by ducky
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Implementation of the SHA-256 hashing algorithm.
- SHA-256 is one of the three algorithms in the SHA2
- specification. The others, SHA-384 and SHA-512, are not
- offered in this implementation.
- Algorithm specification can be found here:
- * http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
- This implementation uses little endian byte order.
-*********************************************************************/
-
-/*************************** HEADER FILES ***************************/
+// SPDX-FileContributor: Brad Conte <brad@bradconte.com>
+// Identified to be public domain by ducky
+// Disclaimer: This code is presented "as is" without any guarantees.
+
#include "sha256.h"
-/****************************** MACROS ******************************/
#define ROTLEFT(a,b) (((a) << (b)) | ((a) >> (32-(b))))
#define ROTRIGHT(a,b) (((a) >> (b)) | ((a) << (32-(b))))
@@ -32,7 +20,6 @@
((unsigned char *)(ptr))[i] = (unsigned char)(value); \
} while (0)
-/**************************** VARIABLES *****************************/
static const WORD k[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
@@ -44,7 +31,6 @@ static const WORD k[64] = {
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
};
-/*********************** FUNCTION DEFINITIONS ***********************/
void sha256_transform(SHA256_CTX *ctx, const BYTE data[])
{
WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64];
diff --git a/wasm/sha256.h b/wasm/sha256.h
index bbf9abc..659a5ad 100644
--- a/wasm/sha256.h
+++ b/wasm/sha256.h
@@ -1,21 +1,14 @@
-/*********************************************************************
-* Filename: sha256.h
-* Author: Brad Conte (brad AT bradconte.com)
-* Copyright: Identified to be public domain by ducky
-* Disclaimer: This code is presented "as is" without any guarantees.
-* Details: Defines the API for the corresponding SHA1 implementation.
-*********************************************************************/
+// SPDX-FileContributor: Brad Conte <brad@bradconte.com>
+// Identified to be public domain by ducky
+// Disclaimer: This code is presented "as is" without any guarantees.
#ifndef SHA256_H
#define SHA256_H
-/*************************** HEADER FILES ***************************/
#include <stddef.h>
-/****************************** MACROS ******************************/
#define SHA256_BLOCK_SIZE 32 // SHA256 outputs a 32 byte digest
-/**************************** DATA TYPES ****************************/
typedef unsigned char BYTE; // 8-bit byte
typedef unsigned int WORD; // 32-bit word, change to "long" for 16-bit machines
@@ -26,7 +19,6 @@ typedef struct {
WORD state[8];
} SHA256_CTX;
-/*********************** FUNCTION DECLARATIONS **********************/
void sha256_init(SHA256_CTX * ctx);
void sha256_update(SHA256_CTX * ctx, const BYTE data[], size_t len);
void sha256_final(SHA256_CTX * ctx, BYTE hash[]);
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++;
}