diff --git a/Makefile.am b/Makefile.am index 4f335e8..dad5bff 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,7 +5,8 @@ lib_LTLIBRARIES = \ libblkmaker_@LIBBLKMAKER_API_VERSION@_la_SOURCES = \ blkmaker.c \ - blktemplate.c + blktemplate.c \ + hex.c libblkmaker_@LIBBLKMAKER_API_VERSION@_la_LDFLAGS = -version-info $(LIBBLKMAKER_SO_VERSION) -no-undefined diff --git a/blkmaker_jansson.c b/blkmaker_jansson.c index 4312f63..d053b20 100644 --- a/blkmaker_jansson.c +++ b/blkmaker_jansson.c @@ -14,6 +14,8 @@ #include #include +#include "private.h" + #ifndef JSON_INTEGER_IS_LONG_LONG # error "Jansson 2.0 with long long support required!" #endif @@ -80,38 +82,7 @@ err: } -static bool my_hex2bin(void *o, const char *x, size_t len) { - unsigned char *oc = o; - unsigned char c, hc = 0x10; - len *= 2; - while (len) - { - switch (x[0]) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - c = x[0] - '0'; - break; - case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - c = x[0] - 'A' + 10; - break; - case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': - c = x[0] - 'a' + 10; - break; - default: - return false; - } - ++x; - if (hc < 0x10) - { - (oc++)[0] = (hc << 4) | c; - hc = 0x10; - } - else - hc = c; - --len; - } - return !x[0]; -} +#define my_hex2bin _blkmk_hex2bin #define GET(key, type) do { \ if (!(v = json_object_get(json, #key))) \ @@ -294,17 +265,7 @@ char varintEncode(unsigned char *out, uint64_t n) { return L; } -static -void my_bin2hex(char *out, const void *data, size_t datasz) { - const unsigned char *datac = data; - static char hex[] = "0123456789abcdef"; - out[datasz * 2] = '\0'; - for (size_t i = 0; i < datasz; ++i) - { - out[ i*2 ] = hex[datac[i] >> 4]; - out[(i*2)+1] = hex[datac[i] & 15]; - } -} +#define my_bin2hex _blkmk_bin2hex json_t *blkmk_submit_jansson(blktemplate_t *tmpl, const unsigned char *data, unsigned int dataid, blknonce_t nonce) { unsigned char blk[80 + 8 + 1000000]; diff --git a/hex.c b/hex.c new file mode 100644 index 0000000..0607bfe --- /dev/null +++ b/hex.c @@ -0,0 +1,47 @@ +#include + +#include + +bool _blkmk_hex2bin(void *o, const char *x, size_t len) { + unsigned char *oc = o; + unsigned char c, hc = 0x10; + len *= 2; + while (len) + { + switch (x[0]) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + c = x[0] - '0'; + break; + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + c = x[0] - 'A' + 10; + break; + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + c = x[0] - 'a' + 10; + break; + default: + return false; + } + ++x; + if (hc < 0x10) + { + (oc++)[0] = (hc << 4) | c; + hc = 0x10; + } + else + hc = c; + --len; + } + return !x[0]; +} + +void _blkmk_bin2hex(char *out, const void *data, size_t datasz) { + const unsigned char *datac = data; + static char hex[] = "0123456789abcdef"; + out[datasz * 2] = '\0'; + for (size_t i = 0; i < datasz; ++i) + { + out[ i*2 ] = hex[datac[i] >> 4]; + out[(i*2)+1] = hex[datac[i] & 15]; + } +} diff --git a/private.h b/private.h new file mode 100644 index 0000000..08e5a1c --- /dev/null +++ b/private.h @@ -0,0 +1,11 @@ +#ifndef BLKMK_PRIVATE_H +#define BLKMK_PRIVATE_H + +#include +#include + +// hex.c +extern void _blkmk_bin2hex(char *out, const void *data, size_t datasz); +extern bool _blkmk_hex2bin(void *o, const char *x, size_t len); + +#endif