Exemplo n.º 1
0
int
main( int argc, char** argv )
{



    kpabe_pub_t* pub;
    kpabe_msk_t* msk;
    kpabe_prv_t* prv;

    parse_args(argc, argv);

    pub = kpabe_pub_unserialize(suck_file(pub_file), 1);
    msk = kpabe_msk_unserialize(pub, suck_file(msk_file), 1);


    struct timespec start,d,end;
    clock_gettime(CLOCK_REALTIME,&start);

    if( !(prv = kpabe_keygen(pub, msk, policy)) ) {
        die("%s", kpabe_error());
    }


    clock_gettime(CLOCK_REALTIME,&end);
    diff(&d,&start,&end);

    printf("%lf", to_milliseconds(&d));

    free(policy);
    spit_file(out_file, kpabe_prv_serialize(prv), 1);

    return 0;
}
Exemplo n.º 2
0
int
main( int argc, char** argv )
{
	
	w12ibe_pub_params* pub;
	w12ibe_sk_id* sk;
	int file_len;
	GByteArray* aes_buf;
	GByteArray* plt;
	GByteArray* ct_buf;
	w12ibe_ct* ct;
	element_t m;
	
	parse_args(argc, argv);
	pub = w12ibe_pub_unserialize(suck_file(pub_file), 1);
	sk = w12ibe_sk_id_unserialize(pub, suck_file(prv_file), 1);
	read_w12ibe_file(in_file, &ct_buf, &file_len, &aes_buf);

	ct = w12ibe_ct_unserialize(pub, ct_buf, 1);
	if( !w12ibe_dec(pub, ct, sk, m) )
		die("%s", w12ibe_error());
	w12ibe_ct_free(ct);

	plt = aes_128_cbc_decrypt(aes_buf, m);
	g_byte_array_set_size(plt, file_len);
	g_byte_array_free(aes_buf, 1);
	//maybe I should free the sk too. However, it should be automatically been free when execution ends.
	spit_file(out_file, plt, 1);

	if( !keep )
		unlink(in_file);

	return 0;
}
Exemplo n.º 3
0
int
main( int argc, char** argv )
{
	bswabe_pub_t* pub;
	bswabe_cph_t* cph;
	int file_len;
	GByteArray* plt;
	GByteArray* cph_buf;
	GByteArray* aes_buf;
	element_t m;
	
	clock_t start, end;
	float time_result;

	parse_args(argc, argv);

	pub = bswabe_pub_unserialize(suck_file(pub_file), 1);
	
	//Start timer
	start=clock();
 	if( !(cph = bswabe_enc(pub, m, policy)) )
		die("%s", bswabe_error());
	free(policy);

	cph_buf = bswabe_cph_serialize(cph);
	bswabe_cph_free(cph);

	plt = suck_file(in_file);
	file_len = plt->len;
	aes_buf = aes_128_cbc_encrypt(plt, m);
	g_byte_array_free(plt, 1);
	element_clear(m);

	write_cpabe_file(out_file, cph_buf, file_len, aes_buf);
	//End Timer, display output
	end=clock();
	time_result = (float) (end-start)/(float) CLOCKS_PER_SEC;
	printf("Computation took %f seconds\n",time_result);
	
	g_byte_array_free(cph_buf, 1);
	g_byte_array_free(aes_buf, 1);

	if( !keep )
		unlink(in_file);

	return 0;
}
Exemplo n.º 4
0
int
main( int argc, char** argv )
{
	bswabe_pub_t* pub;
	bswabe_prv_t* prv;
	int file_len;
	GByteArray* aes_buf;
	GByteArray* plt;
	GByteArray* cph_buf;
	bswabe_cph_t* cph;
	element_t m;

	parse_args(argc, argv);

	pub = bswabe_pub_unserialize(suck_file(pub_file), 1);
	prv = bswabe_prv_unserialize(pub, suck_file(prv_file), 1);

	read_cpabe_file(in_file, &cph_buf, &file_len, &aes_buf);

	cph = bswabe_cph_unserialize(pub, cph_buf, 1);
	if( !bswabe_dec(pub, prv, cph, m) )
		die("%s", bswabe_error());
	bswabe_cph_free(cph);

	plt = aes_128_cbc_decrypt(aes_buf, m);
	g_byte_array_set_size(plt, file_len);
	g_byte_array_free(aes_buf, 1);

	spit_file(out_file, plt, 1);

	if( !keep )
		unlink(in_file);

	/* report ops if necessary */
/* 	if( report_ops ) */
/* 		printf("pairings:        %5d\n" */
/* 					 "exponentiations: %5d\n" */
/* 					 "multiplications: %5d\n", num_pairings, num_exps, num_muls); */

	return 0;
}
Exemplo n.º 5
0
int
main( int argc, char** argv )
{
	kpabe_pub_t* pub;
	kpabe_cph_t* cph;
	int file_len;
	GByteArray* plt;
	GByteArray* cph_buf;
	GByteArray* aes_buf;
	element_t m;

	parse_args(argc, argv);

	pub = kpabe_pub_unserialize(suck_file(pub_file), 1);

  if( !(cph = kpabe_enc(pub, m, attrs)) )
		die("%s", kpabe_error());
	free(attrs);

	cph_buf = kpabe_cph_serialize(cph);
	kpabe_cph_free(cph);

	plt = suck_file(in_file);
	file_len = plt->len;
	aes_buf = aes_128_cbc_encrypt(plt, m);
	g_byte_array_free(plt, 1);
	element_clear(m);

	write_kpabe_file(out_file, cph_buf, file_len, aes_buf);

	g_byte_array_free(cph_buf, 1);
	g_byte_array_free(aes_buf, 1);

	if( !keep )
		unlink(in_file);

	return 0;
}