code
stringlengths
31
2.05k
label_name
stringclasses
5 values
label
int64
0
4
void ed_mul_sim_lot(ed_t r, const ed_t p[], const bn_t k[], int n) { int i, j, l, *_l = RLC_ALLOCA(int, n); ed_t *_p = RLC_ALLOCA(ed_t, n); int8_t *naf = NULL; RLC_TRY { l = 0; for (i = 0; i < n; i++) { l = RLC_MAX(l, bn_bits(k[i]) + 1); } naf = RLC_ALLOCA(int8_t, n * l); if (naf == NULL || _p == NULL...
Base
1
void ed_mul_sim_joint(ed_t r, const ed_t p, const bn_t k, const ed_t q, const bn_t m) { ed_t t[5]; int i, l, u_i, offset; int8_t jsf[2 * (RLC_FP_BITS + 1)]; if (bn_is_zero(k) || ed_is_infty(p)) { ed_mul(r, q, m); return; } if (bn_is_zero(m) || ed_is_infty(q)) { ed_mul(r, p, k); return; } RLC_TRY { ...
Base
1
static void ed_mul_sim_plain(ed_t r, const ed_t p, const bn_t k, const ed_t q, const bn_t m, const ed_t *t) { int i, l, l0, l1, n0, n1, w, gen; int8_t naf0[RLC_FP_BITS + 1], naf1[RLC_FP_BITS + 1], *_k, *_m; ed_t t0[1 << (ED_WIDTH - 2)]; ed_t t1[1 << (ED_WIDTH - 2)]; RLC_TRY { gen = (t == NULL ? 0 : 1); if (...
Base
1
void ed_mul_sim_trick(ed_t r, const ed_t p, const bn_t k, const ed_t q, const bn_t m) { ed_t t0[1 << (ED_WIDTH / 2)], t1[1 << (ED_WIDTH / 2)], t[1 << ED_WIDTH]; bn_t n; int l0, l1, w = ED_WIDTH / 2; uint8_t w0[RLC_FP_BITS + 1], w1[RLC_FP_BITS + 1]; bn_null(n); if (bn_is_zero(k) || ed_is_infty(p)) { ed_mul(r...
Base
1
void ed_read_bin(ed_t a, const uint8_t *bin, int len) { if (len == 1) { if (bin[0] == 0) { ed_set_infty(a); return; } else { RLC_THROW(ERR_NO_BUFFER); return; } } if (len != (RLC_FP_BYTES + 1) && len != (2 * RLC_FP_BYTES + 1)) { RLC_THROW(ERR_NO_BUFFER); return; } a->coord = BASIC; fp_set_...
Base
1
void ed_write_bin(uint8_t *bin, int len, const ed_t a, int pack) { ed_t t; ed_null(t); memset(bin, 0, len); if (ed_is_infty(a)) { if (len < 1) { RLC_THROW(ERR_NO_BUFFER); return; } else { return; } } RLC_TRY { ed_new(t); ed_norm(t, a); if (pack) { if (len < RLC_FP_BYTES + 1) { RL...
Base
1
void ep_map_dst(ep_t p, const uint8_t *msg, int len, const uint8_t *dst, int dst_len) { /* enough space for two field elements plus extra bytes for uniformity */ const int len_per_elm = (FP_PRIME + ep_param_level() + 7) / 8; uint8_t *pseudo_random_bytes = RLC_ALLOCA(uint8_t, 2 * len_per_elm); RLC_TRY { /* for...
Base
1
void ep_map(ep_t p, const uint8_t *msg, int len) { ep_map_dst(p, msg, len, (const uint8_t *)"RELIC", 5); }
Base
1
static void ep_mul_naf_imp(ep_t r, const ep_t p, const bn_t k) { int i, l; /* Some of the supported prime curves have order > field. */ int8_t u, naf[RLC_FP_BITS + 2]; ep_t t[1 << (EP_WIDTH - 2)]; bn_t _k, n; bn_null(n); bn_null(_k); RLC_TRY { bn_new(n); bn_new(_k); /* Prepare the precomputation table. ...
Base
1
void ep_mul_slide(ep_t r, const ep_t p, const bn_t k) { bn_t _k, n; ep_t t[1 << (EP_WIDTH - 1)], q; int i, j, l; uint8_t win[RLC_FP_BITS + 1]; if (bn_is_zero(k) || ep_is_infty(p)) { ep_set_infty(r); return; } ep_null(q); bn_null(n); bn_null(_k); RLC_TRY { bn_new(n); bn_new(_k); for (i = 0; i < (1...
Base
1
void ep_mul_monty(ep_t r, const ep_t p, const bn_t k) { int i, j, bits; ep_t t[2]; bn_t n, l, _k; bn_null(n); bn_null(l); bn_null(_k); ep_null(t[0]); ep_null(t[1]); if (bn_is_zero(k) || ep_is_infty(p)) { ep_set_infty(r); return; } RLC_TRY { bn_new(n); bn_new(l); bn_new(_k); ep_new(t[0]); ep_...
Base
1
void ep_mul_dig(ep_t r, const ep_t p, dig_t k) { ep_t t; bn_t _k; int8_t u, naf[RLC_DIG + 1]; int l; ep_null(t); bn_null(_k); if (k == 0 || ep_is_infty(p)) { ep_set_infty(r); return; } RLC_TRY { ep_new(t); bn_new(_k); bn_set_dig(_k, k); l = RLC_DIG + 1; bn_rec_naf(naf, &l, _k, 2); ep_set_...
Base
1
static void ep_mul_glv_imp(ep_t r, const ep_t p, const bn_t k) { int l, l0, l1, i, n0, n1, s0, s1; int8_t naf0[RLC_FP_BITS + 1], naf1[RLC_FP_BITS + 1], *t0, *t1; bn_t n, _k, k0, k1, v1[3], v2[3]; ep_t q, t[1 << (EP_WIDTH - 2)]; bn_null(n); bn_null(_k); bn_null(k0); bn_null(k1); ep_null(q); RLC_TRY { bn_ne...
Base
1
static void ep_mul_reg_imp(ep_t r, const ep_t p, const bn_t k) { bn_t _k; int i, j, l, n; int8_t s, reg[1 + RLC_CEIL(RLC_FP_BITS + 1, EP_WIDTH - 1)]; ep_t t[1 << (EP_WIDTH - 2)], u, v; if (bn_is_zero(k)) { ep_set_infty(r); return; } bn_null(_k); RLC_TRY { bn_new(_k); ep_new(u); ep_new(v); /* Prep...
Base
1
static void ep_mul_fix_plain(ep_t r, const ep_t *t, const bn_t k) { int l, i, n; int8_t naf[RLC_FP_BITS + 1]; /* Compute the w-TNAF representation of k. */ l = RLC_FP_BITS + 1; bn_rec_naf(naf, &l, k, EP_DEPTH); n = naf[l - 1]; if (n > 0) { ep_copy(r, t[n / 2]); } else { ep_neg(r, t[-n / 2]); } for (i =...
Base
1
static void ep_mul_sim_plain(ep_t r, const ep_t p, const bn_t k, const ep_t q, const bn_t m, const ep_t *t) { int i, l, l0, l1, w, gen; int8_t naf0[RLC_FP_BITS + 1], naf1[RLC_FP_BITS + 1], n0, n1, *u, *v; ep_t t0[1 << (EP_WIDTH - 2)]; ep_t t1[1 << (EP_WIDTH - 2)]; RLC_TRY { gen = (t == NULL ? 0 : 1); if (!g...
Base
1
void ep_mul_sim_joint(ep_t r, const ep_t p, const bn_t k, const ep_t q, const bn_t m) { bn_t n, _k, _m; ep_t t[5]; int i, l, u_i, offset; int8_t jsf[2 * (RLC_FP_BITS + 1)]; if (bn_is_zero(k) || ep_is_infty(p)) { ep_mul(r, q, m); return; } if (bn_is_zero(m) || ep_is_infty(q)) { ep_mul(r, p, k); return;...
Base
1
void ep_mul_sim_trick(ep_t r, const ep_t p, const bn_t k, const ep_t q, const bn_t m) { ep_t t0[1 << (EP_WIDTH / 2)], t1[1 << (EP_WIDTH / 2)], t[1 << EP_WIDTH]; bn_t n, _k, _m; int l0, l1, w = EP_WIDTH / 2; uint8_t w0[RLC_FP_BITS + 1], w1[RLC_FP_BITS + 1]; if (bn_is_zero(k) || ep_is_infty(p)) { ep_mul(r, q, m...
Base
1
void ep_mul_sim_lot_plain(ep_t r, const ep_t p[], const bn_t k[], int n) { int i, j, l, *_l = RLC_ALLOCA(int, n); ep_t *_p = RLC_ALLOCA(ep_t, n); int8_t *naf = NULL; RLC_TRY { l = 0; for (i = 0; i < n; i++) { l = RLC_MAX(l, bn_bits(k[i]) + 1); } naf = RLC_ALLOCA(int8_t, n * l); if (naf == NULL || _p =...
Base
1
void ep_write_bin(uint8_t *bin, int len, const ep_t a, int pack) { ep_t t; ep_null(t); memset(bin, 0, len); if (ep_is_infty(a)) { if (len < 1) { RLC_THROW(ERR_NO_BUFFER); return; } else { return; } } RLC_TRY { ep_new(t); ep_norm(t, a); if (pack) { if (len < RLC_FP_BYTES + 1) { RL...
Base
1
void ep_read_bin(ep_t a, const uint8_t *bin, int len) { if (len == 1) { if (bin[0] == 0) { ep_set_infty(a); return; } else { RLC_THROW(ERR_NO_BUFFER); return; } } if (len != (RLC_FP_BYTES + 1) && len != (2 * RLC_FP_BYTES + 1)) { RLC_THROW(ERR_NO_BUFFER); return; } a->coord = BASIC; fp_set_...
Base
1
void ep2_map_dst(ep2_t p, const uint8_t *msg, int len, const uint8_t *dst, int dst_len) { /* enough space for two field elements plus extra bytes for uniformity */ const int len_per_elm = (FP_PRIME + ep_param_level() + 7) / 8; uint8_t *pseudo_random_bytes = RLC_ALLOCA(uint8_t, 4 * len_per_elm);...
Base
1
void ep2_map(ep2_t p, const uint8_t *msg, int len) { ep2_map_dst(p, msg, len, (const uint8_t *)"RELIC", 5); }
Base
1
void ep2_mul_dig(ep2_t r, const ep2_t p, const dig_t k) { ep2_t t; bn_t _k; int8_t u, naf[RLC_DIG + 1]; int l; ep2_null(t); bn_null(_k); if (k == 0 || ep2_is_infty(p)) { ep2_set_infty(r); return; } RLC_TRY { ep2_new(t); bn_new(_k); bn_set_dig(_k, k); l = RLC_DIG + 1; bn_rec_naf(naf, &l, _k, ...
Base
1
void ep2_mul_basic(ep2_t r, const ep2_t p, const bn_t k) { int i, l; ep2_t t; ep2_null(t); if (bn_is_zero(k) || ep2_is_infty(p)) { ep2_set_infty(r); return; } RLC_TRY { ep2_new(t); l = bn_bits(k); if (bn_get_bit(k, l - 1)) { ep2_copy(t, p); } else { ep2_set_infty(t); } for (i = l - 2; i...
Base
1
void ep2_mul_slide(ep2_t r, const ep2_t p, const bn_t k) { ep2_t t[1 << (EP_WIDTH - 1)], q; int i, j, l; uint8_t win[RLC_FP_BITS + 1]; ep2_null(q); if (bn_is_zero(k) || ep2_is_infty(p)) { ep2_set_infty(r); return; } RLC_TRY { for (i = 0; i < (1 << (EP_WIDTH - 1)); i ++) { ep2_null(t[i]); ep2_new(t...
Base
1
static void ep2_mul_naf_imp(ep2_t r, const ep2_t p, const bn_t k) { int l, i, n; int8_t naf[RLC_FP_BITS + 1]; ep2_t t[1 << (EP_WIDTH - 2)]; RLC_TRY { /* Prepare the precomputation table. */ for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep2_null(t[i]); ep2_new(t[i]); } /* Compute the precomputation ta...
Base
1
static void ep2_mul_glv_imp(ep2_t r, const ep2_t p, const bn_t k) { int i, j, l, _l[4]; bn_t n, _k[4], u; int8_t naf[4][RLC_FP_BITS + 1]; ep2_t q[4]; bn_null(n); bn_null(u); RLC_TRY { bn_new(n); bn_new(u); for (i = 0; i < 4; i++) { bn_null(_k[i]); ep2_null(q[i]); bn_new(_k[i]); ep2_new(q[i]);...
Base
1
static void ep2_mul_fix_plain(ep2_t r, const ep2_t *table, const bn_t k) { int len, i, n; int8_t naf[2 * RLC_FP_BITS + 1], *t; if (bn_is_zero(k)) { ep2_set_infty(r); return; } /* Compute the w-TNAF representation of k. */ len = 2 * RLC_FP_BITS + 1; bn_rec_naf(naf, &len, k, EP_DEPTH); t = naf + len - 1; ...
Base
1
static void ep2_mul_sim_plain(ep2_t r, const ep2_t p, const bn_t k, const ep2_t q, const bn_t m, const ep2_t *t) { int i, l, l0, l1, n0, n1, w, gen; int8_t naf0[2 * RLC_FP_BITS + 1], naf1[2 * RLC_FP_BITS + 1], *_k, *_m; ep2_t t0[1 << (EP_WIDTH - 2)]; ep2_t t1[1 << (EP_WIDTH - 2)]; RLC_TRY { gen = (t == NULL ?...
Base
1
void ep2_mul_sim_dig(ep2_t r, const ep2_t p[], const dig_t k[], int len) { ep2_t t; int max; ep2_null(t); max = util_bits_dig(k[0]); for (int i = 1; i < len; i++) { max = RLC_MAX(max, util_bits_dig(k[i])); } RLC_TRY { ep2_new(t); ep2_set_infty(t); for (int i = max - 1; i >= 0; i--) { ep2_dbl(t, t)...
Base
1
static void ep2_mul_sim_endom(ep2_t r, const ep2_t p, const bn_t k, ep2_t q, const bn_t m) { int i, j, l, _l[4]; bn_t _k[4], _m[4], n, u; int8_t naf0[4][RLC_FP_BITS + 1]; int8_t naf1[4][RLC_FP_BITS + 1]; ep2_t _p[4], _q[4]; bn_null(n); bn_null(u); RLC_TRY { bn_new(n); bn_new(u); for (i = 0; i < 4; i++...
Base
1
void ep2_mul_sim_joint(ep2_t r, const ep2_t p, const bn_t k, const ep2_t q, const bn_t m) { bn_t n, _k, _m; ep2_t t[5]; int i, l, u_i, offset; int8_t jsf[2 * (RLC_FP_BITS + 1)]; if (bn_is_zero(k) || ep2_is_infty(p)) { ep2_mul(r, q, m); return; } if (bn_is_zero(m) || ep2_is_infty(q)) { ep2_mul(r, p, k); ...
Base
1
void ep2_read_bin(ep2_t a, const uint8_t *bin, int len) { if (len == 1) { if (bin[0] == 0) { ep2_set_infty(a); return; } else { RLC_THROW(ERR_NO_BUFFER); return; } } if (len != (2 * RLC_FP_BYTES + 1) && len != (4 * RLC_FP_BYTES + 1)) { RLC_THROW(ERR_NO_BUFFER); return; } a->coord = BASIC; ...
Base
1
void ep2_write_bin(uint8_t *bin, int len, const ep2_t a, int pack) { ep2_t t; ep2_null(t); memset(bin, 0, len); if (ep2_is_infty(a)) { if (len < 1) { RLC_THROW(ERR_NO_BUFFER); return; } else { return; } } RLC_TRY { ep2_new(t); ep2_norm(t, a); if (pack) { if (len < 2 * RLC_FP_BYTES + ...
Base
1
void ep4_map(ep4_t p, const uint8_t *msg, int len) { bn_t x; fp4_t t0; uint8_t digest[RLC_MD_LEN]; bn_null(x); fp4_null(t0); RLC_TRY { bn_new(x); fp4_new(t0); md_map(digest, msg, len); bn_read_bin(x, digest, RLC_MIN(RLC_FP_BYTES, RLC_MD_LEN)); fp4_zero(p->x); fp_prime_conv(p->x[0][0], x); fp4_se...
Base
1
static void ep4_mul_naf_imp(ep4_t r, const ep4_t p, const bn_t k) { int l, i, n; int8_t naf[RLC_FP_BITS + 1]; ep4_t t[1 << (EP_WIDTH - 2)]; RLC_TRY { /* Prepare the precomputation table. */ for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) { ep4_null(t[i]); ep4_new(t[i]); } /* Compute the precomputation ta...
Base
1
static void ep4_mul_glv_imp(ep4_t r, const ep4_t p, const bn_t k) { int sign, i, j, l, _l[8]; bn_t n, _k[8], u, v; int8_t naf[8][RLC_FP_BITS + 1]; ep4_t q[8]; bn_null(n); bn_null(u); bn_null(v); RLC_TRY { bn_new(n); bn_new(u); bn_new(v); for (i = 0; i < 8; i++) { bn_null(_k[i]); ep4_null(q[i]); ...
Base
1
void ep4_mul_slide(ep4_t r, const ep4_t p, const bn_t k) { ep4_t t[1 << (EP_WIDTH - 1)], q; int i, j, l; uint8_t win[RLC_FP_BITS + 1]; ep4_null(q); if (bn_is_zero(k) || ep4_is_infty(p)) { ep4_set_infty(r); return; } RLC_TRY { for (i = 0; i < (1 << (EP_WIDTH - 1)); i ++) { ep4_null(t[i]); ep4_new(t...
Base
1
static void ep4_mul_pre_ordin(ep4_t *t, const ep4_t p) { int i; ep4_dbl(t[0], p); #if defined(EP_MIXED) ep4_norm(t[0], t[0]); #endif #if EP_DEPTH > 2 ep4_add(t[1], t[0], p); for (i = 2; i < (1 << (EP_DEPTH - 2)); i++) { ep4_add(t[i], t[i - 1], t[0]); } #if defined(EP_MIXED) for (i = 1; i < (1 << (EP_DEPTH -...
Base
1
static void ep4_mul_fix_ordin(ep4_t r, const ep4_t *table, const bn_t k) { int len, i, n; int8_t naf[2 * RLC_FP_BITS + 1], *t; if (bn_is_zero(k)) { ep4_set_infty(r); return; } /* Compute the w-TNAF representation of k. */ len = 2 * RLC_FP_BITS + 1; bn_rec_naf(naf, &len, k, EP_DEPTH); t = naf + len - 1; ...
Base
1
void ep4_mul_sim_trick(ep4_t r, const ep4_t p, const bn_t k, const ep4_t q, const bn_t m) { ep4_t t0[1 << (EP_WIDTH / 2)]; ep4_t t1[1 << (EP_WIDTH / 2)]; ep4_t t[1 << EP_WIDTH]; bn_t n; int l0, l1, w = EP_WIDTH / 2; uint8_t w0[2 * RLC_FP_BITS], w1[2 * RLC_FP_BITS]; bn_null(n); if (bn_is_zero(k) || ep4_is_in...
Base
1
void ep4_mul_sim_joint(ep4_t r, const ep4_t p, const bn_t k, const ep4_t q, const bn_t m) { ep4_t t[5]; int i, l, u_i, offset; int8_t jsf[4 * (RLC_FP_BITS + 1)]; if (bn_is_zero(k) || ep4_is_infty(p)) { ep4_mul(r, q, m); return; } if (bn_is_zero(m) || ep4_is_infty(q)) { ep4_mul(r, p, k); return; } RL...
Base
1
static void ep4_mul_sim_plain(ep4_t r, const ep4_t p, const bn_t k, const ep4_t q, const bn_t m, ep4_t *t) { int i, l, l0, l1, n0, n1, w, gen; int8_t naf0[2 * RLC_FP_BITS + 1], naf1[2 * RLC_FP_BITS + 1], *_k, *_m; ep4_t t0[1 << (EP_WIDTH - 2)]; ep4_t t1[1 << (EP_WIDTH - 2)]; RLC_TRY { gen = (t == NULL ? 0 : 1...
Base
1
void ep4_mul_sim_dig(ep4_t r, const ep4_t p[], const dig_t k[], int len) { ep4_t t; int max; ep4_null(t); max = util_bits_dig(k[0]); for (int i = 1; i < len; i++) { max = RLC_MAX(max, util_bits_dig(k[i])); } RLC_TRY { ep4_new(t); ep4_set_infty(t); for (int i = max - 1; i >= 0; i--) { ep4_dbl(t, t)...
Base
1
void ep4_write_bin(uint8_t *bin, int len, const ep4_t a, int pack) { ep4_t t; ep4_null(t); memset(bin, 0, len); if (ep4_is_infty(a)) { if (len < 1) { RLC_THROW(ERR_NO_BUFFER); return; } else { return; } } RLC_TRY { ep4_new(t); ep4_norm(t, a); if (len < 8 * RLC_FP_BYTES + 1) { RLC_THR...
Base
1
void ep4_read_bin(ep4_t a, const uint8_t *bin, int len) { if (len == 1) { if (bin[0] == 0) { ep4_set_infty(a); return; } else { RLC_THROW(ERR_NO_BUFFER); return; } } if (len != (8 * RLC_FP_BYTES + 1)) { RLC_THROW(ERR_NO_BUFFER); return; } a->coord = BASIC; fp4_set_dig(a->z, 1); fp4_read_b...
Base
1
void fb_exp_basic(fb_t c, const fb_t a, const bn_t b) { int i, l; fb_t r; if (bn_is_zero(b)) { fb_set_dig(c, 1); return; } fb_null(r); RLC_TRY { fb_new(r); l = bn_bits(b); fb_copy(r, a); for (i = l - 2; i >= 0; i--) { fb_sqr(r, r); if (bn_get_bit(b, i)) { fb_mul(r, r, a); } } i...
Base
1
void fb_exp_slide(fb_t c, const fb_t a, const bn_t b) { fb_t t[1 << (FB_WIDTH - 1)], r; int i, j, l; uint8_t win[RLC_FB_BITS + 1]; fb_null(r); if (bn_is_zero(b)) { fb_set_dig(c, 1); return; } /* Initialize table. */ for (i = 0; i < (1 << (FB_WIDTH - 1)); i++) { fb_null(t[i]); } RLC_TRY { for (i =...
Base
1
void fb_write_bin(uint8_t *bin, int len, const fb_t a) { bn_t t; bn_null(t); if (len != RLC_FB_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } RLC_TRY { bn_new(t); bn_read_raw(t, a, RLC_FB_DIGS); bn_write_bin(bin, len, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
Base
1
void fb_read_str(fb_t a, const char *str, int len, int radix) { bn_t t; bn_null(t); if (!valid_radix(radix)) { RLC_THROW(ERR_NO_VALID); } RLC_TRY { bn_new(t); bn_read_str(t, str, len, radix); if (bn_bits(t) > RLC_FB_BITS) { RLC_THROW(ERR_NO_BUFFER); } fb_zero(a); dv_copy(a, t->dp, t->used); ...
Base
1
static int log_radix(int radix) { int l = 0; while (radix > 0) { radix = radix / 2; l++; } return --l; }
Base
1
int fb_get_bit(const fb_t a, int bit) { int d; RLC_RIP(bit, d, bit); return (a[d] >> bit) & 1; }
Base
1
void fb_write_str(char *str, int len, const fb_t a, int radix) { fb_t t; int d, l, i, j; char c; fb_null(t); l = fb_size_str(a, radix); if (len < l) { RLC_THROW(ERR_NO_BUFFER); return; } len = l; l = log_radix(radix); if (!valid_radix(radix)) { RLC_THROW(ERR_NO_VALID); return; } if (fb_is_zero(a...
Base
1
void fb_print(const fb_t a) { int i; /* Suppress possible unused parameter warning. */ (void)a; for (i = RLC_FB_DIGS - 1; i > 0; i--) { util_print_dig(a[i], 1); util_print(" "); } util_print_dig(a[0], 1); util_print("\n"); }
Base
1
void fb_read_bin(fb_t a, const uint8_t *bin, int len) { bn_t t; bn_null(t); if (len != RLC_FB_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } RLC_TRY { bn_new(t); bn_read_bin(t, bin, len); fb_copy(a, t->dp); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
Base
1
void fb_set_bit(fb_t a, int bit, int value) { int d; dig_t mask; RLC_RIP(bit, d, bit); mask = (dig_t)1 << bit; if (value == 1) { a[d] |= mask; } else { a[d] &= ~mask; } }
Base
1
void fb_rand(fb_t a) { int bits, digits; rand_bytes((uint8_t *)a, RLC_FB_DIGS * sizeof(dig_t)); RLC_RIP(bits, digits, RLC_FB_BITS); if (bits > 0) { dig_t mask = RLC_MASK(bits); a[RLC_FB_DIGS - 1] &= mask; } }
Base
1
static int valid_radix(int radix) { while (radix > 0) { if (radix != 1 && radix % 2 == 1) return 0; radix = radix / 2; } return 1; }
Base
1
int fb_bits(const fb_t a) { int i = RLC_FB_DIGS - 1; while (i >= 0 && a[i] == 0) { i--; } if (i > 0) { return (i << RLC_DIG_LOG) + util_bits_dig(a[i]); } else { return util_bits_dig(a[0]); } }
Base
1
int fb_size_str(const fb_t a, int radix) { bn_t t; int digits = 0; bn_null(t); if (!valid_radix(radix)) { RLC_THROW(ERR_NO_VALID); return 0; } RLC_TRY { bn_new(t); bn_read_raw(t, a, RLC_FB_DIGS); digits = bn_size_str(t, radix); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_fre...
Base
1
void fp_exp_basic(fp_t c, const fp_t a, const bn_t b) { int i, l; fp_t r; fp_null(r); if (bn_is_zero(b)) { fp_set_dig(c, 1); return; } RLC_TRY { fp_new(r); l = bn_bits(b); fp_copy(r, a); for (i = l - 2; i >= 0; i--) { fp_sqr(r, r); if (bn_get_bit(b, i)) { fp_mul(r, r, a); } } i...
Base
1
void fp_exp_slide(fp_t c, const fp_t a, const bn_t b) { fp_t t[1 << (FP_WIDTH - 1)], r; int i, j, l; uint8_t win[RLC_FP_BITS + 1]; fp_null(r); if (bn_is_zero(b)) { fp_set_dig(c, 1); return; } /* Initialize table. */ for (i = 0; i < (1 << (FP_WIDTH - 1)); i++) { fp_null(t[i]); } RLC_TRY { for (i =...
Base
1
void fp_prime_set_pmers(const int *f, int len) { bn_t p, t; bn_null(p); bn_null(t); RLC_TRY { bn_new(p); bn_new(t); if (len >= RLC_TERMS) { RLC_THROW(ERR_NO_VALID); return; } bn_set_2b(p, f[len - 1]); for (int i = len - 2; i > 0; i--) { if (f[i] > 0) { bn_set_2b(t, f[i]); bn_add(p, ...
Base
1
int fp_size_str(const fp_t a, int radix) { bn_t t; int digits = 0; bn_null(t); RLC_TRY { bn_new(t); fp_prime_back(t, a); digits = bn_size_str(t, radix); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } return digits; }
Base
1
void fp_read_bin(fp_t a, const uint8_t *bin, int len) { bn_t t; bn_null(t); if (len != RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } RLC_TRY { bn_new(t); bn_read_bin(t, bin, len); /* Reject values out of bounds. */ if (bn_sign(t) == RLC_NEG || bn_cmp(t, &core_get()->prime) != RLC_LT) { RLC...
Base
1
int fp_get_bit(const fp_t a, int bit) { int d; RLC_RIP(bit, d, bit); return (a[d] >> bit) & 1; }
Base
1
void fp_read_str(fp_t a, const char *str, int len, int radix) { bn_t t; bn_null(t); RLC_TRY { bn_new(t); bn_read_str(t, str, len, radix); if (bn_is_zero(t)) { fp_zero(a); } else { if (t->used == 1) { fp_prime_conv_dig(a, t->dp[0]); if (bn_sign(t) == RLC_NEG) { fp_neg(a, a); } } el...
Base
1
int fp_bits(const fp_t a) { int i = RLC_FP_DIGS - 1; while (i >= 0 && a[i] == 0) { i--; } if (i > 0) { return (i << RLC_DIG_LOG) + util_bits_dig(a[i]); } else { return util_bits_dig(a[0]); } }
Base
1
void fp_write_bin(uint8_t *bin, int len, const fp_t a) { bn_t t; bn_null(t); if (len != RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } RLC_TRY { bn_new(t); fp_prime_back(t, a); bn_write_bin(bin, len, t); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
Base
1
void fp_write_str(char *str, int len, const fp_t a, int radix) { bn_t t; bn_null(t); RLC_TRY { bn_new(t); fp_prime_back(t, a); bn_write_str(str, len, t, radix); } RLC_CATCH_ANY { RLC_THROW(ERR_CAUGHT); } RLC_FINALLY { bn_free(t); } }
Base
1
void fp_set_bit(fp_t a, int bit, int value) { int d; dig_t mask; RLC_RIP(bit, d, bit); mask = (dig_t)1 << bit; if (value == 1) { a[d] |= mask; } else { a[d] &= ~mask; } }
Base
1
void fp8_exp_cyc(fp8_t c, const fp8_t a, const bn_t b) { fp8_t r, s, t[1 << (FP_WIDTH - 2)]; int i, l; int8_t naf[RLC_FP_BITS + 1], *k; if (bn_is_zero(b)) { return fp8_set_dig(c, 1); } fp8_null(r); fp8_null(s); RLC_TRY { fp8_new(r); fp8_new(s); for (i = 0; i < (1 << (FP_WIDTH - 2)); i ++) { fp8_nu...
Base
1
void fp2_exp_cyc(fp2_t c, const fp2_t a, const bn_t b) { fp2_t r, s, t[1 << (FP_WIDTH - 2)]; int i, l; int8_t naf[RLC_FP_BITS + 1], *k; if (bn_is_zero(b)) { return fp2_set_dig(c, 1); } fp2_null(r); fp2_null(s); RLC_TRY { fp2_new(r); fp2_new(s); for (i = 0; i < (1 << (FP_WIDTH - 2)); i ++) { fp2_nu...
Base
1
void fp24_exp_cyc_sim(fp24_t e, const fp24_t a, const bn_t b, const fp24_t c, const bn_t d) { int i, l, n0, n1, l0, l1; int8_t naf0[RLC_FP_BITS + 1], naf1[RLC_FP_BITS + 1], *_k, *_m; fp24_t r, t0[1 << (EP_WIDTH - 2)]; fp24_t s, t1[1 << (EP_WIDTH - 2)]; if (bn_is_zero(b)) { return fp24_exp_cyc(e, c, d); } if ...
Base
1
void fp24_exp_cyc_sps(fp24_t c, const fp24_t a, const int *b, int len, int sign) { int i, j, k, w = len; fp24_t t, *u = RLC_ALLOCA(fp24_t, w); if (len == 0) { RLC_FREE(u); fp24_set_dig(c, 1); return; } fp24_null(t); RLC_TRY { if (u == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (i = 0; i < w; i++...
Base
1
void fp12_exp_cyc_sps(fp12_t c, const fp12_t a, const int *b, int len, int sign) { int i, j, k, w = len; fp12_t t, *u = RLC_ALLOCA(fp12_t, w); if (len == 0) { RLC_FREE(u); fp12_set_dig(c, 1); return; } fp12_null(t); RLC_TRY { if (u == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (i = 0; i < w; i++...
Base
1
void fp2_exp_cyc_sim(fp2_t e, const fp2_t a, const bn_t b, const fp2_t c, const bn_t d) { int i, l, n0, n1, l0, l1; int8_t naf0[RLC_FP_BITS + 1], naf1[RLC_FP_BITS + 1], *_k, *_m; fp2_t r, t0[1 << (EP_WIDTH - 2)]; fp2_t s, t1[1 << (EP_WIDTH - 2)]; if (bn_is_zero(b)) { return fp2_exp_cyc(e, c, d); } if (bn_is_...
Base
1
void fp48_exp_cyc_sps(fp48_t c, const fp48_t a, const int *b, int len, int sign) { int i, j, k, w = len; fp48_t t, *u = RLC_ALLOCA(fp48_t, w); if (len == 0) { RLC_FREE(u); fp48_set_dig(c, 1); return; } fp48_null(t); RLC_TRY { if (u == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (i = 0; i < w; i++...
Base
1
void fp54_exp_cyc_sps(fp54_t c, const fp54_t a, const int *b, int len, int sign) { int i, j, k, w = len; fp54_t t, *u = RLC_ALLOCA(fp54_t, w); if (len == 0) { RLC_FREE(u); fp54_set_dig(c, 1); return; } fp54_null(t); RLC_TRY { if (u == NULL) { RLC_THROW(ERR_NO_MEMORY); } for (i = 0; i < w; i++...
Base
1
void fp12_exp_dig(fp12_t c, const fp12_t a, dig_t b) { bn_t _b; fp12_t t, v; int8_t u, naf[RLC_DIG + 1]; int l; if (b == 0) { fp12_set_dig(c, 1); return; } bn_null(_b); fp12_null(t); fp12_null(v); RLC_TRY { bn_new(_b); fp12_new(t); fp12_new(v); fp12_copy(t, a); if (fp12_test_cyc(a)) { fp...
Base
1
void fp24_exp_dig(fp24_t c, const fp24_t a, dig_t b) { bn_t _b; fp24_t t, v; int8_t u, naf[RLC_DIG + 1]; int l; if (b == 0) { fp24_set_dig(c, 1); return; } bn_null(_b); fp24_null(t); fp24_null(v); RLC_TRY { bn_new(_b); fp24_new(t); fp24_new(v); fp24_copy(t, a); if (fp24_test_cyc(a)) { fp...
Base
1
void fp48_exp_dig(fp48_t c, const fp48_t a, dig_t b) { bn_t _b; fp48_t t, v; int8_t u, naf[RLC_DIG + 1]; int l; if (b == 0) { fp48_set_dig(c, 1); return; } bn_null(_b); fp48_null(t); fp48_null(v); RLC_TRY { bn_new(_b); fp48_new(t); fp48_new(v); fp48_copy(t, a); if (fp48_test_cyc(a)) { fp...
Base
1
void fp54_exp_dig(fp54_t c, const fp54_t a, dig_t b) { bn_t _b; fp54_t t, v; int8_t u, naf[RLC_DIG + 1]; int l; if (b == 0) { fp54_set_dig(c, 1); return; } bn_null(_b); fp54_null(t); fp54_null(v); RLC_TRY { bn_new(_b); fp54_new(t); fp54_new(v); fp54_copy(t, a); if (fp54_test_cyc(a)) { fp...
Base
1
void fp4_read_bin(fp4_t a, const uint8_t *bin, int len) { if (len != 4 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp2_read_bin(a[0], bin, 2 * RLC_FP_BYTES); fp2_read_bin(a[1], bin + 2 * RLC_FP_BYTES, 2 * RLC_FP_BYTES); }
Base
1
void fp6_read_bin(fp6_t a, const uint8_t *bin, int len) { if (len != 6 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp2_read_bin(a[0], bin, 2 * RLC_FP_BYTES); fp2_read_bin(a[1], bin + 2 * RLC_FP_BYTES, 2 * RLC_FP_BYTES); fp2_read_bin(a[2], bin + 4 * RLC_FP_BYTES, 2 * RLC_FP_BYTES); }
Base
1
void fp2_read_bin(fp2_t a, const uint8_t *bin, int len) { if (len != RLC_FP_BYTES + 1 && len != 2 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } if (len == RLC_FP_BYTES + 1) { fp_read_bin(a[0], bin, RLC_FP_BYTES); fp_zero(a[1]); fp_set_bit(a[1], 0, bin[RLC_FP_BYTES]); fp2_upk(a, a); } if (len ==...
Base
1
void fp48_write_bin(uint8_t *bin, int len, const fp48_t a, int pack) { fp48_t t; fp48_null(t); RLC_TRY { fp48_new(t); if (pack) { if (len != 32 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); } fp48_pck(t, a); fp8_write_bin(bin, 8 * RLC_FP_BYTES, a[0][1]); fp8_write_bin(bin + 8 * RLC_FP_BYTES, ...
Base
1
void fp8_write_bin(uint8_t *bin, int len, const fp8_t a) { if (len != 8 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp4_write_bin(bin, 4 * RLC_FP_BYTES, a[0]); fp4_write_bin(bin + 4 * RLC_FP_BYTES, 4 * RLC_FP_BYTES, a[1]); }
Base
1
void fp12_write_bin(uint8_t *bin, int len, const fp12_t a, int pack) { fp12_t t; fp12_null(t); RLC_TRY { fp12_new(t); if (pack) { if (len != 8 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); } fp12_pck(t, a); fp2_write_bin(bin, 2 * RLC_FP_BYTES, a[0][1], 0); fp2_write_bin(bin + 2 * RLC_FP_BYTES...
Base
1
void fp24_write_bin(uint8_t *bin, int len, const fp24_t a, int pack) { fp24_t t; fp24_null(t); RLC_TRY { fp24_new(t); if (pack) { if (len != 16 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); } fp24_pck(t, a); fp4_write_bin(bin, 4 * RLC_FP_BYTES, a[1][0]); fp4_write_bin(bin + 4 * RLC_FP_BYTES, ...
Base
1
void fp12_read_bin(fp12_t a, const uint8_t *bin, int len) { if (len != 8 * RLC_FP_BYTES && len != 12 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } if (len == 8 * RLC_FP_BYTES) { fp2_zero(a[0][0]); fp2_read_bin(a[0][1], bin, 2 * RLC_FP_BYTES); fp2_read_bin(a[0][2], bin + 2 * RLC_FP_BYTES, 2 * RLC_FP...
Base
1
void fp2_write_bin(uint8_t *bin, int len, const fp2_t a, int pack) { fp2_t t; fp2_null(t); RLC_TRY { fp2_new(t); if (pack && fp2_test_cyc(a)) { if (len < RLC_FP_BYTES + 1) { RLC_THROW(ERR_NO_BUFFER); return; } else { fp2_pck(t, a); fp_write_bin(bin, RLC_FP_BYTES, t[0]); bin[RLC_FP_BY...
Base
1
void fp9_read_bin(fp9_t a, const uint8_t *bin, int len) { if (len != 9 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp3_read_bin(a[0], bin, 3 * RLC_FP_BYTES); fp3_read_bin(a[1], bin + 3 * RLC_FP_BYTES, 3 * RLC_FP_BYTES); fp3_read_bin(a[2], bin + 6 * RLC_FP_BYTES, 3 * RLC_FP_BYTES); }
Base
1
void fp4_write_bin(uint8_t *bin, int len, const fp4_t a) { if (len != 4 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp2_write_bin(bin, 2 * RLC_FP_BYTES, a[0], 0); fp2_write_bin(bin + 2 * RLC_FP_BYTES, 2 * RLC_FP_BYTES, a[1], 0); }
Base
1
void fp9_write_bin(uint8_t *bin, int len, const fp9_t a) { if (len != 9 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp3_write_bin(bin, 3 * RLC_FP_BYTES, a[0]); fp3_write_bin(bin + 3 * RLC_FP_BYTES, 3 * RLC_FP_BYTES, a[1]); fp3_write_bin(bin + 6 * RLC_FP_BYTES, 3 * RLC_FP_BYTES, a[2]); }
Base
1
void fp18_write_bin(uint8_t *bin, int len, const fp18_t a) { if (len != 18 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp9_write_bin(bin, 9 * RLC_FP_BYTES, a[0]); fp9_write_bin(bin + 9 * RLC_FP_BYTES, 9 * RLC_FP_BYTES, a[1]); }
Base
1
void fp24_read_bin(fp24_t a, const uint8_t *bin, int len) { if (len != 16 * RLC_FP_BYTES && len != 24 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } if (len == 16 * RLC_FP_BYTES) { fp4_zero(a[0][0]); fp4_zero(a[0][1]); fp4_read_bin(a[1][0], bin, 4 * RLC_FP_BYTES); fp4_read_bin(a[1][1], bin + 4 * R...
Base
1
void fp6_write_bin(uint8_t *bin, int len, const fp6_t a) { if (len != 6 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } fp2_write_bin(bin, 2 * RLC_FP_BYTES, a[0], 0); fp2_write_bin(bin + 2 * RLC_FP_BYTES, 2 * RLC_FP_BYTES, a[1], 0); fp2_write_bin(bin + 4 * RLC_FP_BYTES, 2 * RLC_FP_BYTES, a[2], 0); }
Base
1
void fp54_read_bin(fp54_t a, const uint8_t *bin, int len) { if (len != 36 * RLC_FP_BYTES && len != 54 * RLC_FP_BYTES) { RLC_THROW(ERR_NO_BUFFER); return; } if (len == 36 * RLC_FP_BYTES) { fp9_zero(a[0][0]); fp9_zero(a[0][1]); fp9_read_bin(a[1][0], bin, 9 * RLC_FP_BYTES); fp9_read_bin(a[1][1], bin + 9 * R...
Base
1