commit 9854bd2952ccaf070a10f8105ecf31e249015719
parent 5f88c05f9cc3b6b41a99016e5a2b134e5961095d
Author: NicholasFarrow <nicholas.w.farrow@gmail.com>
Date: Wed, 22 Jan 2020 00:44:24 +1100
Remove v1 files
Diffstat:
D | check_pub | | | 0 | |
D | check_pub.c | | | 60 | ------------------------------------------------------------ |
D | create_pubkey | | | 0 | |
D | ecdsa | | | 0 | |
D | ecdsa.c | | | 94 | ------------------------------------------------------------------------------- |
D | old_ecdsa.c | | | 30 | ------------------------------ |
D | secp256k1 | | | 1 | - |
M | v3.c | | | 121 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
8 files changed, 121 insertions(+), 185 deletions(-)
diff --git a/check_pub b/check_pub
Binary files differ.
diff --git a/check_pub.c b/check_pub.c
@@ -1,60 +0,0 @@
-#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 b/create_pubkey
Binary files differ.
diff --git a/ecdsa b/ecdsa
Binary files differ.
diff --git a/ecdsa.c b/ecdsa.c
@@ -1,94 +0,0 @@
-#include <stdio.h>
-#include <secp256k1.h>
-#include <create_pubkey.h>
-
-/* y^2 = x^3 + 7 */
-
-
-/* we want to return an array of unsigned bytes */
-char unsigned * gen_private_key() {
- int byte_count = 32;
- static char unsigned data[32];
- FILE *random_file;
-
- random_file = fopen("/dev/urandom", "r");
- fread(&data, 1, byte_count, random_file);
- fclose(random_file);
-
- printf("Private Key : ");
- for(int i=0; i<byte_count; i++) {
- printf("%02X", data[i]);
- }
-
- return data;
-}
-
-
-int main() {
- /*
- pointer to a char byte
- char unsigned *priv_key;
-
- priv_key = gen_private_key(32);
-
- printf("\n\nPrivate Key : ");
- for(int i=0; i<32; i++) {
- printf("%02X", *(i + priv_key));
- }
- */
-
- char unsigned priv_key[32];
- FILE *random_file;
-
- random_file = fopen("/dev/urandom", "r");
- fread(&priv_key, 1, 32, random_file);
- fclose(random_file);
-
- printf("\n\nPrivate Key : ");
- for(int i=0; i<32; i++) {
- printf("%02X", priv_key[i]);
- }
- int verify_ret;
-
- secp256k1_context* ctx;
- ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
-
- verify_ret = secp256k1_ec_seckey_verify(ctx, priv_key);
- printf("\nverify priv_key: %d\n", verify_ret);
-
-
- secp256k1_pubkey pubkey;
- int ret;
- ret = secp256k1_ec_pubkey_create(ctx, &pubkey, priv_key);
- printf("%d", ret);
-
- char unsigned public_key64[65];
- size_t pk_len = sizeof(public_key64);
-
- secp256k1_ec_pubkey_serialize(ctx, public_key64, &pk_len, &pubkey, SECP256K1_EC_UNCOMPRESSED);
-
- printf("\n\nLong Public Key : ");
- for(int i=0; i<65; i++) {
- printf("%02X", public_key64[i]);
- }
-
- printf("\nPublic Address:1");
- puts(coin_encode(public_key64, 0));
-
- /*
- &pubkeys[i]
-
- struct secp256k1_context_struct secp256k1_context;
-
- struct secp256k1_context_struct secp256k1_context;
-
- int op;
- op = secp256k1_ec_pubkey_create(ctx, priv_key, &pubkey);
-
- printf("%d", op);
- */
- printf("\n\n\n");
-}
-
-
-
diff --git a/old_ecdsa.c b/old_ecdsa.c
@@ -1,30 +0,0 @@
-#include <stdio.h>
-
-/* y^2 = x^3 + 7 */
-
-char unsigned gen_private_key(int byte_count) {
- char unsigned data[byte_count];
- FILE *random_file;
-
- random_file = fopen("/dev/urandom", "r");
- fread(&data, 1, byte_count, random_file);
- fclose(random_file);
-
- printf("Private Key : ");
- for(int i=0; i<byte_count; i++) {
- printf("%02X", data[i]);
- }
-
- return data;
-}
-
-
-int main() {
- char unsigned priv_key[32];
- priv_key[32] = gen_private_key(32);
-
- printf("\n\nPrivate Key : ");
- for(int i=0; i<32; i++) {
- printf("%02X", priv_key[i]);
- }
-}
diff --git a/secp256k1 b/secp256k1
@@ -1 +0,0 @@
-Subproject commit 96cd94e385f64c1936abf0d1e303d12d0f5da980
diff --git a/v3.c b/v3.c
@@ -1,4 +1,125 @@
#include <stdio.h>
#include <secp256k1.h>
+#include "create_pubkey.h"
+
+static secp256k1_context *ctx = NULL;
+
+void gen_keypair(unsigned char *seckey, unsigned char *pubaddress) {
+ secp256k1_pubkey pubkey;
+ /*unsigned char seckey[32];*/
+ unsigned char public_key64[65];
+
+ size_t pk_len = 65;
+
+ int i = 0;
+
+ ctx = secp256k1_context_create(
+ SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
+
+ /* Load secret key */
+ FILE *frand = fopen("/dev/urandom", "r");
+ fread(seckey, 32, 1, frand);
+ fclose(frand);
+
+ /*
+ printf("Seckey : ");
+ for(int i=0; i<32; i++) {
+ printf("%02X", seckey[i]);
+ }
+ printf("\n\n");
+ */
+
+ /* Verify secret key is valid */
+ if (!secp256k1_ec_seckey_verify(ctx, seckey)) {
+ printf("Invalid secret key");
+ }
+
+
+ /* Create Public Key */
+ if (!secp256k1_ec_pubkey_create(ctx, &pubkey, seckey)) {
+ printf("Failed to create public key");
+ }
+
+ /* Serialize Public Key */
+ secp256k1_ec_pubkey_serialize(
+ ctx,
+ public_key64,
+ &pk_len,
+ &pubkey,
+ SECP256K1_EC_UNCOMPRESSED
+ );
+
+ /* Print public key */
+ /*
+ printf("Long Public Key : ");
+ for(int i=0; i<65; i++) {
+ printf("%02X", public_key64[i]);
+ }
+ printf("\n\n");
+ */
+
+ /* Generate Public Address */
+ coin_encode(public_key64, pubaddress);
+}
+
+int check_vanity(unsigned char *pubaddress) {
+ unsigned char compstr[40];
+ int j;
+
+ /* For each vanity length
+ * ('len' digits in a row)
+ */
+ for(int len=10; len>4; len--) {
+
+ /* For each digit 1-9 */
+ for(int i=0; i<10; i++) {
+
+ /* Comprise compstr of 'len' repeats
+ * of digit 'i'
+ */
+ j = 0;
+ while(j<len) {
+ /* Offset digit i by 48
+ * as 48 is 0 in ASCII*/
+ compstr[j] = i + 48;
+ j++;
+ }
+
+ /* End string with null char*/
+ compstr[j] = '\0';
+
+ /*printf("Here is that string... %s\n", compstr);*/
+
+ /* Check if string in pubaddress */
+ if(strstr(pubaddress, compstr) != NULL) {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+int main() {
+ unsigned char seckey[32];
+ unsigned char pubaddress[40];
+
+ while(1) {
+ gen_keypair(seckey, pubaddress);
+
+ if(check_vanity(pubaddress)) {
+ printf("FOUND!!!\n\n");
+ printf("Seckey : ");
+ for(int i=0; i<32; i++) {
+ printf("%02X", seckey[i]);
+ }
+ printf("\n");
+ printf("Public Address: 1%s\n", pubaddress);
+ }
+ else {
+ ; /*printf("nothing...\n\n");*/
+ }
+ }
+}