void calibration_init(void) { rt_thread_t tid; struct setup_items setup; if(setup_load(&setup) == RT_EOK) { struct calibration_data data; rt_device_t device; data.min_x = setup.touch_min_x; data.max_x = setup.touch_max_x; data.min_y = setup.touch_min_y; data.max_y = setup.touch_max_y; device = rt_device_find("touch"); if(device != RT_NULL) rt_device_control(device, RT_TOUCH_CALIBRATION_DATA, &data); return; } tid = rt_thread_create("cali", calibration_entry, RT_NULL, 1024, 20, 20); if (tid != RT_NULL) rt_thread_startup(tid); }
int main(int argc,char **argv) { int rv = 0,i = 0,j=0; int datalen = sizeof(time_t) + 2*sizeof(uint32_t); int c = 0; char *ca[] = {"key.pub","key.prv","key.par"}; uint8_t *pmsg = NULL,*smsg = NULL; uint8_t **msga = NULL,*pmsga = NULL; //timing vars clock_t cstart =0,cend=0; struct timeval start,end; int subtime = 0; double totsubtime=0.0; setup_params_t *setup = NULL; ibe_keypair_t *ibk[MAXASPATHLEN]; //one key per as ibe_signature_t *signature[MAXPFIXNUM]; //one aggregated signature per prefix time_t tstamps[(MAXASPATHLEN+1)*MAXPFIXNUM]; time_t rsatstamps[(MAXASPATHLEN+1)*MAXPFIXNUM]; size_t vlen[MAXASPATHLEN +1]; //RSA struct rsa_public_key **rsa_pub = NULL; struct rsa_private_key **rsa_priv = NULL; mpz_t *vsign = NULL; long int nonces[MAXPFIXNUM*MAXPFIXLEN]; int rsadatalen =sizeof(time_t) + 2*sizeof(uint32_t)+ sizeof(long int) + sizeof(uint8_t) + sizeof(in_addr_t); while ((c=getopt (argc,argv,"a:p:")) != -1) { switch(c) { case 'a': aspathlen = strtol(optarg, NULL, 10); if(aspathlen > MAXASPATHLEN) { die("The specified aspathlen execeed MAXASPATHLEN(%d)\n",MAXASPATHLEN); } break; case 'p': pfixnum = strtol(optarg, NULL, 10); if(pfixnum > MAXPFIXNUM) { die("The specified pfixnum execeed MAXPFIXNUM(%d)\n",MAXPFIXNUM); } break; default: die("Invalid input option\n Aborting.\n"); } } rv = setup_load (ca[0],ca[1],ca[2],&setup); if(rv < 0) die("Cannot initialize setup\n Aborting. \n"); //initialize IBE structures bzero(ibk,MAXASPATHLEN*sizeof(ibe_keypair_t *)); bzero(signature,MAXPFIXNUM*sizeof(ibe_signature_t *)); bzero(&tstamps,MAXASPATHLEN*MAXPFIXNUM * sizeof(time_t)); bzero(&rsatstamps,MAXASPATHLEN*MAXPFIXNUM * sizeof(time_t)); rv = create_aslist(&ibk[0],setup); if(rv < 0) die("create_aslist"); msga = (uint8_t **) malloc((MSG_NUM)* sizeof(uint8_t*)); if(!msga) { die("malloc msga :: %s",strerror(errno)); } for(i=0; i < MSG_NUM; i++) { pmsga = (uint8_t * ) malloc(MAX_VRFY_LEN); if(!pmsga) { die("malloc msga[%d] :: %s",i,strerror(errno)); } bzero(pmsga,MAX_VRFY_LEN); msga[i] = pmsga; } vlen[0] = 9; for(i = 1; i < (MSG_NUM);i++){ vlen[i] = datalen; } //initialize RSA structures bzero(&nonces,MAXASPATHLEN*MAXPFIXNUM * sizeof(long int)); rsa_pub = (struct rsa_public_key **) malloc((MSG_NUM)* sizeof(struct rsa_public_key *)); rsa_priv = (struct rsa_private_key **)malloc((MSG_NUM) * sizeof(struct rsa_private_key *)) ; if(!rsa_pub || ! rsa_priv) die("init_rsa_array :: %s\n",strerror(errno)); init_rsa_array(rsa_pub,rsa_priv); vsign = (mpz_t *) malloc(sizeof(mpz_t) * MSG_NUM * pfixnum); if(!vsign) die("init_rsa_sign() :: %s\n",strerror(errno)); //----------------- Timing goes here ----------------- //create the verification message //aggregate the signature to assigned prefixes (by AS1) //for AS2 to ASn-1 pmsg = smsg = &upvrfy[0]; //printf("#TEST SUMMARY\n"); //printf("#AS path length:%6d\n",aspathlen); //printf("#Number of prefixes:%2d\n",pfixnum); printf("%d %d ",aspathlen,pfixnum); //printf("=======================================\n"); //printf("====== IBE SIGNATURE TIMING TEST ======\n"); //printf("=======================================\n"); //for each as gettimeofday(&start,NULL); //cstart = clock(); for(j = 0 ; j < (aspathlen-1); j++ ){ //for each prefix for(i = 0; i < pfixlist->size; i++) { //generate the current timestamp (for prefix + as couple) tstamps[j*pfixnum + i] = time(NULL); //update the verification message memcpy(pmsg,&tstamps[j*pfixnum + i],sizeof(time_t)); pmsg+=sizeof(time_t); memcpy(pmsg,&ibk[j]->id->asnum,sizeof(uint32_t)); //pmsg+=sizeof(ibk[j]->id->asnum); pmsg+=sizeof(uint32_t); memcpy(pmsg,&ibk[j+1]->id->asnum,sizeof(uint32_t)); //pmsg+=sizeof(ibk[j+1]->id->asnum); pmsg+=sizeof(uint32_t); //aggregate signature to prefixes ibe_sign(pfixlist->pf_sign[i],ibk[j],(const uint8_t * )smsg,pmsg-smsg); //printf(">> %d %d %d\n",tstamps[j*pfixnum + i],ibk[j]->id->asnum,ibk[j+1]->id->asnum); //print_msg(smsg); smsg = pmsg; } } //cend = clock(); gettimeofday(&end,NULL); print_avg_time(start,end,(aspathlen-1)); //print_time_clock(cstart,cend); //printf("=======================================\n"); //printf("====== RSA SIGNATURE TIMING TEST ======\n"); //printf("=======================================\n"); //for each as pmsg = smsg = &rsaupvrfy[0]; gettimeofday(&start,NULL); //cstart = clock(); for(j = 0 ; j < (aspathlen-1); j++ ){ //for each prefix for(i = 0; i < pfixlist->size; i++) { //add some randomness nonces[j*pfixnum +i] = random(); memcpy(pmsg,&nonces[j*pfixnum + i],sizeof(long int)); pmsg+=sizeof(long int); //generate the current timestamp (for prefix + as couple) rsatstamps[j*pfixnum + i] = time(NULL); //update the verification message memcpy(pmsg,&rsatstamps[j*pfixnum + i],sizeof(time_t)); pmsg+=sizeof(time_t); memcpy(pmsg,&ibk[j]->id->asnum,sizeof(uint32_t)); pmsg+=sizeof(uint32_t); memcpy(pmsg,&ibk[j+1]->id->asnum,sizeof(uint32_t)); pmsg+=sizeof(uint32_t); memcpy(pmsg,&pfixlist->ina[i].s_addr,sizeof(in_addr_t)); pmsg+=sizeof(struct in_addr); memcpy(pmsg,&pfixlist->netmask[i],sizeof(uint8_t)); pmsg+=sizeof(uint8_t); //sign prefix rsa_sign_msg(rsa_priv[j],vsign[j*pfixnum +i],(uint8_t * )smsg,pmsg-smsg); smsg = pmsg; } } //cend = clock(); gettimeofday(&end,NULL); print_avg_time(start,end,(aspathlen-1)); //print_time(start,end); //print_time_clock(cstart,cend); //printf("==========================================\n"); //printf("====== IBE VERIFICATION TIMING TEST ======\n"); //printf("==========================================\n"); pmsg = smsg = &upvrfy[0]; gettimeofday(&start,NULL); //cstart = clock(); //----------------- Timing goes here ----------------- for(i=0; i < pfixlist->size; i++) { //build array of messages build_msg_array(msga,smsg,tstamps,i,setup); //verfy aggregated message rv = ibe_vrfy(pfixlist->pf_sign[i],setup,(const uint8_t **)msga,vlen,&subtime); if(rv != SIGN_VALID) printf("Invalid signature :( \n");; //aggregate signature (by ASn) smsg+=datalen; totsubtime +=subtime; } //cend = clock(); gettimeofday(&end,NULL); print_time_sub(start,end,totsubtime); //print_time_clock(cstart,cend); //printf("==========================================\n"); //printf("====== RSA VERIFICATION TIMING TEST ======\n"); //printf("==========================================\n"); //start = clock(); gettimeofday(&start,NULL); //cstart = clock(); int z = 0; while(z < 2) { pmsg = smsg = &rsaupvrfy[0]; //----------------- Timing goes here ----------------- for(j = 0 ; j < (aspathlen-1); j++ ){ for(i=0; i < pfixlist->size; i++) { //vrfy rsa signature rv = rsa_vrfy_msg(rsa_pub[j],vsign[j*pfixnum +i],smsg,rsadatalen); if(rv != SIGN_VALID) printf("Invalid signature :( \n");; //go to next message smsg+=rsadatalen; } } z++; } //cend = clock(); gettimeofday(&end,NULL); print_time(start,end); //print_time_clock(cstart,cend); printf("\n"); //cleanup for(i = 0; i < MAXASPATHLEN ; i++) { ibe_keypair_clear(ibk[i]); } for(i=0; i < MAXASPATHLEN; i++) { if(msga[i]) free(msga[i]); } free(msga); return 0; }
int main() { int rv = 0,res =0,i = 0,j=0; char *ca[] = {"key.pub","key.prv","key.par"}; char *glb[] = {"gbl.act","gbl.rvk"}; char *epoch[] = {"epc.act","epc.rvk"}; char *facc = "last.acc"; char fname[MAX_ENVEL_NAME]; setup_params_t *setup = NULL; epoch_item_t *ep = NULL; id_list_t *actls= NULL, *rvkls = NULL; action_data_t *join = NULL; rv = setup_load (ca[0],ca[1],ca[2],&setup); if(rv < 0) pbgp_die("Cannot initialize setup\n Aborting. \n"); //genera epoca rv = claim_new_epoch(glb,epoch,facc,"last.epc",setup); if(rv < 0) pbgp_die("Cannot claim a new epoch\n"); rv = newepoch_init(&ep,setup); if(rv < 0) { pbgp_die("claim_new_init :: Cannot complete initialization process\n"); } rv = ids_init(&ep->epls.act,&ep->epls.rvk); if(rv < 0) { pbgp_die("ids_init :: Cannot create lists\n"); } rv = newepoch_load("last.epc",ep,setup); if(rv < 0) { pbgp_die("\n"); } //da usare per caricare i nomi dei file ids_init(&actls,&rvkls); ids_load(glb[0],actls); ids_load(glb[1],rvkls); join_init(&join,setup,NULL); if(join == NULL) pbgp_die("join is null. Abort."); printf("ACTIVE USER TEST:\n"); for(i=0; i < actls->size ; i++) { char *idstr = NULL; //carica join elem sprintf(fname,"id-%d.env",actls->head[i].asnum); join_load(fname,join); id_to_string(&idstr, join->ibk->id); printf("Verifying %s\n",idstr); id_to_string_clear(idstr); //update the witness witness_update(join->witness,join->ibk->id,setup, ep->epls.act,ep->epls.rvk); //check the presence of the AS into the accumulator rv = revokation_check(ep->acc,join->witness,join->signature, join->ibk->id->asnum,setup); //check the prefix list signatures TODO!!!!! aaggiusta sto codice -.- for(j=0; j < join->pfixlist->size; j++) { const uint8_t *buf_ina = (const uint8_t *) &join->pfixlist->ina[j]; size_t sina[1]; char as[40]; inet_net_ntop (AF_INET, &join->pfixlist->ina[j], join->pfixlist->netmask[j],as, 40); //sina[0] = sizeof(join->pfixlist->ina[j]); uint8_t to_vrfy[1][9]; uint8_t *p = to_vrfy; bzero(p,9); SERIALIZE_AUTH(p,&join->pfixlist->ina[j],&join->pfixlist->netmask[j],&join->pfixlist->tsca); sina[0] = 9; res = ibe_vrfy(join->pfixlist->pf_sign[j], setup,(const uint8_t **)&p,sina,NULL); if(res == SIGN_VALID) printf("The signature is valid! (%s)\n",as); else printf("Invalid signature :( \n"); } if(rv != 0) { pbgp_error("revokation_check :: %d have been revoked!\n",join->ibk->id->asnum); rv = -1; } else { printf("SUCCESS: User %d is still into the accumulator\n",join->ibk->id->asnum); join_save(join); } pfix_clear(join->pfixlist); } join_clear(join); // verifica che i revocati non sono nell'accumulatore join_init(&join,setup,NULL); if(join == NULL) pbgp_die("join is null. Abort."); printf("REVOKED USER TEST:\n"); for(i=0; i < rvkls->size ; i++) { char *idstr = NULL; //carica join elem sprintf(fname,"id-%d.env",rvkls->head[i].asnum); join_load(fname,join); id_to_string(&idstr, join->ibk->id); printf("Verifying %s\n",idstr); //aggiorna il witness witness_update(join->witness,join->ibk->id,setup, ep->epls.act,ep->epls.rvk); rv = revokation_check(ep->acc,join->witness,join->signature, join->ibk->id->asnum,setup); if(rv != 0) { pbgp_error("revokation_check :: %d have been revoked!\n",join->ibk->id->asnum); rv = -1; } else { printf("SUCCESS: User %d is still into the accumulator\n",join->ibk->id->asnum); join_save(join); } id_to_string_clear(idstr); } join_clear(join); ids_clear(actls,rvkls); setup_clear(setup); return 0; }
/* * action [join|revoke] * ip netmask [asnum] * file epoch {.rvk,.act} without extension * file global {.rvk.act} without extension * file setup keypair{.priv,.pub,.par} */ int main(int argc, char **argv) { int rv = 0; int c = 0; int action = -1; char *ca[] = {"key.pub","key.prv","key.par"}; char *glb[] = {"gbl.act","gbl.rvk"}; char *epoch[] = {"epc.act","epc.rvk"}; char *pfixstr = NULL; //struct sockaddr_in prefix,netmask; setup_params_t *setup = NULL; ibeid_t id; prefls_t *pfixlist = NULL; memset(&id,0,sizeof(ibeid_t)); while ((c=getopt (argc,argv,"p:a:i:egkrj::")) != -1) { switch(c) { case 'p': //ip prefix (ex: 10.0.1.0/24,11.0.0.0/8) pfixstr = malloc(strlen(optarg)); if(!pfixstr) pbgp_die("malloc %s\n",strerror(errno)); memcpy(pfixstr,optarg,strlen(optarg)); break; case 'i': //as number if(optarg) id.asnum = strtol(optarg, NULL, 10); break; case 'e': //epoch filename prefix pbgp_die("Option not implemented yet\n"); break; case 'g': //global filename prefix pbgp_die("Option not implemented yet\n"); break; case 'k': //ca keypair filename prefix pbgp_die("Option not implemented yet\n"); break; case 'r': if(action <0) action = REVOKE; else { print_usage(); pbgp_die("JOIN and REVOKE options are mutually exclusive\n"); } break; case 'j': if ( action < 0) action = JOIN; else { print_usage(); pbgp_die("JOIN and REVOKE options are mutually exclusive\n"); } break; //TODO: addprefix option case 'a': pbgp_die("Option not implemented yet\n"); break; default: print_usage(); pbgp_die("%c is not a valid option\n",c); } } if(action != JOIN && action != REVOKE && action != ADDPREFIX) { print_usage(); pbgp_die("You must specify a valid action to take (join or revoke)\n"); } rv = setup_load (ca[0],ca[1],ca[2],&setup); if(rv < 0) pbgp_die("setup_load failed, cannot proceed\n"); if(pfixstr) { rv = parse_prefix_list(&pfixlist,pfixstr,setup); free(pfixstr); if(rv < 0) pbgp_die("parse_prefix_list failed, cannot proceed (%s)\n",strerror(errno)); } switch(action) { case JOIN: printf(" ****** Join action called ****** \n"); rv = join_action(glb,epoch,setup,&id,pfixlist); if(rv < 0) { pbgp_error("Error during join: %s\n",strerror(errno)); } break; case REVOKE: printf(" ****** Revoke action called ****** \n"); if(id.asnum <= 0) { pbgp_die("You must specify the asnum option for revokation\n"); } revoke_action(glb,epoch,setup,&id); break; case ADDPREFIX: //TODO break; } setup_clear(setup); return 0; }