Example #1
0
 void init()
 {
     if (init_done_)
         return;
     secp256k1_start();
     init_done_ = true;
 }
Example #2
0
Address toAddress(Secret _private)
{
	secp256k1_start();

	byte pubkey[65];
	int pubkeylen = 65;
	int ok = secp256k1_ecdsa_seckey_verify(_private.data());
	if (!ok)
		return Address();
	ok = secp256k1_ecdsa_pubkey_create(pubkey, &pubkeylen, _private.data(), 0);
	assert(pubkeylen == 65);
	if (!ok)
		return Address();
	ok = secp256k1_ecdsa_pubkey_verify(pubkey, 65);
	if (!ok)
		return Address();
	auto ret = right160(dev::eth::sha3(bytesConstRef(&(pubkey[1]), 64)));
#if ETH_ADDRESS_DEBUG
	cout << "---- ADDRESS -------------------------------" << endl;
	cout << "SEC: " << _private << endl;
	cout << "PUB: " << toHex(bytesConstRef(&(pubkey[1]), 64)) << endl;
	cout << "ADR: " << ret << endl;
#endif
	return ret;
}
Example #3
0
int main(void) {
    bench_sign_t data;
    secp256k1_start(SECP256K1_START_SIGN);

    run_benchmark("ecdsa_sign", bench_sign, bench_sign_setup, NULL, &data, 10, 20000);

    secp256k1_stop();
    return 0;
}
Example #4
0
    void init()
    {
        if (init_done_)
            return;

        // It may be more efficient on a per-call basis to pass these
        // individually via init(), however since we are caching the init
        // we must set both flags here.
        secp256k1_start(SECP256K1_START_VERIFY | SECP256K1_START_SIGN);

        init_done_ = true;
    }
