static size_t gf32m_out_str(FILE *stream, int base, element_t e) { UNUSED_VAR(base); element_ptr e0 = GF32M(e)->_0, e1 = GF32M(e)->_1; size_t size = 0; size += element_out_str(stream, base, e0); size += element_out_str(stream, base, e1); return size; }
static size_t point_out_str(FILE *stream, int base, element_ptr a) { point_ptr p = DATA(a); size_t size = 0; if (p->isinf) return fprintf(stream, "O"); else { size += element_out_str(stream, base, p->x); size += element_out_str(stream, base, p->y); return size; } }
static size_t fq_out_str(FILE *stream, int base, element_ptr e) { size_t result = 4, status; eptr p = e->data; if (EOF == fputc('[', stream)) return 0; result = element_out_str(stream, base, p->x); if (!result) return 0; if (EOF == fputs(", ", stream)) return 0; status = element_out_str(stream, base, p->y); if (!status) return 0; if (EOF == fputc(']', stream)) return 0; return result + status; }
void BroadcastKEM_using_product(global_broadcast_params_t gbp, broadcast_system_t sys, ct_t myct, element_t key) { if(!gbp) { printf("ACK! You gave me no broadcast params! I die.\n"); return; } if(!sys) { printf("ACK! You gave me no broadcast system! I die.\n"); return; } if(!myct) { printf("ACK! No struct to store return vals! I die.\n"); return; } element_t t; element_init_Zr(t, gbp->pairing); element_random(t); element_init(key, gbp->pairing->GT); element_init(myct->C0, gbp->pairing->G2); element_init(myct->C1, gbp->pairing->G1); //COMPUTE K element_pairing(key, gbp->gs[gbp->num_users-1], gbp->gs[0]); element_pow_zn(key, key, t); //COMPUTE C0 element_pow_zn(myct->C0, gbp->g, t); //COMPUTE C1 if(DEBUG && 0) { printf("\npub_key = "); element_out_str(stdout, 0, sys->pub_key); printf("\nencr_prod = "); element_out_str(stdout, 0, sys->encr_prod); } element_mul(myct->C1, sys->pub_key, sys->encr_prod); if(DEBUG && 0) { printf("\npub_key = "); element_out_str(stdout, 0, sys->pub_key); printf("\nencr_prod = "); element_out_str(stdout, 0, sys->encr_prod); printf("\nhdr_c1 = "); element_out_str(stdout, 0, myct->C1); printf("\n"); } element_pow_zn(myct->C1, myct->C1, t); element_clear(t); }
static size_t sn_out_str(FILE *stream, int base, element_ptr a) { point_ptr p = a->data; size_t result, status; if (p->inf_flag) { if (EOF == fputc('O', stream)) return 0; return 1; } result = element_out_str(stream, base, p->x); if (!result) return 0; if (EOF == fputc(' ', stream)) return 0; status = element_out_str(stream, base, p->y); if (!status) return 0; return result + status + 1; }
static size_t curve_out_str(FILE *stream, int base, element_ptr a) { point_ptr p = (point_ptr)a->data; size_t result, status; if (p->inf_flag) { if (EOF == fputc('O', stream)) return 0; return 1; } if (EOF == fputc('[', stream)) return 0; result = element_out_str(stream, base, p->x); if (!result) return 0; if (EOF == fputs(", ", stream)) return 0; status = element_out_str(stream, base, p->y); if (!status) return 0; if (EOF == fputc(']', stream)) return 0; return result + status + 4; }
void element_string_to_file(element_t element, char* outputFile){ FILE* fp_element = fopen(outputFile, "w"); element_out_str(fp_element, 10, element); fclose( fp_element ); }
void BroadcastKEM_using_indicies(global_broadcast_params_t gbp, broadcast_system_t sys, ct_t myct, int *in_recip, int num_recip, element_t key) { Gen_encr_prod_from_indicies(gbp, sys, in_recip, num_recip); if(DEBUG && 0) { printf("index product = "); element_out_str(stdout, 0, sys->encr_prod); printf("\n"); } BroadcastKEM_using_product(gbp, sys, myct, key); }
void BroadcastKEM_using_bitvec(global_broadcast_params_t gbp, broadcast_system_t sys, char *recip, ct_t myct, element_t key) { Gen_encr_prod_from_bitvec(gbp, sys, recip); if(DEBUG && 0) { printf("bitvec product = "); element_out_str(stdout, 0, sys->encr_prod); printf("\n"); } BroadcastKEM_using_product(gbp, sys, myct, key); }
static size_t mulg_out_str(FILE *stream, int base, element_ptr e) { return element_out_str(stream, base, e->data); }
static void v_elem_out(FILE* stream, val_ptr v) { element_out_str(stream, 0, v->elem); }
int main(void){ pairing_t pairing; element_t g, h, f, beta, beta_inverse; char s[16384]; signed long int temp_share; FILE *fp = stdin; fp = fopen("../public/a.param", "r"); if (!fp) pbc_die("error opening parameter file", "r"); size_t count = fread(s, 1, 16384, fp); if(!count) pbc_die("read parameter failure\n"); fclose(fp); if(pairing_init_set_buf(pairing, s, count)) pbc_die("pairing init failed\n"); if(!pairing_is_symmetric(pairing)) pbc_die("pairing is not symmetric\n"); element_init_G1(g, pairing); element_init_G1(h, pairing); element_init_G1(f, pairing); element_init_Zr(beta, pairing); element_init_Zr(beta_inverse, pairing); //(G1, g, h, f) is the public key of authorizer //find the generator of the group element_set(g, ((curve_data_ptr)((a_pairing_data_ptr)\ pairing->data)->Eq->data)->gen); element_random(beta); element_invert(beta_inverse, beta); //h = g^beta element_pow_zn(h, g, beta); //f = g^(1/beta) element_pow_zn(f, g, beta_inverse); fp = NULL; fp = fopen("./authorizer_public_keys.txt", "w+"); if(!fp) pbc_die("error creating public key files"); else{ fprintf(fp, "g:"); element_out_str(fp, 10, g); fprintf(fp, "\n\nh:"); element_out_str(fp, 10, h); fprintf(fp, "\n\nf:"); element_out_str(fp, 10, f); fclose(fp); } fp = fopen("./authorizer_secret_key.txt", "w+"); if(!fp) pbc_die("error creating secret key files"); else{ fprintf(fp, "beta:"); element_out_str(fp, 10, beta); } element_clear(g); element_clear(h); element_clear(f); element_clear(beta); element_clear(beta_inverse); return 1; }