From 6229badcae2d126c9c89d625fd7d8f88391730ea Mon Sep 17 00:00:00 2001 From: John Newby Date: Tue, 6 Aug 2019 15:55:39 +0200 Subject: [PATCH] Removed previous stuff --- Makefile | 26 --------------- src/base64.c | 77 --------------------------------------------- src/erl_comm.c | 63 ------------------------------------- src/erl_ecrecover.c | 45 -------------------------- src/test.c | 23 -------------- 5 files changed, 234 deletions(-) delete mode 100644 Makefile delete mode 100644 src/base64.c delete mode 100644 src/erl_comm.c delete mode 100644 src/erl_ecrecover.c delete mode 100644 src/test.c diff --git a/Makefile b/Makefile deleted file mode 100644 index 4711c25..0000000 --- a/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -DEBUG ?= 0 -ifeq ($(DEBUG), 1) - CFLAGS =-DDEBUG=1 -else - CFLAGS=-DNDEBUG -Ofast -endif - -CC = gcc -LIBS = -llibecrecover.so -LDPATH = -Ltarget/debug -INCLUDEPATH = -Iinclude - -%.o: %.c $(DEPS) - $(CC) $(CFLAGS) -c -o $(INCLUDEPATH) $@ $< - -all: test erl_ecrecover - -test: src/test.c src/base64.c target/release/libecrecover.so - $(CC) -o $@ $^ $(INCLUDEPATH) $(CFLAGS) $(LDPATH) - ./test - -erl_ecrecover: src/erl_ecrecover.c src/base64.c src/erl_comm.c target/debug/libecrecover.so - $(CC) -o$ $@ $^ $(INCLUDEPATH) $(CFLAGS) $(LDPATH) - -clean: - rm -f erl_ecrecover test diff --git a/src/base64.c b/src/base64.c deleted file mode 100644 index 59749b3..0000000 --- a/src/base64.c +++ /dev/null @@ -1,77 +0,0 @@ -#include "base64.h" - -#include - - -char *bin2hex(unsigned char *p, int len) -{ - char *hex = malloc(((2*len) + 1)); - char *r = hex; - - while(len && p) - { - (*r) = ((*p) & 0xF0) >> 4; - (*r) = ((*r) <= 9 ? '0' + (*r) : 'a' - 10 + (*r)); - r++; - (*r) = ((*p) & 0x0F); - (*r) = ((*r) <= 9 ? '0' + (*r) : 'a' - 10 + (*r)); - r++; - p++; - len--; - } - *r = '\0'; - - return hex; -} - -unsigned char *hex2bin(const char *str) -{ - int len, h; - unsigned char *result, *err, *p, c; - - err = malloc(1); - *err = 0; - - if (!str) - return err; - - if (!*str) - return err; - - len = 0; - p = (unsigned char*) str; - while (*p++) - len++; - - result = malloc((len/2)+1); - h = !(len%2) * 4; - p = result; - *p = 0; - - c = *str; - while(c) - { - if(('0' <= c) && (c <= '9')) - *p += (c - '0') << h; - else if(('A' <= c) && (c <= 'F')) - *p += (c - 'A' + 10) << h; - else if(('a' <= c) && (c <= 'f')) - *p += (c - 'a' + 10) << h; - else - return err; - - str++; - c = *str; - - if (h) - h = 0; - else - { - h = 4; - p++; - *p = 0; - } - } - - return result; -} diff --git a/src/erl_comm.c b/src/erl_comm.c deleted file mode 100644 index 4e174c3..0000000 --- a/src/erl_comm.c +++ /dev/null @@ -1,63 +0,0 @@ -// -*- C -*- - -#include "erl_comm.h" - -#include - -int read_cmd(byte *buf) -{ - int len; - - if (read_exact(buf, 2) != 2) - return(-1); - len = (buf[0] << 8) | buf[1]; - DEBUG_PRINTF("Len is %d\n", len); - if(len > ECRECOVER_BUFFER_MAX - 1) { - DEBUG_PRINTF("Avoiding overflow\n"); - return 0; // let's not overflow. - } - int read = read_exact(buf, len); - DEBUG_PRINTF("read_cmd returning %d\n", read); - return read; -} - -int write_cmd(byte *buf, int len) -{ - byte li; - - li = (len >> 8) & 0xff; - write_exact(&li, 1); - - li = len & 0xff; - write_exact(&li, 1); - - return write_exact(buf, len); -} - -int read_exact(byte *buf, int len) -{ - int i, got=0; - DEBUG_PRINTF("Read exact\n"); - do { - if ((i = read(0, buf+got, len-got)) <= 0) { - DEBUG_PRINTF("got=%d len=%d i=%d\n", got, len, i); - return(i); - } - got += i; - } while (got -#include -#include -#include - -#include "ecrecover.h" -#include "erl_comm.h" -#include "base64.h" - -#define OUTPUT_LENGTH 32 - -int main(int arc, char **argv) -{ - int fn, arg, len; - byte buf[ECRECOVER_BUFFER_MAX]; - - while ((len = read_cmd(buf)) > 0) { - DEBUG_PRINTF("len %d\n", len); - fn = buf[0]; - DEBUG_PRINTF("Function %d len %d\n", fn, len); - buf[len] = '\0'; - if (fn == 1) { - int result; - byte *input = hex2bin(buf+1); - byte *output = malloc(ECRECOVER_BUFFER_MAX); - result = ecrecover(input, output); - free(input); - DEBUG_PRINTF("Return value is %d", result); - if(result) { - byte *hex_result = bin2hex(output, OUTPUT_LENGTH); - strcpy(buf, hex_result); - free(hex_result); - DEBUG_PRINTF("result is %s len %ld\n", buf, strlen(buf)); - } else { - strcpy("failed", buf); - } - free(output); - } else { - strcpy("function not found", buf); - } - DEBUG_PRINTF("Returning %s\n", buf); - write_cmd(buf, strlen(buf)); - } -} diff --git a/src/test.c b/src/test.c deleted file mode 100644 index 26f6527..0000000 --- a/src/test.c +++ /dev/null @@ -1,23 +0,0 @@ -// -*-C-*- -#include -#include -#include -#include - -#include "../include/ecrecover.h" - -char *bin2hex(unsigned char*, int); -unsigned char *hex2bin(const char*); - -#define OUTPUT_LENGTH 32 - -int main(int arc, char **argv) -{ - // copied from Ethereum tests - unsigned char *input = hex2bin("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b650acf9d3f5f0a2c799776a1254355d5f4061762a237396a99a0e0e3fc2bcd6729514a0dacb2e623ac4abd157cb18163ff942280db4d5caad66ddf941ba12e03"); - unsigned char *expected = "000000000000000000000000c08b5542d177ac6686946920409741463a15dddb"; - unsigned char *output = malloc(OUTPUT_LENGTH * sizeof(unsigned char)); - ecrecover(input, output); - assert(strcmp(bin2hex(output, OUTPUT_LENGTH), expected) == 0); - printf("Test passed\n"); -}