status_t element_init_G2(element_t e) { g2_inits(e->g2); g2_set_infty(e->g2); bn_inits(e->order); g2_get_ord(e->order); e->isInitialized = TRUE; e->type = G2; return ELEMENT_OK; }
int element_is_member(element_t e) { LEAVE_IF(e->isInitialized != TRUE, "uninitialized argument."); int result; if(e->type == ZR) { if(bn_cmp(e->bn, e->order) <= CMP_EQ) result = TRUE; else result = FALSE; } else if(e->type == G1) { g1_t r; g1_inits(r); g1_mul(r, e->g1, e->order); if(g1_is_infty(r) == 1) result = TRUE; else result = FALSE; g1_free(r); } else if(e->type == G2) { g2_t r; g2_inits(r); g2_mul(r, e->g2, e->order); if(g2_is_infty(r) == 1) result = TRUE; else result = FALSE; g2_free(r); } else if(e->type == GT) { gt_t r; gt_inits(r); gt_exp(r, e->gt, e->order); if(gt_is_unity(r) == 1) result = TRUE; else result = FALSE; gt_free(r); } else { result = ELEMENT_INVALID_ARG; } return result; }
status_t element_pp_init(element_pp_t e_pp, element_t e) { int i; if(e_pp->isInitialized == TRUE) return ELEMENT_INITIALIZED_ALRDY; if(e->isInitialized == FALSE) return ELEMENT_UNINITIALIZED; if(e->type == G1) { e_pp->t1 = malloc(sizeof(g1_t) * G1_TABLE); for (i = 0; i < G1_TABLE; i++) { g1_inits(e_pp->t1[i]); } /* compute the pre-computation table */ g1_mul_pre(e_pp->t1, e->g1); } else if(e->type == G2) { e_pp->t2 = malloc(sizeof(g2_t) * G2_TABLE); for (i = 0; i < G2_TABLE; i++) { g2_inits(e_pp->t2[i]); } /* compute the pre-computation table */ g2_mul_pre(e_pp->t2, e->g2); } e_pp->isInitialized = TRUE; return ELEMENT_OK; }