niceBit

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 5f88c05f9cc3b6b41a99016e5a2b134e5961095d
parent 9f9f7eabcda0cf46c35e4394f6c15c39fd78f3ce
Author: nicholasfarrow <nicholas.w.farrow@gmail.com>
Date:   Wed, 11 Dec 2019 12:19:14 +1100

first commit

Diffstat:
Acheck_pub | 0
Acheck_pub.c | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcreate_pubkey.h | 19++++++++++++++++---
Mecdsa | 0
Mecdsa.c | 11++---------
5 files changed, 78 insertions(+), 12 deletions(-)

diff --git a/check_pub b/check_pub Binary files differ. diff --git a/check_pub.c b/check_pub.c @@ -0,0 +1,60 @@ +#include <stdio.h> +#include <string.h> +#include <openssl/sha.h> + +const char *coin_err; +#define bail(s) { coin_err = s; return 0; } + +int unbase58(const char *s, unsigned char *out) { + static const char *tmpl = "123456789" + "ABCDEFGHJKLMNPQRSTUVWXYZ" + "abcdefghijkmnopqrstuvwxyz"; + int i, j, c; + const char *p; + + memset(out, 0, 25); + for (i = 0; s[i]; i++) { + if (!(p = strchr(tmpl, s[i]))) + bail("bad char"); + + c = p - tmpl; + for (j = 25; j--; ) { + c += 58 * out[j]; + out[j] = c % 256; + c /= 256; + } + + if (c) bail("address too long"); + } + + return 1; +} + +int valid(const char *s) { + unsigned char dec[32], d1[SHA256_DIGEST_LENGTH], d2[SHA256_DIGEST_LENGTH]; + + coin_err = ""; + if (!unbase58(s, dec)) return 0; + + SHA256(SHA256(dec, 21, d1), SHA256_DIGEST_LENGTH, d2); + + if (memcmp(dec + 21, d2, 4)) + bail("bad digest"); + + return 1; +} + +int main (void) { + const char *s[] = { + "1fVyBWPTYp8vMUePH99e61WJwz8pM9w3t3t", + "1JbdnHv5PT9yDy7zVmkVFaFaxGZeV6qoVC", + "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62I", + 0 }; + int i; + for (i = 0; s[i]; i++) { + int status = valid(s[i]); + printf("%s: %s\n", s[i], status ? "Ok" : coin_err); + } + + return 0; +} diff --git a/create_pubkey.h b/create_pubkey.h @@ -48,19 +48,32 @@ char* base58(byte *s, char *out) { return out; } +/* char *coin_encode(const char *x, const char *y, char *out) { +*/ +char *coin_encode(const unsigned char *pubkey64, char *out) { byte s[65]; byte rmd[5 + RIPEMD160_DIGEST_LENGTH]; - + + /* if (!is_hex(x) || !(is_hex(y))) { coin_err = "bad public point string"; return 0; } - + */ + s[0] = 4; + + int j; + for (j = 0; j < 64; j++) { + s[j+1] = pubkey64[j]; + } + + /* str_to_byte(x, s + 1, 32); str_to_byte(y, s + 33, 32); - + */ + rmd[0] = COIN_VER; RIPEMD160(SHA256(s, 65, 0), SHA256_DIGEST_LENGTH, rmd + 1); diff --git a/ecdsa b/ecdsa Binary files differ. diff --git a/ecdsa.c b/ecdsa.c @@ -72,15 +72,8 @@ int main() { printf("%02X", public_key64[i]); } - char unsigned public_key32[33]; - size_t pk32_len = sizeof(public_key32); - - secp256k1_ec_pubkey_serialize(ctx, public_key32, &pk32_len, &pubkey, SECP256K1_EC_COMPRESSED); - - printf("\n\nShort Public Key : "); - for(int i=0; i<33; i++) { - printf("%02X", public_key32[i]); - } + printf("\nPublic Address:1"); + puts(coin_encode(public_key64, 0)); /* &pubkeys[i]