13 assert(random != NULL);
14 static const int c = 25;
17 mpz_inits(p, q, r, t1, NULL);
18 int q_composite, r_composite;
23 mpz_fdiv_q_ui(q, t1, 2);
30 q_composite = mpz_probab_prime_p(q, c) == 0;
31 r_composite = mpz_probab_prime_p(r, c) == 0;
32 }
while (q_composite && r_composite);
34 mpz_set(out, q_composite ? r : p);
36 mpz_clears(p, q, r, t1, NULL);
45 assert(bit_size >= 512 && bit_size <= 8192);
48 assert(l / 2 + 1 <= k);
53 static const int F4 = 65537;
55 size_t prime_size = bit_size / 2;
57 mpz_t pr, qr, p, q, d, e, ll, m, n, delta_inv, divisor, r, vk_v, vk_u, s_i, vk_i;
58 mpz_inits(pr, qr, p, q, d, e, ll, m, n, delta_inv, divisor, r, vk_v, vk_u, s_i, vk_i, NULL);
65 mpz_fdiv_q_ui(pr, pr, 2);
69 mpz_fdiv_q_ui(qr, qr, 2);
79 if (public_e != NULL) {
81 if (mpz_probab_prime_p(e, 25) && mpz_cmp(ll, e) < 0) {
98 mpz_gcd(divisor, r, n);
99 }
while (mpz_cmp_ui(divisor, 1) != 0);
100 mpz_powm_ui(vk_v, r, 2, n);
106 mpz_mod(vk_u, vk_u, n);
107 }
while (mpz_jacobi(vk_u, n) != -1);
111 mpz_fac_ui(delta_inv, l);
112 mpz_invert(delta_inv, delta_inv, m);
118 for(
int i=1; i <= info->
l; i++) {
123 mpz_mul(s_i, s_i, delta_inv);
124 mpz_mod(s_i, s_i, m);
129 mpz_powm(vk_i, vk_v, s_i, n);
134 mpz_clears(pr, qr, p, q, d, e, ll, m, n, delta_inv, divisor, r, vk_v, vk_u, s_i, vk_i, NULL);
138 for (
int i = 0; i < info->
l; i++) {
139 assert(ks[i] != NULL);
142 assert(*out != NULL);
#define TC_ID_TO_INDEX(id)
void random_prime(mpz_t rop, int bit_len, random_fn random)
void generate_safe_prime(mpz_t out, int bit_len, random_fn random)
Structure that's stores a pointer that points to data_len bytes.
void random_dev(mpz_t rop, int bit_len)
void(* random_fn)(mpz_t rop, int bit_len)
key_metainfo_t * tc_init_key_metainfo(uint16_t k, uint16_t l)
#define TC_BYTES_TO_MPZ(z, bytes)
Structure that represents one key share, to be used to generate a signature share.
void clear_poly(poly_t *poly)
key_share_t ** tc_generate_keys(key_metainfo_t **out, size_t bit_size, uint16_t k, uint16_t l, bytes_t *public_e)
poly_t * create_random_poly(mpz_t d, size_t size, mpz_t m)
void poly_eval_ui(mpz_t rop, poly_t *poly, unsigned long op)
#define TC_MPZ_TO_BYTES(bytes, z)
key_share_t ** tc_init_key_shares(key_metainfo_t *info)