void main(void){ int i =0; int j =0; int bits = 128; paillier_prvkey_t* prvkey; paillier_pubkey_t* pubkey; char* my_str = "cookies"; char* my_str2; char* my_pubkey; char* my_prvkey; paillier_plaintext_t* my_plain_txt; paillier_plaintext_t* my_plain_txt2; paillier_ciphertext_t* my_enc_txt; void* my_enc_export[128]; my_plain_txt = paillier_plaintext_from_str(my_str); paillier_keygen( bits, &pubkey, &prvkey, &paillier_get_rand_devurandom); my_enc_txt = paillier_enc(NULL, pubkey, my_plain_txt, &paillier_get_rand_devurandom); my_plain_txt2 = paillier_dec(NULL, pubkey, prvkey, my_enc_txt); my_str2 = paillier_plaintext_to_str(my_plain_txt2); my_pubkey = paillier_pubkey_to_hex( pubkey ); my_prvkey = paillier_prvkey_to_hex( prvkey ); printf("my pub key is : %s\n", my_pubkey); printf("my prv key is : %s\n", my_prvkey); return; }
int main() { paillier_pubkey_t *pubkey; paillier_prvkey_t *privkey; FILE *f = fopen("key", "r"); if (f != NULL) { char yn; while(1) { printf("Key file exists, do you want overrite?[y/n]"); scanf("%s", &yn); if (yn == 'n') { exit(1); } if (yn == 'y') { fclose(f); break; } } } FILE *p = fopen("key", "w"); if (p == NULL) { printf("Please run with sudo!\n"); exit(1); } printf("Generate new key...\n"); generate_key(128, &pubkey, &privkey); fprintf(p, "%s\n", paillier_pubkey_to_hex(pubkey)); fprintf(p, "%s\n", paillier_prvkey_to_hex(privkey)); fclose(p); paillier_freepubkey(pubkey); paillier_freeprvkey(privkey); return 0; }
int main (int argc, char** argv) { paillier_pubkey_t* pkey; paillier_prvkey_t* skey; paillier_keygen(128,&pkey,&skey,&paillier_get_rand_devrandom); void *context = zmq_ctx_new (); struct opts options; parse_options(argc,argv, &options); if(options.size <= 0 || options.scale <= 0 || !options.fileset){ fprintf(stderr,"Size and scale must be greater than 0 and file must be set\n"); exit(EXIT_FAILURE); } struct classify_data data; data.pub = pkey; data.prv = skey; data.maxcol = options.size; data.scale_factor = options.scale; data.texts = (paillier_plaintext_t**)malloc(options.size*sizeof(paillier_plaintext_t*)); data.col = 0; data.correct = 0; data.total = 0; init_rand(data.rand,&paillier_get_rand_devurandom,pkey->bits / 8 + 1); // Socket to talk to server gmp_printf("n: %Zd, lambda: %Zd\n",pkey->n,skey->lambda); void *requester = zmq_socket (context, ZMQ_REQ); zmq_connect (requester, "ipc:///tmp/karma"); char* pubkeyhex = paillier_pubkey_to_hex(pkey); s_send(requester,pubkeyhex); char* recv = s_recv(requester); free(recv); free(pubkeyhex); data.socket = requester; char* file = options.file; FILE* fp; struct csv_parser p; char buf[1024]; size_t bytes_read; if(csv_init(&p,0)) { fprintf(stderr, "Failed to initialize parser\n"); exit(EXIT_FAILURE); } fp = fopen(file,"rb"); if(!fp){ fprintf(stderr,"Failed to open classify file %s\n",strerror(errno)); exit(EXIT_FAILURE); } while ((bytes_read=fread(buf,1,1024,fp)) > 0){ if(!csv_parse(&p,buf,bytes_read,field_parsed,row_parsed,&data)){ fprintf(stderr, "Failed to parse file: %s\n",csv_strerror(csv_error(&p))); } } csv_fini(&p,field_parsed,row_parsed,&data); //fini took care of freeing the plaintexts csv_free(&p); free(data.texts); gmp_randclear(data.rand); printf("Correct(%i)/Total(%i) = %f\n",data.correct,data.total,data.correct/(data.total+0.0)); sleep (2); zmq_close (requester); zmq_ctx_destroy (context); return 0; }