Example #5
0
int main(int argc, char **argv) {
	int count = 10000;
	
    if (argc > 1)
        count = strtol(argv[1], NULL, 0)*47;

    printf("test count = %i\n", count);

    // initialize
    secp256k1_start();

    // num tests
	test_random_sigs(count);

    // shutdown
    secp256k1_stop();
    return 0;
}
static void __javasecp256k1_attach(void) {
	secp256k1_start(SECP256K1_START_VERIFY);
}
Example #7
0
int main(int argc, char **argv) {
    /* find iteration count */
    if (argc > 1) {
        count = strtol(argv[1], NULL, 0);
    }

    /* find random seed */
    uint64_t seed;
    if (argc > 2) {
        seed = strtoull(argv[2], NULL, 0);
    } else {
        FILE *frand = fopen("/dev/urandom", "r");
        if (!frand || !fread(&seed, sizeof(seed), 1, frand)) {
            seed = time(NULL) * 1337;
        }
        fclose(frand);
    }
    secp256k1_rand_seed(seed);

    printf("test count = %i\n", count);
    printf("random seed = %llu\n", (unsigned long long)seed);

    /* initialize */
    secp256k1_start(SECP256K1_START_SIGN | SECP256K1_START_VERIFY);

    /* initializing a second time shouldn't cause any harm or memory leaks. */
    secp256k1_start(SECP256K1_START_SIGN | SECP256K1_START_VERIFY);

    /* Likewise, re-running the internal init functions should be harmless. */
    secp256k1_fe_start();
    secp256k1_ge_start();
    secp256k1_scalar_start();
    secp256k1_ecdsa_start();

#ifndef USE_NUM_NONE
    /* num tests */
    run_num_smalltests();
#endif

    /* scalar tests */
    run_scalar_tests();

    /* field tests */
    run_field_inv();
    run_field_inv_var();
    run_field_inv_all();
    run_field_inv_all_var();
    run_sqr();
    run_sqrt();

    /* group tests */
    run_ge();

    /* ecmult tests */
    run_wnaf();
    run_point_times_order();
    run_ecmult_chain();

    /* ecdsa tests */
    run_ecdsa_sign_verify();
    run_ecdsa_end_to_end();
    run_ecdsa_edge_cases();
#ifdef ENABLE_OPENSSL_TESTS
    run_ecdsa_openssl();
#endif

    printf("random run = %llu\n", (unsigned long long)secp256k1_rand32() + ((unsigned long long)secp256k1_rand32() << 32));

    /* shutdown */
    secp256k1_stop();

    /* shutting down twice shouldn't cause any double frees. */
    secp256k1_stop();

    /* Same for the internal shutdown functions. */
    secp256k1_fe_stop();
    secp256k1_ge_stop();
    secp256k1_scalar_stop();
    secp256k1_ecdsa_stop();
    return 0;
}
int main(int argc, char **argv) {
	int rank;
	int size;

	MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
	MPI_Comm_size(MPI_COMM_WORLD, &size);
	printf("Moin. I'm process %d of %d processes.\n", rank, size);
	//FILE *ifile = stdin;
	//MPI_File ifile = stdin;
	MPI_File ifile;
	FILE *ofile = stdout;

	int c, spok = 0, aopt = 0;
	unsigned char *bopt = NULL, *iopt = NULL, *oopt = NULL;
	unsigned char *topt = NULL, *sopt = NULL, *popt = NULL;
	unsigned char *Wopt = NULL;

	while ((c = getopt(argc, argv, "ab:hi:o:p:s:t:W:")) != -1) {
		switch (c) {
		case 'a':
			aopt = 1; // open output file in append mode
			break;
		case 'b':
			bopt = optarg; // bloom filter file
			break;
		case 'i':
			iopt = optarg; // input file
			break;
		case 'o':
			oopt = optarg; // output file
			break;
		case 's':
			sopt = optarg; // salt
			break;
		case 'p':
			popt = optarg; // passphrase
			break;
		case 't':
			topt = optarg; // type of input
			break;
		case 'W':
			Wopt = optarg;
			break;
		case 'h':
			// show help
			usage(argv[0]);
			return 0;
		case '?':
			// show error
			return 1;
		default:
			// should never be reached...
			printf("got option '%c' (%d)\n", c, c);
			return 1;
		}
	}

	if (optind < argc) {
		if (optind == 1 && argc == 2) {
			// older versions of brainflayer had the bloom filter file as a
			// single optional argument, this keeps compatibility with that
			bopt = argv[1];
		} else {
			fprintf(stderr, "Invalid arguments:\n");
			while (optind < argc) {
				fprintf(stderr, "    '%s'\n", argv[optind++]);
			}
			exit(1);
		}
	}

	if (topt != NULL) {
		if (strcmp(topt, "str") == 0) {
			input2hash160 = &pass2hash160;
		} else if (strcmp(topt, "hex") == 0) {
			input2hash160 = &hexpass2hash160;
		} else if (strcmp(topt, "priv") == 0) {
			input2hash160 = &hexpriv2hash160;
		} else if (strcmp(topt, "warp") == 0) {
			spok = 1;
			input2hash160 = popt ? &warpsalt2hash160 : &warppass2hash160;
		} else if (strcmp(topt, "bwio") == 0) {
			spok = 1;
			if (popt && strcmp(popt, "hello world") == 0
					&& (Wopt == NULL
							|| strcmp(Wopt, "NEVER_TELL_ME_THE_ODDS") != 0)) {
				// https://www.youtube.com/watch?v=NHWjlCaIrQo
				for (c = 0; c < 100; ++c)
					fprintf(stderr, "\n"); // try not to clobber scrollback
				fprintf(stderr, "\033[2J\033[0;0H\033[0;0f"); // clear terminal and send cursor to top left
				fflush(stderr);
				sleep(1);
				fprintf(stderr, "A STRANGE GAME.\n");
				sleep(2);
				fprintf(stderr, "THE ONLY WINNING MOVE IS NOT TO PLAY.\n");
				sleep(2);
				fprintf(stderr,
						"\n"
								"So, you're looking for that sweet, sweet 0.5BTC bounty? Brainflayer's\n"
								"cracking speed against brainwallet.io had been communicated to them before\n"
								"the challange was created. It is likely that the salt was chosen to be\n"
								"infeasible to crack in the given timeframe by a significant margin. I advise\n"
								"against trying it - it's probably a waste time and money. If you want to do it\n"
								"anyway, run with `-W NEVER_TELL_ME_THE_ODDS`.\n");
				sleep(2);
				fprintf(stderr,
						"\nAs for me, I have better things to do with my CPU cycles.\n");
				sleep(3);
				bail(83, "CONNECTION TERMINATED\n");
			}
			input2hash160 = popt ? &bwiosalt2hash160 : &bwiopass2hash160;
		} else if (strcmp(topt, "bv2") == 0) {
			spok = 1;
			input2hash160 = popt ? &brainv2salt2hash160 : &brainv2pass2hash160;
		} else {
			bail(1, "Unknown input type '%s'.\n", topt);
		}
	} else {
		topt = "str";
		input2hash160 = &pass2hash160;
	}

	if (spok) {
		if (sopt && popt) {
			bail(1, "Cannot specify both a salt and a passphrase\n");
		}
		if (popt) {
			kdfpass = popt;
			kdfpass_sz = strlen(popt);
		} else {
			if (sopt) {
				kdfsalt = sopt;
				kdfsalt_sz = strlen(kdfsalt);
			} else {
				kdfsalt = malloc(0);
				kdfsalt_sz = 0;
			}
		}
	} else {
		if (popt) {
			bail(1,
					"Specifying a passphrase not supported with input type '%s'\n",
					topt);
		} else if (sopt) {
			bail(1,
					"Specifying a salt not supported with this input type '%s'\n",
					topt);
		}
	}

	if (bopt) {
		if ((bloom = bloom_open(bopt)) == NULL) {
			bail(1, "failed to open bloom filter.\n");
		}
	}

	if (iopt) {
		if (MPI_File_open(MPI_COMM_WORLD, iopt, MPI_MODE_RDONLY, MPI_INFO_NULL,
				&ifile)) {
			bail(1, "failed to open '%s' for reading: %s\n", iopt,
					strerror(errno));
		}
	}

	if (oopt) {
		if ((ofile = fopen(oopt, (aopt ? "a" : "w"))) == NULL) {
			bail(1, "failed to open '%s' for writing: %s\n", oopt,
					strerror(errno));
		}
	}

	/* use line buffered output */
	setvbuf(ofile, NULL, _IOLBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);

	secp256k1_start();
	const int overlap = 100;
	char **lines;
	int nlines;
	readlines(&ifile, rank, size, overlap, &lines, &nlines);
	fprintf(ofile, "----Welcome %d! %d Lines for you.----\n", rank, nlines);
	int index = 0;
	time_t start, end;
	double length;
	time(&start);
	for (int i = 0; i < nlines - 1; i++) {
		++index;
		input2hash160(lines[i], strlen(lines[i]));
		if (bloom) {
			if (bloom_chk_hash160(bloom, hash160_uncmp.ul)) {
				fprintresult(ofile, &hash160_uncmp, 'u', topt, lines[i]);
			}
			if (bloom_chk_hash160(bloom, hash160_compr.ul)) {
				fprintresult(ofile, &hash160_compr, 'c', topt, lines[i]);
			}
		} else {
			fprintresult(ofile, &hash160_uncmp, 'u', topt, lines[i]);
			fprintresult(ofile, &hash160_compr, 'c', topt, lines[i]);
		}
	}
	time(&end);
	length = difftime(end, start);
	double perSecond = index / length;
	fprintf(ofile, "----Process: %d, Lines: %d, speed: %.0f/sec!----\n", rank, index, perSecond);
	secp256k1_stop();
	MPI_File_close(&ifile);
	MPI_Finalize();
	return 0;
}
static void __javasecp256k1_attach(void) {
	secp256k1_start(secp256k1_start_verify);
}
Example #10
0
int main(int argc, char **argv) {
    /* find iteration count */
    if (argc > 1) {
        count = strtol(argv[1], NULL, 0);
    }

    /* find random seed */
    uint64_t seed;
    if (argc > 2) {
        seed = strtoull(argv[2], NULL, 0);
    } else {
        FILE *frand = fopen("/dev/urandom", "r");
        if (!frand || !fread(&seed, sizeof(seed), 1, frand)) {
            seed = time(NULL) * 1337;
        }
        fclose(frand);
    }
    secp256k1_rand_seed(seed);

    printf("test count = %i\n", count);
    printf("random seed = %llu\n", (unsigned long long)seed);

    /* initialize */
    secp256k1_start(SECP256K1_START_SIGN | SECP256K1_START_VERIFY);

    /* num tests */
    run_num_smalltests();

    /* scalar tests */
    run_scalar_tests();

    /* field tests */
    run_field_inv();
    run_field_inv_var();
    run_field_inv_all();
    run_field_inv_all_var();
    run_sqr();
    run_sqrt();

    /* group tests */
    run_ge();

    /* ecmult tests */
    run_wnaf();
    run_point_times_order();
    run_ecmult_chain();

    /* ecdsa tests */
    run_ecdsa_sign_verify();
    run_ecdsa_end_to_end();
    run_ecdsa_infinity();
#ifdef ENABLE_OPENSSL_TESTS
    run_ecdsa_openssl();
#endif

    printf("random run = %llu\n", (unsigned long long)secp256k1_rand32() + ((unsigned long long)secp256k1_rand32() << 32));

    /* shutdown */
    secp256k1_stop();
    return 0;
}
Example #11
0
int main(int argc, char **argv) {
  char *line = NULL;
  size_t line_sz = 0;

  secp256k1_start();

  /* use line buffered output */
  setvbuf(stdout, NULL, _IOLBF, 0);
  setvbuf(stderr, NULL, _IONBF, 0);

  if (argc == 2) {
    if ((bloom = bloom_open(argv[1])) == NULL) {
      fprintf(stderr, "failed to open bloom filter.\n");
      exit(1);
    }
  } else if (argc > 2) {
    fprintf(stderr, "too many arguments\n");
    exit(1);
  }

  while (getline(&line, &line_sz, stdin) > 0) {
    line[strlen(line)-1] = 0;
    pass2hash160(line, strlen(line));
    if (argc == 2) {
      if (bloom_chk_hash160(bloom, hash160_uncmp.ul)) {
        fprintf(stdout, "matched: %08x%08x%08x%08x%08x:u:%s\n",
                ntohl(hash160_uncmp.ul[0]),
                ntohl(hash160_uncmp.ul[1]),
                ntohl(hash160_uncmp.ul[2]),
                ntohl(hash160_uncmp.ul[3]),
                ntohl(hash160_uncmp.ul[4]),
                line);
      }
      if (bloom_chk_hash160(bloom, hash160_compr.ul)) {
        fprintf(stdout, "matched: %08x%08x%08x%08x%08x:c:%s\n",
                ntohl(hash160_compr.ul[0]),
                ntohl(hash160_compr.ul[1]),
                ntohl(hash160_compr.ul[2]),
                ntohl(hash160_compr.ul[3]),
                ntohl(hash160_compr.ul[4]),
                line);
      }
    } else {
      fprintf(stdout, "%08x%08x%08x%08x%08x:u:%s\n",
              ntohl(hash160_uncmp.ul[0]),
              ntohl(hash160_uncmp.ul[1]),
              ntohl(hash160_uncmp.ul[2]),
              ntohl(hash160_uncmp.ul[3]),
              ntohl(hash160_uncmp.ul[4]),
              line);
      fprintf(stdout, "%08x%08x%08x%08x%08x:c:%s\n",
              ntohl(hash160_compr.ul[0]),
              ntohl(hash160_compr.ul[1]),
              ntohl(hash160_compr.ul[2]),
              ntohl(hash160_compr.ul[3]),
              ntohl(hash160_compr.ul[4]),
              line);
    }
  }

  secp256k1_stop();

  return 0;
}