예제 #1
0
void bench_setup(void* arg) {
    bench_inv_t *data = (bench_inv_t*)arg;

    static const unsigned char init_x[32] = {
        0x02, 0x03, 0x05, 0x07, 0x0b, 0x0d, 0x11, 0x13,
        0x17, 0x1d, 0x1f, 0x25, 0x29, 0x2b, 0x2f, 0x35,
        0x3b, 0x3d, 0x43, 0x47, 0x49, 0x4f, 0x53, 0x59,
        0x61, 0x65, 0x67, 0x6b, 0x6d, 0x71, 0x7f, 0x83
    };

    static const unsigned char init_y[32] = {
        0x82, 0x83, 0x85, 0x87, 0x8b, 0x8d, 0x81, 0x83,
        0x97, 0xad, 0xaf, 0xb5, 0xb9, 0xbb, 0xbf, 0xc5,
        0xdb, 0xdd, 0xe3, 0xe7, 0xe9, 0xef, 0xf3, 0xf9,
        0x11, 0x15, 0x17, 0x1b, 0x1d, 0xb1, 0xbf, 0xd3
    };

    secp256k1_scalar_set_b32(&data->scalar_x, init_x, NULL);
    secp256k1_scalar_set_b32(&data->scalar_y, init_y, NULL);
    secp256k1_fe_set_b32(&data->fe_x, init_x);
    secp256k1_fe_set_b32(&data->fe_y, init_y);
    CHECK(secp256k1_ge_set_xo_var(&data->ge_x, &data->fe_x, 0));
    CHECK(secp256k1_ge_set_xo_var(&data->ge_y, &data->fe_y, 1));
    secp256k1_gej_set_ge(&data->gej_x, &data->ge_x);
    secp256k1_gej_set_ge(&data->gej_y, &data->ge_y);
    memcpy(data->data, init_x, 32);
    memcpy(data->data + 32, init_y, 32);
}
예제 #2
0
static int secp256k1_pubkey_load(const secp256k1_context* ctx, secp256k1_ge* ge, const secp256k1_pubkey* pubkey) {
    if (sizeof(secp256k1_ge_storage) == 64) {
        /* When the secp256k1_ge_storage type is exactly 64 byte, use its
         * representation inside secp256k1_pubkey, as conversion is very fast.
         * Note that secp256k1_pubkey_save must use the same representation. */
        secp256k1_ge_storage s;
        memcpy(&s, &pubkey->data[0], sizeof(s));
        secp256k1_ge_from_storage(ge, &s);
    } else {
        /* Otherwise, fall back to 32-byte big endian for X and Y. */
        secp256k1_fe x, y;
        secp256k1_fe_set_b32(&x, pubkey->data);
        secp256k1_fe_set_b32(&y, pubkey->data + 32);
        secp256k1_ge_set_xy(ge, &x, &y);
    }
    ARG_CHECK(!secp256k1_fe_is_zero(&ge->x));
    return 1;
}
예제 #3
0
파일: tests.c 프로젝트: 13XeNuS37/bitcoin
void random_fe(secp256k1_fe_t *x) {
    unsigned char bin[32];
    do {
        secp256k1_rand256(bin);
        if (secp256k1_fe_set_b32(x, bin)) {
            return;
        }
    } while(1);
}
예제 #4
0
파일: tests.c 프로젝트: 13XeNuS37/bitcoin
void random_field_element_test(secp256k1_fe_t *fe) {
    do {
        unsigned char b32[32];
        secp256k1_rand256_test(b32);
        if (secp256k1_fe_set_b32(fe, b32)) {
            break;
        }
    } while(1);
}
예제 #5
0
파일: tests.c 프로젝트: BitcoinCore/bitcoin
void random_field_element_test(secp256k1_fe_t *fe) {
    do {
        unsigned char b32[32];
        secp256k1_rand256_test(b32);
        secp256k1_num_t num;
        secp256k1_num_set_bin(&num, b32, 32);
        if (secp256k1_num_cmp(&num, &secp256k1_fe_consts->p) >= 0)
            continue;
        secp256k1_fe_set_b32(fe, b32);
        break;
    } while(1);
}
void precomputeTable(int window_size){
	secp256k1_gej_t gj; // base point in jacobian coordinates
	secp256k1_gej_t *table;

	WINDOW_SIZE = window_size;
	numberOfValues = (int) pow(2.0,window_size);

	if (256 % window_size == 0){
		numberOfWindows = (256 / window_size);
	}else{
		numberOfWindows = (256 / window_size) + 1;
	}
	remmining = 256 % window_size;

	
	table = (secp256k1_gej_t *)malloc(numberOfWindows*numberOfValues*sizeof(secp256k1_gej_t));
	prec = (secp256k1_ge_t *)malloc(numberOfWindows*numberOfValues*sizeof(secp256k1_ge_t));
	secp256k1_gej_set_ge(&gj, &secp256k1_ge_const_g);

	printf("%d %d %d %d\n",window_size,numberOfWindows,numberOfValues,remmining);
	secp256k1_ge_const_g;

	{
        static const unsigned char nums_b32[33] = "The scalar for this x is unknown";
        secp256k1_fe_t nums_x;
        secp256k1_ge_t nums_ge;
        VERIFY_CHECK(secp256k1_fe_set_b32(&nums_x, nums_b32));
        VERIFY_CHECK(secp256k1_ge_set_xo_var(&nums_ge, &nums_x, 0));
        secp256k1_gej_set_ge(&nums_gej, &nums_ge);
        /* Add G to make the bits in x uniformly distributed. */
        secp256k1_gej_add_ge_var(&nums_gej, &nums_gej, &secp256k1_ge_const_g, NULL);
    }
	
	secp256k1_gej_t gbase;
    secp256k1_gej_t numsbase;
    gbase = gj; /* (2^w_size)^num_of_windows * G */
    numsbase = nums_gej; /* 2^num_of_windows * nums. */

	for (int j = 0; j < numberOfWindows; j++) {
        //[number of windows][each value from 0 - (2^window_size - 1)]
        table[j*numberOfValues] = numsbase;
        for (int i = 1; i < numberOfValues; i++) {
            secp256k1_gej_add_var(&table[j*numberOfValues + i], &table[j*numberOfValues + i - 1], &gbase, NULL);
        }
        
        for (int i = 0; i < window_size; i++) {
            secp256k1_gej_double_var(&gbase, &gbase, NULL);
        }
        /* Multiply numbase by 2. */
        secp256k1_gej_double_var(&numsbase, &numsbase, NULL);
        if (j == numberOfWindows-2) {
            /* In the last iteration, numsbase is (1 - 2^j) * nums instead. */
            secp256k1_gej_neg(&numsbase, &numsbase);
            secp256k1_gej_add_var(&numsbase, &numsbase, &nums_gej, NULL);
        }
    }
	secp256k1_ge_set_all_gej_var(numberOfWindows*numberOfValues, prec, table, 0);

	printf("");
    free(table);
}
예제 #7
0
파일: tests.c 프로젝트: BitcoinCore/bitcoin
void random_fe(secp256k1_fe_t *x) {
    unsigned char bin[32];
    secp256k1_rand256(bin);
    secp256k1_fe_set_b32(x, bin);
}