Beispiel #1
0
int main(int argc, char **argv)
{
    unsigned l_num = 1;
    unsigned i, j;
    
    if(argc > 1)
    {
        l_num = strtoul(argv[1], NULL, 10);
    }
    
    randfd = open("/dev/urandom", O_RDONLY);
    if(randfd == -1)
    {
        printf("No access to urandom\n");
        return -1;
    }
    
    uint8_t l_private[uECC_BYTES];
    uint8_t l_public[uECC_BYTES*2];
    uint8_t base64enc[uECC_BYTES*4];
    
    for(i=0; i<l_num; ++i)
    {
	uECC_set_rng(&getRandomBytes);
	uECC_make_key(l_public, l_private);
	
	base64_encode(base64enc, l_private, uECC_BYTES);
        printf("Private_key_%u= \"", i);
        printf(base64enc);
        printf("\";\n");
        printf("uint8_t private_%u[NUM_ECC_DIGITS] = {", i);
        vli_print(l_private);
        printf("};\n");


 	base64_encode(base64enc, l_public, uECC_BYTES*2);
        printf("Public_key_%u= \"", i);
        printf(base64enc);
        printf("\";\n");

        printf("uint8_t public_%u[2*NUM_ECC_DIGITS] = {", i);
        vli_print(l_public);
        vli_print(l_public+uECC_BYTES);
        printf("};\n\n");
    }
    
    return 0;
}
Beispiel #2
0
int main(int argc, char **argv)
{
    unsigned l_num = 1;
    unsigned i, j;
    
    if(argc > 1)
    {
        l_num = strtoul(argv[1], NULL, 10);
    }
    
    randfd = open("/dev/urandom", O_RDONLY);
    if(randfd == -1)
    {
        printf("No access to urandom\n");
        return -1;
    }
    
    uint32_t l_private[NUM_ECC_DIGITS];
    EccPoint l_public;
    
    for(i=0; i<l_num; ++i)
    {
        getRandomBytes((char *)l_private, NUM_ECC_DIGITS * sizeof(uint32_t));
        ecc_make_key(&l_public, l_private, l_private);
        
        printf("uint32_t private_%u[NUM_ECC_DIGITS] = {", i);
        vli_print(l_private);
        printf("};\n");

        printf("EccPoint public_%u = {\n", i);
        printf("    {");
        vli_print(l_public.x);
        printf("},\n");
        printf("    {");
        vli_print(l_public.y);
        printf("}};\n\n");
    }
    
    return 0;
}
Beispiel #3
0
static void test_multi(void)
{
	uint8_t public1[64], public2[64];
	uint8_t private1[32], private2[32];
	uint8_t shared1[32], shared2[32];
	int i;

	printf("Testing %u random private key pairs\n", PAIR_COUNT);

	for (i = 0; i < PAIR_COUNT; i++) {
		printf(".");
		fflush(stdout);

		ecc_make_key(public1, private1);
		ecc_make_key(public2, private2);

		ecdh_shared_secret(public1, private2, shared1);
		ecdh_shared_secret(public2, private1, shared2);

		if (memcmp(shared1, shared2, sizeof(shared1)) != 0) {
			printf("Shared secrets are not identical!\n");
			printf("Shared secret 1 = ");
			vli_print(shared1, sizeof(shared1));
			printf("\n");
			printf("Shared secret 2 = ");
			vli_print(shared2, sizeof(shared2));
			printf("\n");
			printf("Private key 1 = ");
			vli_print(private1, sizeof(private1));
			printf("\n");
			printf("Private key 2 = ");
			vli_print(private2, sizeof(private2));
			printf("\n");
			g_assert_not_reached();
		}
	}

	printf("\n");
}