From 81a7091b188fafc8deac01c199a502cbd3f437b5 Mon Sep 17 00:00:00 2001 From: Vlad Pronsky Date: Mon, 1 Jul 2024 00:50:14 +0300 Subject: [PATCH] ci --- .github/workflows/ci.yml | 18 ++++++++++++++++++ Makefile | 8 ++++---- lib/sha256.c | 18 +++++++++--------- main.c | 4 ++-- 4 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..07e4eeb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: ci + +on: + push: + +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - run: cc -v + - run: make build + - run: ./ecloop -v + - run: ./ecloop add -f data/btc-puzzles-hash -r 8000:ffff -q -o /dev/null diff --git a/Makefile b/Makefile index 1f5c6b2..d8d575b 100644 --- a/Makefile +++ b/Makefile @@ -10,15 +10,15 @@ clean: @rm -rf ecloop bench main a.out *.profraw *.profdata build: clean - @CC $(CC_FLAGS) main.c -o ecloop + @$(CC) $(CC_FLAGS) main.c -o ecloop add: build - ./ecloop add -f data/btc-puzzles-hash -t 8 -r 8000:ffffff -v + ./ecloop add -f data/btc-puzzles-hash -t 8 -r 8000:ffffff mul: build - cat data.txt | ./ecloop mul -f _check_1.txt -t 8 -a cu -v + cat data.txt | ./ecloop mul -f _check_1.txt -t 8 -a cu blf-test: build @rm -rf /tmp/test.blf cat data/btc-puzzles-hash | ./ecloop blf-gen -n 1024 -o /tmp/test.blf - ./ecloop add -f /tmp/test.blf -t 8 -r 8000:ffffff -v + ./ecloop add -f /tmp/test.blf -t 8 -r 8000:ffffff diff --git a/lib/sha256.c b/lib/sha256.c index b70739d..5dcd593 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -388,7 +388,7 @@ void sha256_final(u32 state[8], const u8 data[], u32 length) { static inline u32 rotr(u32 x, u32 n) { return (x >> n) | (x << (32 - n)); } static inline u32 MAJ(u32 a, u32 b, u32 c) { return (a & b) ^ (a & c) ^ (b & c); } static inline u32 CH(u32 e, u32 f, u32 g) { return (e & f) ^ (~e & g); } -static inline void round(u32 a, u32 b, u32 c, u32 *d, u32 e, u32 f, u32 g, u32 *h, u32 m, u32 k) { +static inline void ROUND(u32 a, u32 b, u32 c, u32 *d, u32 e, u32 f, u32 g, u32 *h, u32 m, u32 k) { u32 s = CH(e, f, g) + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + k + m; *d += s + *h; *h += s + MAJ(a, b, c) + (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)); @@ -426,14 +426,14 @@ void sha256_final(u32 state[8], const u8 data[], u32 length) { } for (int i = 0; i < 64; i += 8) { - round(a, b, c, &d, e, f, g, &h, w[i + 0], SHA256_K[i + 0]); - round(h, a, b, &c, d, e, f, &g, w[i + 1], SHA256_K[i + 1]); - round(g, h, a, &b, c, d, e, &f, w[i + 2], SHA256_K[i + 2]); - round(f, g, h, &a, b, c, d, &e, w[i + 3], SHA256_K[i + 3]); - round(e, f, g, &h, a, b, c, &d, w[i + 4], SHA256_K[i + 4]); - round(d, e, f, &g, h, a, b, &c, w[i + 5], SHA256_K[i + 5]); - round(c, d, e, &f, g, h, a, &b, w[i + 6], SHA256_K[i + 6]); - round(b, c, d, &e, f, g, h, &a, w[i + 7], SHA256_K[i + 7]); + ROUND(a, b, c, &d, e, f, g, &h, w[i + 0], SHA256_K[i + 0]); + ROUND(h, a, b, &c, d, e, f, &g, w[i + 1], SHA256_K[i + 1]); + ROUND(g, h, a, &b, c, d, e, &f, w[i + 2], SHA256_K[i + 2]); + ROUND(f, g, h, &a, b, c, d, &e, w[i + 3], SHA256_K[i + 3]); + ROUND(e, f, g, &h, a, b, c, &d, w[i + 4], SHA256_K[i + 4]); + ROUND(d, e, f, &g, h, a, b, &c, w[i + 5], SHA256_K[i + 5]); + ROUND(c, d, e, &f, g, h, a, &b, w[i + 6], SHA256_K[i + 6]); + ROUND(b, c, d, &e, f, g, h, &a, w[i + 7], SHA256_K[i + 7]); } state[0] += a; diff --git a/main.c b/main.c index c6b92cc..32e9c05 100644 --- a/main.c +++ b/main.c @@ -696,7 +696,7 @@ void usage(const char *name) { } void init(ctx_t *ctx, args_t *args) { - // check bench commands first + // check other commands first if (args->argc > 1) { if (strcmp(args->argv[1], "blf-gen") == 0) return blf_gen(args); if (strcmp(args->argv[1], "bench") == 0) return run_bench(); @@ -712,7 +712,7 @@ void init(ctx_t *ctx, args_t *args) { if (ctx->cmd == CMD_NIL) { if (args_bool(args, "-v")) printf("ecloop v%s\n", VERSION); else usage(args->argv[0]); - exit(1); + exit(0); } char *path = arg_str(args, "-f");