CVE-2023-36326 (C, published 2023-09-01T16:15Z)
Description: value: Integer Overflow vulnerability in RELIC before commit 34580d840469361ba9b5f001361cad659687b9ab, allows attackers to execute arbitrary code, cause a denial of service, and escalate privileges when calling realloc function in bn_grow function.
Severity: nan (CVSS v3 base score: 9.8)
Weakness: CWE-190 \u2014 Integer Overflow or Wraparound
The product performs a calculation that can
         produce an integer overflow or wraparound when the logic
         assumes that the resulting value will always be larger than
         the original value. This occurs when an integer value is
         incremented to a value that is too large to store in the
         associated representation. When this occurs, the value may
         become a very small or negative number.
Repository: https://github.com/relic-toolkit/relic
Files changed:
bench/bench_bn.c
bench/bench_cp.c
bench/bench_epx.c
include/relic_bn.h
include/relic_cp.h
include/relic_eb.h
include/relic_ed.h
include/relic_ep.h
include/relic_epx.h
include/relic_fb.h
include/relic_fp.h
include/relic_fpx.h
include/relic_md.h
include/relic_rand.h
include/relic_util.h
src/bn/relic_bn_gcd.c
src/bn/relic_bn_mem.c
src/bn/relic_bn_mxp.c
src/bn/relic_bn_prime.c
src/bn/relic_bn_rec.c
src/bn/relic_bn_shift.c
src/bn/relic_bn_smb.c
src/bn/relic_bn_srt.c
src/bn/relic_bn_util.c
src/cp/relic_cp_bls.c
src/cp/relic_cp_cmlhs.c
src/cp/relic_cp_pbpsi.c
src/cp/relic_cp_rsa.c
src/cp/relic_cp_sokaka.c
src/cp/relic_cp_vbnn.c
src/eb/relic_eb_map.c
src/eb/relic_eb_mul.c
src/eb/relic_eb_mul_sim.c
src/eb/relic_eb_util.c
src/ed/relic_ed_map.c
src/ed/relic_ed_mul.c
src/ed/relic_ed_mul_fix.c
src/ed/relic_ed_mul_sim.c
src/ed/relic_ed_util.c
src/ep/relic_ep_map.c
src/ep/relic_ep_mul.c
src/ep/relic_ep_mul_fix.c
src/ep/relic_ep_mul_sim.c
src/ep/relic_ep_util.c
src/epx/relic_ep2_map.c
src/epx/relic_ep2_mul.c
src/epx/relic_ep2_mul_fix.c
src/epx/relic_ep2_mul_sim.c
src/epx/relic_ep2_util.c
src/epx/relic_ep4_map.c
src/epx/relic_ep4_mul.c
src/epx/relic_ep4_mul_fix.c
src/epx/relic_ep4_mul_sim.c
src/epx/relic_ep4_util.c
src/fb/relic_fb_exp.c
src/fb/relic_fb_util.c
src/fp/relic_fp_exp.c
src/fp/relic_fp_prime.c
src/fp/relic_fp_util.c
src/fpx/relic_fpx_cyc.c
src/fpx/relic_fpx_exp.c
src/fpx/relic_fpx_util.c
src/md/relic_md_blake2s.c
src/md/relic_md_hmac.c
src/md/relic_md_kdf.c
src/md/relic_md_mgf.c
src/md/relic_md_sha224.c
src/md/relic_md_sha256.c
src/md/relic_md_sha384.c
src/md/relic_md_sha512.c
src/pp/relic_pp_map_k12.c
src/pp/relic_pp_map_k24.c
src/pp/relic_pp_map_k48.c
src/pp/relic_pp_map_k54.c
src/pp/relic_pp_map_k8.c
src/rand/relic_rand_core.c
src/rand/relic_rand_hashd.c
src/relic_util.c
test/test_bn.c
test/test_core.c
test/test_pc.c
test/test_rand.c
Commit message: Huge commit improving the API to use size_t instead of int.


Vulnerable code:
	int len;
		int len;
			int len = RLC_BN_BITS + 1;
		int len = RLC_BN_BITS + 1;
	BENCH_ONE("cp_bdpe_gen", cp_bdpe_gen(pub, prv, bn_get_prime(47),
		RLC_BN_BITS), 1);
		in = out[0] % bn_get_prime(47);
		in = out[0] % bn_get_prime(47);
	BENCH_FEW("ep2_null", ep4_null(a[i]), 1);
	BENCH_FEW("ep2_new", ep4_new(a[i]), 1);
	BENCH_FEW("ep2_free", ep4_free(a[i]), 1);
#define RLC_BN_BITS 	((int)BN_PRECI)
#define RLC_BN_DIGS		((int)RLC_CEIL(BN_PRECI, RLC_DIG))
#define RLC_BN_SIZE		((int)(2 * RLC_BN_DIGS + 2))
#define RLC_BN_SIZE		((int)(RLC_BN_DIGS + 1))
#define RLC_BN_SIZE		((int)RLC_BN_DIGS)
	int alloc;
	int used;
void bn_make(bn_t a, int digits);
void bn_grow(bn_t a, int digits);
int bn_bits(const bn_t a);
int bn_get_bit(const bn_t a, int bit);
void bn_set_bit(bn_t a, int bit, int value);
int bn_ham(const bn_t a);
void bn_set_2b(bn_t a, int b);
void bn_rand(bn_t a, int sign, int bits);
int bn_size_str(const bn_t a, int radix);
void bn_read_str(bn_t a, const char *str, int len, int radix);
void bn_write_str(char *str, int len, const bn_t a, int radix);
int bn_size_bin(const bn_t a);
void bn_read_bin(bn_t a, const uint8_t *bin, int len);
void bn_write_bin(uint8_t *bin, int len, const bn_t a);
int bn_size_raw(const bn_t a);
void bn_read_raw(bn_t a, const dig_t *raw, int len);
void bn_write_raw(dig_t *raw, int len, const bn_t a);
void bn_lsh(bn_t c, const bn_t a, int bits);
void bn_rsh(bn_t c, const bn_t a, int bits);
void bn_gen_prime_basic(bn_t a, int bits);
void bn_gen_prime_safep(bn_t a, int bits);
void bn_gen_prime_stron(bn_t a, int bits);
int bn_gen_prime_factor(bn_t a, bn_t b, int abits, int bbits);
void bn_rec_win(uint8_t *win, int *len, const bn_t k, int w);
void bn_rec_slw(uint8_t *win, int *len, const bn_t k, int w);
void bn_rec_naf(int8_t *naf, int *len, const bn_t k, int w);
void bn_rec_tnaf(int8_t *tnaf, int *len, const bn_t k, int8_t u, int m, int w);
void bn_rec_rtnaf(int8_t *tnaf, int *len, const bn_t k, int8_t u, int m, int w);
void bn_rec_tnaf_get(uint8_t *t, int8_t *beta, int8_t *gama, int8_t u, int w);
void bn_rec_tnaf_mod(bn_t r0, bn_t r1, const bn_t k, int u, int m);
void bn_rec_reg(int8_t *naf, int *len, const bn_t k, int n, int w);
void bn_rec_jsf(int8_t *jsf, int *len, const bn_t k, const bn_t l);
int cp_rsa_gen(rsa_t pub, rsa_t prv, int bits);
int cp_bls_sig(g1_t s, const uint8_t *msg, int len, const bn_t d);
void eb_read_bin(eb_t a, const uint8_t *bin, int len);
void eb_write_bin(uint8_t *bin, int len, const eb_t a, int pack);
void eb_map(eb_t p, const uint8_t *msg, int len);
void ed_map(ed_t p, const uint8_t *msg, int len);
void ed_map_dst(ed_t p, const uint8_t *msg, int len, const uint8_t *dst, int dst_len);
void ed_read_bin(ed_t a, const uint8_t *bin, int len);
void ed_write_bin(uint8_t *bin, int len, const ed_t a, int pack);
void ep_read_bin(ep_t a, const uint8_t *bin, int len);
void ep_write_bin(uint8_t *bin, int len, const ep_t a, int pack);
void ep_map_from_field(ep_t p, const uint8_t *uniform_bytes, int len);
void ep_map(ep_t p, const uint8_t *msg, int len);
void ep_map_dst(ep_t p, const uint8_t *msg, int len, const uint8_t *dst,
		int dst_len);
void ep2_read_bin(ep2_t a, const uint8_t *bin, int len);
void ep2_write_bin(uint8_t *bin, int len, const ep2_t a, int pack);
void ep2_mul_sim_inter(ep2_t r, const ep2_t p, const bn_t k, const ep2_t q, const bn_t m);
void ep2_mul_sim_joint(ep2_t r, const ep2_t p, const bn_t k, const ep2_t q, const bn_t m);
void ep2_mul_sim_lot(ep2_t r, const ep2_t p[], const bn_t k[], int n);
void ep2_mul_sim_dig(ep2_t r, const ep2_t p[], const dig_t k[], int len);
void ep2_map_from_field(ep2_t p, const uint8_t *uniform_bytes, int len);
void ep2_map(ep2_t p, const uint8_t *msg, int len);
void ep2_map_dst(ep2_t p, const uint8_t *msg, int len, const uint8_t *dst, int dst_len);
void ep4_read_bin(ep4_t a, const uint8_t *bin, int len);
void ep4_write_bin(uint8_t *bin, int len, const ep4_t a, int pack);
void ep4_mul_sim_lot(ep4_t r, const ep4_t p[], const bn_t k[], int n);
void ep4_mul_sim_dig(ep4_t r, const ep4_t p[], const dig_t k[], int len);
void ep4_map(ep4_t p, const uint8_t *msg, int len);
void ep4_map_dst(ep4_t p, const uint8_t *msg, int len, const uint8_t *dst, int dst_len);
#define RLC_FB_BITS 	((int)FB_POLYN)
#define RLC_FB_DIGS		((int)RLC_CEIL(RLC_FB_BITS, RLC_DIG))
#define RLC_FB_BYTES 	((int)RLC_CEIL(RLC_FB_BITS, 8))
int fb_get_bit(const fb_t a, int bit);
void fb_set_bit(fb_t a, int bit, int value);
int fb_bits(const fb_t a);
int fb_size_str(const fb_t a, int radix);
void fb_read_str(fb_t a, const char *str, int len, int radix);
void fb_write_str(char *str, int len, const fb_t a, int radix);
 * @param[in] bin			- the byte vector.
void fb_read_bin(fb_t a, const uint8_t *bin, int len);
void fb_write_bin(uint8_t *bin, int len, const fb_t a);
#define RLC_FP_BITS 	((int)FP_PRIME)
#define RLC_FP_DIGS 	((int)RLC_CEIL(RLC_FP_BITS, RLC_DIG))
#define RLC_FP_BYTES 	((int)RLC_CEIL(RLC_FP_BITS, 8))
void fp_prime_set_pmers(const int *spars, int len);
* Assigns the prime field modulus to a parametrization from a family of
int fp_get_bit(const fp_t a, int bit);
void fp_set_bit(fp_t a, int bit, int value);
int fp_bits(const fp_t a);
int fp_size_str(const fp_t a, int radix);
void fp_read_str(fp_t a, const char *str, int len, int radix);
void fp_write_str(char *str, int len, const fp_t a, int radix);
void fp_read_bin(fp_t a, const uint8_t *bin, int len);
void fp_write_bin(uint8_t *bin, int len, const fp_t a);
void fp2_read_bin(fp2_t a, const uint8_t *bin, int len);
void fp2_write_bin(uint8_t *bin, int len, const fp2_t a, int pack);
void fp3_read_bin(fp3_t a, const uint8_t *bin, int len);
void fp3_write_bin(uint8_t *bin, int len, const fp3_t a);
void fp4_read_bin(fp4_t a, const uint8_t *bin, int len);
void fp4_write_bin(uint8_t *bin, int len, const fp4_t a);
void fp6_read_bin(fp6_t a, const uint8_t *bin, int len);
void fp6_write_bin(uint8_t *bin, int len, const fp6_t a);
void fp8_read_bin(fp8_t a, const uint8_t *bin, int len);
void fp8_write_bin(uint8_t *bin, int len, const fp8_t a);
void fp9_read_bin(fp9_t a, const uint8_t *bin, int len);
void fp9_write_bin(uint8_t *bin, int len, const fp9_t a);
void fp12_read_bin(fp12_t a, const uint8_t *bin, int len);
void fp12_write_bin(uint8_t *bin, int len, const fp12_t a, int pack);
void fp2_exp_cyc_sim(fp2_t e, const fp2_t a, const bn_t b, const fp2_t c, const bn_t d);
void fp12_exp_cyc_sim(fp12_t e, const fp12_t a, const bn_t b, const fp12_t c, const bn_t d);
void fp12_exp_cyc_sps(fp12_t c, const fp12_t a, const int *b, int l, int s);
void fp18_read_bin(fp18_t a, const uint8_t *bin, int len);
void fp18_write_bin(uint8_t *bin, int len, const fp18_t a);
void fp24_read_bin(fp24_t a, const uint8_t *bin, int len);
void fp24_write_bin(uint8_t *bin, int len, const fp24_t a, int pack);
void fp24_exp_cyc_sps(fp24_t c, const fp24_t a, const int *b, int l, int s);
void fp48_read_bin(fp48_t a, const uint8_t *bin, int len);
void fp48_write_bin(uint8_t *bin, int len, const fp48_t a, int pack);
void fp48_exp_cyc_sps(fp48_t c, const fp48_t a, const int *b, int l, int s);
void fp54_read_bin(fp54_t a, const uint8_t *bin, int len);
void fp54_write_bin(uint8_t *bin, int len, const fp54_t a, int pack);
void fp54_exp_cyc_sps(fp54_t c, const fp54_t a, const int *b, int l, int s);
void md_map_sh224(uint8_t *hash, const uint8_t *msg, int len);
void md_map_sh256(uint8_t *hash, const uint8_t *msg, int len);
void md_map_sh384(uint8_t *hash, const uint8_t *msg, int len);
void md_map_sh512(uint8_t *hash, const uint8_t *msg, int len);
void md_map_b2s160(uint8_t *hash, const uint8_t *msg, int len);
void md_map_b2s256(uint8_t *hash, const uint8_t *msg, int len);
void md_kdf(uint8_t *key, int key_len, const uint8_t *in, int in_len);
void md_mgf(uint8_t *mask, int mask_len, const uint8_t *in, int in_len);
void md_hmac(uint8_t *mac, const uint8_t *in, int in_len, const uint8_t *key,
		int key_len);
void md_xmd_sh224(uint8_t *buf, int buf_len, const uint8_t *in, int in_len,
		const uint8_t *dst, int dst_len);
void md_xmd_sh256(uint8_t *buf, int buf_len, const uint8_t *in, int in_len,
		const uint8_t *dst, int dst_len);
void md_xmd_sh384(uint8_t *buf, int buf_len, const uint8_t *in, int in_len,
		const uint8_t *dst, int dst_len);
void md_xmd_sh512(uint8_t *buf, int buf_len, const uint8_t *in, int in_len,
		const uint8_t *dst, int dst_len);
void rand_seed(uint8_t *buf, int size);
void rand_seed(void (*callback)(uint8_t *, int, void *), void *arg);
int rand_check(uint8_t *buf, int size);
void rand_bytes(uint8_t *buf, int size);
int util_bits_dig(dig_t a);
			bn_rsh(u, x, bn_bits(x) - RLC_DIG);
			bn_rsh(v, y, bn_bits(x) - RLC_DIG);
				bn_rsh(u, x, bn_bits(x) - 2 * RLC_DIG);
				bn_rsh(v, y, bn_bits(x) - 2 * RLC_DIG);
				bn_rsh(t0, u, bn_bits(u) - RLC_DIG);
				bn_rsh(t1, v, bn_bits(u) - RLC_DIG);
			bn_rsh(u, x, bn_bits(x) - RLC_DIG);
			bn_rsh(v, y, bn_bits(x) - RLC_DIG);
				bn_rsh(u, x, bn_bits(x) - 2 * RLC_DIG);
				bn_rsh(v, y, bn_bits(x) - 2 * RLC_DIG);
				bn_rsh(t0, u, bn_bits(u) - RLC_DIG);
				bn_rsh(t1, v, bn_bits(u) - RLC_DIG);
void bn_make(bn_t a, int digits) {
void bn_grow(bn_t a, int digits) {
		if (a->used <= 0) {
	int i, j, l, w = 1;
	for (i = 0; i < RLC_TABLE_SIZE; i++) {
	i = bn_bits(b);
	if (i <= 21) {
	} else if (i <= 32) {
	} else if (i <= 128) {
	} else if (i <= 256) {
	} else if (i <= 512) {
		for (i = 0; i < (1 << (w - 1)); i++) {
		for (i = 1; i < 1 << (w - 1); i++) {
		l = bn_bits(b);
		for (i = 0; i < l; i++) {
				for (j = 0; j < util_bits_dig(win[i]); j++) {
		for (i = 0; i < (1 << (w - 1)); i++) {
		while (bn_is_even(r)) {
void bn_gen_prime_basic(bn_t a, int bits) {
void bn_gen_prime_safep(bn_t a, int bits) {
void bn_gen_prime_stron(bn_t a, int bits) {
int bn_gen_prime_factor(bn_t a, bn_t b, int abits, int bbits) {
static char get_bits(const bn_t a, int from, int to) {
void bn_rec_win(uint8_t *win, int *len, const bn_t k, int w) {
void bn_rec_slw(uint8_t *win, int *len, const bn_t k, int w) {
void bn_rec_naf(int8_t *naf, int *len, const bn_t k, int w) {
void bn_rec_tnaf_get(uint8_t *t, int8_t *beta, int8_t *gama, int8_t u, int w) {
void bn_rec_tnaf_mod(bn_t r0, bn_t r1, const bn_t k, int u, int m) {
void bn_rec_tnaf(int8_t *tnaf, int *len, const bn_t k, int8_t u, int m, int w) {
void bn_rec_rtnaf(int8_t *tnaf, int *len, const bn_t k, int8_t u, int m, int w) {
void bn_rec_reg(int8_t *naf, int *len, const bn_t k, int n, int w) {
void bn_rec_jsf(int8_t *jsf, int *len, const bn_t k, const bn_t l) {
	int r1, r2, bits;
void bn_lsh(bn_t c, const bn_t a, int bits) {
	if (bits <= 0) {
		return;
	}

void bn_rsh(bn_t c, const bn_t a, int bits) {
	if (bits <= 0) {
		return;
	}

	c->used = a->used - digits;
			while (bn_is_even(t0)) {
	int bits, cmp;
		bn_set_2b(l, (bits >> 1) - 1);
int bn_bits(const bn_t a) {
int bn_get_bit(const bn_t a, int bit) {
void bn_set_bit(bn_t a, int bit, int value) {
int bn_ham(const bn_t a) {
void bn_set_2b(bn_t a, int b) {
	if (b < 0) {
		bn_zero(a);
void bn_rand(bn_t a, int sign, int bits) {
int bn_size_str(const bn_t a, int radix) {
void bn_read_str(bn_t a, const char *str, int len, int radix) {
void bn_write_str(char *str, int len, const bn_t a, int radix) {
int bn_size_bin(const bn_t a) {
void bn_read_bin(bn_t a, const uint8_t *bin, int len) {
void bn_write_bin(uint8_t *bin, int len, const bn_t a) {
int bn_size_raw(const bn_t a) {
void bn_read_raw(bn_t a, const dig_t *raw, int len) {
void bn_write_raw(dig_t *raw, int len, const bn_t a) {
int cp_bls_sig(g1_t s, const uint8_t *msg, int len, const bn_t d) {
		if (bls) {
			cp_bls_gen(sk, pk);
		} else {
			cp_ecdsa_gen(sk, g1);
			fp_copy(pk->x[0], g1->x);
			fp_copy(pk->y[0], g1->y);
		}
		bn_rand_mod(d, n);
		g2_mul_gen(y, d);
	int len, dlen = strlen(data), result = RLC_OK;
	int len, dlen = strlen(data), result = 1;
	int len, dlen = strlen(data), result = 1;
static int pad_pkcs1(bn_t m, int *p_len, int m_len, int k_len, int operation) {
	int len, result = RLC_ERR;
		switch (operation) {
static int pad_pkcs2(bn_t m, int *p_len, int m_len, int k_len, int operation) {
		switch (operation) {
int cp_rsa_gen(rsa_t pub, rsa_t prv, int bits) {
	int len1 = strlen(id1), len2 = strlen(id2);
	int size, first = 0, result = RLC_OK;
	int len, result = RLC_OK;
	int len, result = RLC_OK;
	int len, result = 0;
	ec_t Z;
	ec_t t;
void eb_map(eb_t p, const uint8_t *msg, int len) {
	int i, l, n;
	int i, l, n;
	int i, l, n;
	int i, l, n;
	int bits, i, j;
		for (i = bits - 1; i >= 0; i--) {
			j = bn_get_bit(t, i);
	int i, j, l, trc, cof;
	int i, l, l0, l1, n0, n1, w, g;
	int i, l, l0, l1, n0, n1, w, g;
	int l0, l1, w = EB_WIDTH / 2;
	int i, u_i, len, offset;
void eb_read_bin(eb_t a, const uint8_t *bin, int len) {
void eb_write_bin(uint8_t *bin, int len, const eb_t a, int pack) {
void ed_map_dst(ed_t p, const uint8_t *msg, int len, const uint8_t *dst, int dst_len) {
void ed_map(ed_t p, const uint8_t *msg, int len) {
	int l, i, n;
	int i, j, l, n;
	int i, j, l;
		for (i = 0; i < (1 << (EP_WIDTH - 1)); i ++) {
		for (i = 1; i < (1 << (EP_WIDTH - 1)); i++) {
		for (i = 0; i < l; i++) {
				for (j = 0; j < util_bits_dig(win[i]); j++) {
		for (i = 0; i < (1 << (EP_WIDTH - 1)); i++) {
	int l;
	int l, i, n;
	int i, l, l0, l1, n0, n1, w, gen;
	int l0, l1, w = ED_WIDTH / 2;
	int i, l, u_i, offset;
	int i, j, l, *_l = RLC_ALLOCA(int, n);
	ed_t *_p = RLC_ALLOCA(ed_t, n);
void ed_read_bin(ed_t a, const uint8_t *bin, int len) {
void ed_write_bin(uint8_t *bin, int len, const ed_t a, int pack) {
TMPL_MAP_HORNER(fp, fp_st)
		TMPL_MAP_ISOGENY_MAP(ep, fp, iso)
#define EP_MAP_COPY_COND(O, I, C) dv_copy_cond(O, I, RLC_FP_DIGS, C)
		TMPL_MAP_SSWU(ep, fp, dig_t, EP_MAP_COPY_COND)
TMPL_MAP_SVDW(ep, fp, dig_t, EP_MAP_COPY_COND)
/* caution: this function overwrites k, which it uses as an auxiliary variable */
void ep_map_from_field(ep_t p, const uint8_t *uniform_bytes, int len) {
		void (*const map_fn)(ep_t, fp_t) =(ep_curve_is_ctmap() ||
#define EP_MAP_CONVERT_BYTES(IDX)                                       \
    do {                                                                \
      bn_read_bin(k, uniform_bytes + IDX * len_per_elm, len_per_elm);   \
      fp_prime_conv(t, k);                                              \
    } while (0)

#define EP_MAP_APPLY_MAP(PT)                                    \
    do {                                                        \
      /* check sign of t */                                     \
      neg = fp_sgn0(t, k);                                      \
      /* convert */                                             \
      map_fn(PT, t);                                            \
      /* compare sign of y and sign of t; fix if necessary */   \
      neg = neg != fp_sgn0(PT->y, k);                             \
      fp_neg(t, PT->y);                                          \
      dv_copy_cond(PT->y, t, RLC_FP_DIGS, neg);                  \
    } while (0)
void ep_map_dst(ep_t p, const uint8_t *msg, int len, const uint8_t *dst,
		int dst_len) {
void ep_map(ep_t p, const uint8_t *msg, int len) {
	int l, l0, l1, i, n0, n1, s0, s1;
	int i, l;
		for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) {
		for (i = l - 1; i >= 0; i--) {
		for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) {
	int i, j, l, n0, n1, s0, s1, b0, b1;
	int i, j, l, n;
	int i, j, l;
		for (i = 0; i < (1 << (EP_WIDTH - 1)); i ++) {
		for (i = 1; i < (1 << (EP_WIDTH - 1)); i++) {
		for (i = 0; i < l; i++) {
				for (j = 0; j < util_bits_dig(win[i]); j++) {
		for (i = 0; i < (1 << (EP_WIDTH - 1)); i++) {
	int i, j, bits;
		for (i = bits - 1; i >= 0; i--) {
			j = bn_get_bit(l, i);
	int l;
	int l, i, n;
	int i, l, l0, l1, l2, l3, sk0, sk1, sl0, sl1, w, g = 0;
	int i, j, m, l, _l[2], sk;
	int i, l, l0, l1, w, gen;
	int i, j, l, *_l = RLC_ALLOCA(int, n);
	ep_t *_p = RLC_ALLOCA(ep_t, n);
	int l0, l1, w = EP_WIDTH / 2;
	int i, l, u_i, offset;
void ep_read_bin(ep_t a, const uint8_t *bin, int len) {
void ep_write_bin(uint8_t *bin, int len, const ep_t a, int pack) {


#define EP2_MAP_COPY_COND(O, I, C)                                                       \
	do {                                                                                 \
		dv_copy_cond(O[0], I[0], RLC_FP_DIGS, C);                                        \
		dv_copy_cond(O[1], I[1], RLC_FP_DIGS, C);                                        \


void ep2_map_from_field(ep2_t p, const uint8_t *uniform_bytes, int len) {
        bn_t k;
        fp2_t t;
        ep2_t q;
        int neg;
        /* enough space for two extension field elements plus extra bytes for uniformity */
        const int len_per_elm = (FP_PRIME + ep_param_level() + 7) / 8;

        bn_null(k);
        fp2_null(t);
        ep2_null(q);

        RLC_TRY {
                if (len != 2* len_per_elm) {
                  RLC_THROW(ERR_NO_VALID);
                }

                bn_new(k);
                fp2_new(t);
                ep2_new(q);

                /* which hash function should we use? */
                const int abNeq0 = (ep2_curve_opt_a() != RLC_ZERO) && (ep2_curve_opt_b() != RLC_ZERO);
                void (*const map_fn)(ep2_t, fp2_t) = (ep2_curve_is_ctmap() || abNeq0) ? ep2_map_sswu : ep2_map_svdw;

#define EP2_MAP_CONVERT_BYTES(IDX)                                                       \
        do {                                                                                 \
                bn_read_bin(k, uniform_bytes + 2 * IDX * len_per_elm, len_per_elm);        \
                fp_prime_conv(t[0], k);                                                          \
                bn_read_bin(k, uniform_bytes + (2 * IDX + 1) * len_per_elm, len_per_elm);  \
                fp_prime_conv(t[1], k);                                                          \
        } while (0)

#define EP2_MAP_APPLY_MAP(PT)                                                            \
        do {                                                                                 \
                /* sign of t */                                                                  \
                neg = fp2_sgn0(t, k);                                                            \
                /* convert */                                                                    \
                map_fn(PT, t);                                                                   \
                /* compare sign of y to sign of t; fix if necessary */                           \
                neg = neg != fp2_sgn0(PT->y, k);                                                 \
                fp2_neg(t, PT->y);                                                               \
                dv_copy_cond(PT->y[0], t[0], RLC_FP_DIGS, neg);                                  \
                dv_copy_cond(PT->y[1], t[1], RLC_FP_DIGS, neg);                                  \
        } while (0)

                /* first map invocation */
                EP2_MAP_CONVERT_BYTES(0);
                EP2_MAP_APPLY_MAP(p);
                TMPL_MAP_CALL_ISOMAP(ep2, p);

                /* second map invocation */
                EP2_MAP_CONVERT_BYTES(1);
                EP2_MAP_APPLY_MAP(q);
                TMPL_MAP_CALL_ISOMAP(ep2, q);

                /* XXX(rsw) could add p and q and then apply isomap,
                 * but need ep_add to support addition on isogeny curves */
                /* sum the result */
                ep2_add(p, p, q);
                ep2_norm(p, p);
                ep2_mul_cof(p, p);
        }
        RLC_CATCH_ANY {
                RLC_THROW(ERR_CAUGHT);
        }
        RLC_FINALLY {
                bn_free(k);
                fp2_free(t);
                ep2_free(q);
        }
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);

        RLC_TRY {

                /* XXX(rsw) See note in ep/relic_ep_map.c about using MD_MAP. */
                /* hash to a pseudorandom string using md_xmd */
                md_xmd(pseudo_random_bytes, 4 * len_per_elm, msg, len, dst, dst_len);
                ep2_map_from_field(p, pseudo_random_bytes, 2 * len_per_elm);
        }
        RLC_CATCH_ANY {
                RLC_THROW(ERR_CAUGHT);
        }
        RLC_FINALLY {
                RLC_FREE(pseudo_random_bytes);
        }
void ep2_map(ep2_t p, const uint8_t *msg, int len) {
	int i, j, l, _l[4];
		for (i = 0; i < 4; i++) {
		for (i = 0; i < 4; i++) {
		for (j = l - 1; j >= 0; j--) {
			for (i = 0; i < 4; i++) {
		for (i = 0; i < 4; i++) {
	int l, i, n;
		for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) {
		for (i = l - 1; i >= 0; i--) {
		for (i = 0; i < (1 << (EP_WIDTH - 2)); i++) {
	int i, l;
		for (i = l - 2; i >= 0; i--) {
	int i, j, l;
		for (i = 0; i < (1 << (EP_WIDTH - 1)); i ++) {
		for (i = 1; i < (1 << (EP_WIDTH - 1)); i++) {
		for (i = 0; i < l; i++) {
				for (j = 0; j < util_bits_dig(win[i]); j++) {
		for (i = 0; i < (1 << (EP_WIDTH - 1)); i++) {
	int l;
	int len, i, n;
	for (i = len - 1; i >= 0; i--, t--) {
	int i, j, l, _l[4];
		for (i = 0; i < 4; i++) {
		for (i = 0; i < 4; i++) {
		for (i = l - 1; i >= 0; i--) {
			for (j = 0; j < 4; j++) {
		for (i = 0; i < 4; i++) {
	int i, l, l0, l1, n0, n1, w, gen;
	int l0, l1, w = EP_WIDTH / 2;
	int i, l, u_i, offset;
void ep2_mul_sim_dig(ep2_t r, const ep2_t p[], const dig_t k[], int len) {
void ep2_mul_sim_lot(ep2_t r, const ep2_t p[], const bn_t k[], int n) {
	const int len = RLC_FP_BITS + 1;
	int i, j, m, l, _l[4];
void ep2_read_bin(ep2_t a, const uint8_t *bin, int len) {
void ep2_write_bin(uint8_t *bin, int len, const ep2_t a, int pack) {
void ep4_map(ep4_t p, const uint8_t *msg, int len) {
	int sign, i, j, l, _l[8];
	int l, i, n;
	int i, j, l;
		for (i = 0; i < (1 << (EP_WIDTH - 1)); i ++) {
		for (i = 1; i < (1 << (EP_WIDTH - 1)); i++) {
		for (i = 0; i < l; i++) {
				for (j = 0; j < util_bits_dig(win[i]); j++) {
		for (i = 0; i < (1 << (EP_WIDTH - 1)); i++) {
	int i;

	for (i = 2; i < (1 << (EP_DEPTH - 2)); i++) {
	for (i = 1; i < (1 << (EP_DEPTH - 2)); i++) {
	int len, i, n;
	for (i = len - 1; i >= 0; i--, t--) {
	int i, l, l0, l1, n0, n1, w, gen;
	int l0, l1, w = EP_WIDTH / 2;
	int i, l, u_i, offset;
void ep4_mul_sim_dig(ep4_t r, const ep4_t p[], const dig_t k[], int len) {
void ep4_mul_sim_lot(ep4_t r, const ep4_t p[], const bn_t k[], int n) {
	const int len = RLC_FP_BITS + 1;
	int i, j, m, l, *_l = RLC_ALLOCA(int, 8 * n);
void ep4_read_bin(ep4_t a, const uint8_t *bin, int len) {
void ep4_write_bin(uint8_t *bin, int len, const ep4_t a, int pack) {
	int i, l;
		for (i = l - 2; i >= 0; i--) {
	int i, j, l;
	for (i = 0; i < (1 << (FB_WIDTH - 1)); i++) {
		for (i = 0; i < (1 << (FB_WIDTH - 1)); i ++) {
		for (i = 1; i < 1 << (FB_WIDTH - 1); i++) {
		for (i = 0; i < l; i++) {
				for (j = 0; j < util_bits_dig(win[i]); j++) {
		for (i = 0; i < (1 << (FB_WIDTH - 1)); i++) {
static int valid_radix(int radix) {
static int log_radix(int radix) {
int fb_get_bit(const fb_t a, int bit) {
void fb_set_bit(fb_t a, int bit, int value) {
int fb_bits(const fb_t a) {
	int bits, digits;
	int i;

	for (i = RLC_FB_DIGS - 1; i > 0; i--) {
int fb_size_str(const fb_t a, int radix) {
	int digits = 0;
void fb_read_str(fb_t a, const char *str, int len, int radix) {
void fb_write_str(char *str, int len, const fb_t a, int radix) {
void fb_read_bin(fb_t a, const uint8_t *bin, int len) {
void fb_write_bin(uint8_t *bin, int len, const fb_t a) {
	int i, l;
		for (i = l - 2; i >= 0; i--) {
	int i, j, l;
	for (i = 0; i < (1 << (FP_WIDTH - 1)); i++) {
		for (i = 0; i < (1 << (FP_WIDTH - 1)); i ++) {
		for (i = 1; i < 1 << (FP_WIDTH - 1); i++) {
		for (i = 0; i < l; i++) {
				for (j = 0; j < util_bits_dig(win[i]); j++) {
		for (i = 0; i < (1 << (FP_WIDTH - 1)); i++) {
	int len = bn_bits(x) + 1;
void fp_prime_set_pmers(const int *f, int len) {
int fp_get_bit(const fp_t a, int bit) {
void fp_set_bit(fp_t a, int bit, int value) {
int fp_bits(const fp_t a) {
int fp_size_str(const fp_t a, int radix) {
	int digits = 0;
void fp_read_str(fp_t a, const char *str, int len, int radix) {
void fp_write_str(char *str, int len, const fp_t a, int radix) {
void fp_read_bin(fp_t a, const uint8_t *bin, int len) {
			}	
void fp_write_bin(uint8_t *bin, int len, const fp_t a) {
	int i, l;
		for (i = 0; i < (1 << (FP_WIDTH - 2)); i ++) {
		for (i = l - 1; i >= 0; i--, k--) {
		for (i = 0; i < (1 << (FP_WIDTH - 2)); i++) {
	int i, l;
		for (i = 0; i < (1 << (FP_WIDTH - 2)); i ++) {
		for (i = l - 1; i >= 0; i--, k--) {
		for (i = 0; i < (1 << (FP_WIDTH - 2)); i++) {
	int i, j, k, l, w = bn_ham(b);
		int _l[4];
			for (i = 0; i < 4; i++) {
				for (i = 0; i < 4; i++) {
				for (i = l - 1; i >= 0; i--) {
					for (j = 0; j < 4; j++) {
				for (i = bn_bits(b) - 2; i >= 0; i--) {
			for (i = 0; i < 4; i++) {
			for (i = 0; i < w; i++) {
			for (i = 1; i < bn_bits(b); i++) {
			for (i = j; i < k; i++) {
			for (i = 0; i < w; i++) {
	int i, l, n0, n1, l0, l1;
		for (i = 0; i < (1 << (FP_WIDTH - 2)); i ++) {
			for (i = 0; i < l0; i++) {
			for (i = 0; i < l1; i++) {
		for (i = l - 1; i >= 0; i--, _k--, _m--) {
		for (i = 0; i < (1 << (FP_WIDTH - 2)); i++) {
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;
	int i, j, k, w = bn_ham(b);
		int l, _l[8];
			for (i = 0; i < 8; i++) {
				for (i = 0; i < 8; i++) {
				for (i = 0; i < 8; i++) {
				for (i = l - 1; i >= 0; i--) {
					for (j = 0; j < 8; j++) {
				for (i = bn_bits(b) - 2; i >= 0; i--) {
			for (i = 0; i < 8; i++) {
			for (i = 0; i < w; i++) {
			for (i = 1; i < bn_bits(b); i++) {
			for (i = j; i < k; i++) {
			for (i = 0; i < w; i++) {
	int i, l, n0, n1, l0, l1;
		for (i = 0; i < (1 << (FP_WIDTH - 2)); i ++) {
			for (i = 0; i < l0; i++) {
			for (i = 0; i < l1; i++) {
		for (i = l - 1; i >= 0; i--, _k--, _m--) {
		for (i = 0; i < (1 << (FP_WIDTH - 2)); i++) {
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;
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;
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;
	int l;
	int l;
	int l;
	int l;
void fp2_read_bin(fp2_t a, const uint8_t *bin, int len) {
void fp2_write_bin(uint8_t *bin, int len, const fp2_t a, int pack) {
void fp3_read_bin(fp3_t a, const uint8_t *bin, int len) {
void fp3_write_bin(uint8_t *bin, int len, const fp3_t a) {
void fp4_read_bin(fp4_t a, const uint8_t *bin, int len) {
void fp4_write_bin(uint8_t *bin, int len, const fp4_t a) {
void fp6_read_bin(fp6_t a, const uint8_t *bin, int len) {
void fp6_write_bin(uint8_t *bin, int len, const fp6_t a) {
void fp8_read_bin(fp8_t a, const uint8_t *bin, int len) {
void fp8_write_bin(uint8_t *bin, int len, const fp8_t a) {
void fp9_read_bin(fp9_t a, const uint8_t *bin, int len) {
void fp9_write_bin(uint8_t *bin, int len, const fp9_t a) {
void fp12_read_bin(fp12_t a, const uint8_t *bin, int len) {
void fp12_write_bin(uint8_t *bin, int len, const fp12_t a, int pack) {
void fp18_read_bin(fp18_t a, const uint8_t *bin, int len) {
void fp18_write_bin(uint8_t *bin, int len, const fp18_t a) {
void fp24_read_bin(fp24_t a, const uint8_t *bin, int len) {
void fp24_write_bin(uint8_t *bin, int len, const fp24_t a, int pack) {
void fp48_read_bin(fp48_t a, const uint8_t *bin, int len) {
void fp48_write_bin(uint8_t *bin, int len, const fp48_t a, int pack) {
void fp54_read_bin(fp54_t a, const uint8_t *bin, int len) {
void fp54_write_bin(uint8_t *bin, int len, const fp54_t a, int pack) {
void md_map_b2s160(uint8_t *hash, const uint8_t *msg, int len) {
void md_map_b2s256(uint8_t *hash, const uint8_t *msg, int len) {
void md_hmac(uint8_t *mac, const uint8_t *in, int in_len, const uint8_t *key,
    int key_len) {
void md_kdf(uint8_t *key, int key_len, const uint8_t *in,
		int in_len) {
void md_mgf(uint8_t *key, int key_len, const uint8_t *in,
		int in_len) {
void md_map_sh224(uint8_t *hash, const uint8_t *msg, int len) {
void md_map_sh256(uint8_t *hash, const uint8_t *msg, int len) {
void md_map_sh384(uint8_t *hash, const uint8_t *msg, int len) {
void md_map_sh512(uint8_t *hash, const uint8_t *msg, int len) {
	int i, j, len = bn_bits(a) + 1;
	int i, j, len = bn_bits(a) + 1;
	int i, len = bn_bits(a) + 1;
	int i, len = bn_bits(a) + 1;
	int i, j, len = bn_bits(a) + 1;
int rand_check(uint8_t *buf, int size) {
static void rand_hash(uint8_t *out, int out_len, uint8_t *in, int in_len) {
	int len = RLC_CEIL(out_len, RLC_MD_LEN);
static int rand_inc(uint8_t *data, int size, int digit) {
static int rand_add(uint8_t *state, uint8_t *hash, int size) {
static void rand_gen(uint8_t *out, int out_len) {
void rand_bytes(uint8_t *buf, int size) {
void rand_seed(uint8_t *buf, int size) {
	int len = (RLC_RAND_SIZE - 1) / 2;
int util_bits_dig(dig_t a) {
			int len = RLC_CEIL(RLC_BN_BITS, 8);
			int len = RLC_CEIL(RLC_BN_BITS, 8);
	int bits, code = RLC_ERR;
	int w, k, l;
	int l, code = RLC_ERR;
	int len = sizeof(out) / 2, code = RLC_ERR;

Fixed code:
	size_t len;
		size_t len;
			size_t len = RLC_BN_BITS + 1;
		size_t len = RLC_BN_BITS + 1;
	dig_t prime = 0xFB;
	BENCH_ONE("cp_bdpe_gen", cp_bdpe_gen(pub, prv, prime, RLC_BN_BITS), 1);
		in = out[0] % prime;
		in = out[0] % prime;
	BENCH_FEW("ep2_null", ep2_null(a[i]), 1);
	BENCH_FEW("ep2_new", ep2_new(a[i]), 1);
	BENCH_FEW("ep2_free", ep2_free(a[i]), 1);
#define RLC_BN_BITS 	((size_t)BN_PRECI)
#define RLC_BN_DIGS		((size_t)RLC_CEIL(BN_PRECI, RLC_DIG))
#define RLC_BN_SIZE		((size_t)(2 * RLC_BN_DIGS + 2))
#define RLC_BN_SIZE		((size_t)(RLC_BN_DIGS + 1))
#define RLC_BN_SIZE		((size_t)RLC_BN_DIGS)
	size_t alloc;
	size_t used;
void bn_make(bn_t a, size_t digits);
void bn_grow(bn_t a, size_t digits);
size_t bn_bits(const bn_t a);
int bn_get_bit(const bn_t a, size_t bit);
void bn_set_bit(bn_t a, size_t bit, int value);
size_t bn_ham(const bn_t a);
void bn_set_2b(bn_t a, size_t b);
void bn_rand(bn_t a, int sign, size_t bits);
size_t bn_size_str(const bn_t a, unsigned int radix);
void bn_read_str(bn_t a, const char *str, size_t len, unsigned int radix);
void bn_write_str(char *str, size_t len, const bn_t a, unsigned radix);
size_t bn_size_bin(const bn_t a);
void bn_read_bin(bn_t a, const uint8_t *bin, size_t len);
void bn_write_bin(uint8_t *bin, size_t len, const bn_t a);
size_t bn_size_raw(const bn_t a);
void bn_read_raw(bn_t a, const dig_t *raw, size_t len);
void bn_write_raw(dig_t *raw, size_t len, const bn_t a);
void bn_lsh(bn_t c, const bn_t a, unsigned int bits);
void bn_rsh(bn_t c, const bn_t a, unsigned int bits);
void bn_gen_prime_basic(bn_t a, size_t bits);
void bn_gen_prime_safep(bn_t a, size_t bits);
void bn_gen_prime_stron(bn_t a, size_t bits);
int bn_gen_prime_factor(bn_t a, bn_t b, size_t abits, size_t bbits);
void bn_rec_win(uint8_t *win, size_t *len, const bn_t k, size_t w);
void bn_rec_slw(uint8_t *win, size_t *len, const bn_t k, size_t w);
void bn_rec_naf(int8_t *naf, size_t *len, const bn_t k, size_t w);
void bn_rec_tnaf(int8_t *tnaf, size_t *len, const bn_t k, int8_t u, size_t m,
		size_t w);
void bn_rec_rtnaf(int8_t *tnaf, size_t *len, const bn_t k, int8_t u, size_t m,
		size_t w);
void bn_rec_tnaf_get(uint8_t *t, int8_t *beta, int8_t *gama, int8_t u,
		size_t w);
void bn_rec_tnaf_mod(bn_t r0, bn_t r1, const bn_t k, int u, size_t m);
void bn_rec_reg(int8_t *naf, size_t *len, const bn_t k, size_t n, size_t w);
void bn_rec_jsf(int8_t *jsf, size_t *len, const bn_t k, const bn_t l);
int cp_rsa_gen(rsa_t pub, rsa_t prv, size_t bits);
int cp_bls_sig(g1_t s, const uint8_t *msg, size_t len, const bn_t d);
void eb_read_bin(eb_t a, const uint8_t *bin, size_t len);
void eb_write_bin(uint8_t *bin, size_t len, const eb_t a, int pack);
void eb_map(eb_t p, const uint8_t *msg, size_t len);
void ed_map(ed_t p, const uint8_t *msg, size_t len);
void ed_map_dst(ed_t p, const uint8_t *msg, size_t len, const uint8_t *dst,
		size_t dst_len);
void ed_read_bin(ed_t a, const uint8_t *bin, size_t len);
void ed_write_bin(uint8_t *bin, size_t len, const ed_t a, int pack);
void ep_read_bin(ep_t a, const uint8_t *bin, size_t len);
void ep_write_bin(uint8_t *bin, size_t len, const ep_t a, int pack);
void ep_map_from_field(ep_t p, const uint8_t *uniform_bytes, size_t len);
void ep_map(ep_t p, const uint8_t *msg, size_t len);
void ep_map_dst(ep_t p, const uint8_t *msg, size_t len, const uint8_t *dst,
		size_t dst_len);
void ep2_read_bin(ep2_t a, const uint8_t *bin, size_t len);
void ep2_write_bin(uint8_t *bin, size_t len, const ep2_t a, int pack);
void ep2_mul_sim_inter(ep2_t r, const ep2_t p, const bn_t k, const ep2_t q,
			const bn_t m);
void ep2_mul_sim_joint(ep2_t r, const ep2_t p, const bn_t k, const ep2_t q,
			const bn_t m);
void ep2_mul_sim_lot(ep2_t r, const ep2_t p[], const bn_t k[], size_t n);
void ep2_mul_sim_dig(ep2_t r, const ep2_t p[], const dig_t k[], size_t len);
void ep2_map_from_field(ep2_t p, const uint8_t *uniform_bytes, size_t len);
void ep2_map(ep2_t p, const uint8_t *msg, size_t len);
void ep2_map_dst(ep2_t p, const uint8_t *msg, size_t len, const uint8_t *dst,
		size_t dst_len);
void ep4_read_bin(ep4_t a, const uint8_t *bin, size_t len);
void ep4_write_bin(uint8_t *bin, size_t len, const ep4_t a, int pack);
void ep4_mul_sim_lot(ep4_t r, const ep4_t p[], const bn_t k[], size_t n);
void ep4_mul_sim_dig(ep4_t r, const ep4_t p[], const dig_t k[], size_t len);
void ep4_map(ep4_t p, const uint8_t *msg, size_t len);
void ep4_map_dst(ep4_t p, const uint8_t *msg, size_t len, const uint8_t *dst,
		size_t dst_len);
#define RLC_FB_BITS 	((size_t)FB_POLYN)
#define RLC_FB_DIGS		((size_t)RLC_CEIL(RLC_FB_BITS, RLC_DIG))
#define RLC_FB_BYTES 	((size_t)RLC_CEIL(RLC_FB_BITS, 8))
int fb_get_bit(const fb_t a, size_t bit);
void fb_set_bit(fb_t a, size_t bit, int value);
size_t fb_bits(const fb_t a);
size_t fb_size_str(const fb_t a, unsigned int radix);
void fb_read_str(fb_t a, const char *str, size_t len, unsigned int radix);
void fb_write_str(char *str, size_t len, const fb_t a, unsigned int radix);
 * @param[in] bin			- the byte vector.,
void fb_read_bin(fb_t a, const uint8_t *bin, size_t len);
void fb_write_bin(uint8_t *bin, size_t len, const fb_t a);
#define RLC_FP_BITS 	((size_t)FP_PRIME)
#define RLC_FP_DIGS 	((size_t)RLC_CEIL(RLC_FP_BITS, RLC_DIG))
#define RLC_FP_BYTES 	((size_t)RLC_CEIL(RLC_FP_BITS, 8))
void fp_prime_set_pmers(const int *spars, size_t len);
 * Assigns the prime field modulus to a parametrization from a family of
int fp_get_bit(const fp_t a, size_t bit);
void fp_set_bit(fp_t a, size_t bit, int value);
size_t fp_bits(const fp_t a);
size_t fp_size_str(const fp_t a, unsigned int radix);
void fp_read_str(fp_t a, const char *str, size_t len, unsigned int radix);
void fp_write_str(char *str, size_t len, const fp_t a, unsigned int radix);
void fp_read_bin(fp_t a, const uint8_t *bin, size_t len);
void fp_write_bin(uint8_t *bin, size_t len, const fp_t a);
void fp2_read_bin(fp2_t a, const uint8_t *bin, size_t len);
void fp2_write_bin(uint8_t *bin, size_t len, const fp2_t a, int pack);
void fp3_read_bin(fp3_t a, const uint8_t *bin, size_t len);
void fp3_write_bin(uint8_t *bin, size_t len, const fp3_t a);
void fp4_read_bin(fp4_t a, const uint8_t *bin, size_t len);
void fp4_write_bin(uint8_t *bin, size_t len, const fp4_t a);
void fp6_read_bin(fp6_t a, const uint8_t *bin, size_t len);
void fp6_write_bin(uint8_t *bin, size_t len, const fp6_t a);
void fp8_read_bin(fp8_t a, const uint8_t *bin, size_t len);
void fp8_write_bin(uint8_t *bin, size_t len, const fp8_t a);
void fp9_read_bin(fp9_t a, const uint8_t *bin, size_t len);
void fp9_write_bin(uint8_t *bin, size_t len, const fp9_t a);
void fp12_read_bin(fp12_t a, const uint8_t *bin, size_t len);
void fp12_write_bin(uint8_t *bin, size_t len, const fp12_t a, int pack);
void fp2_exp_cyc_sim(fp2_t e, const fp2_t a, const bn_t b, const fp2_t c,
		const bn_t d);
void fp12_exp_cyc_sim(fp12_t e, const fp12_t a, const bn_t b, const fp12_t c,
		const bn_t d);
void fp12_exp_cyc_sps(fp12_t c, const fp12_t a, const int *b, size_t l, int s);
void fp18_read_bin(fp18_t a, const uint8_t *bin, size_t len);
void fp18_write_bin(uint8_t *bin, size_t len, const fp18_t a);
void fp24_read_bin(fp24_t a, const uint8_t *bin, size_t len);
void fp24_write_bin(uint8_t *bin, size_t len, const fp24_t a, int pack);
void fp24_exp_cyc_sps(fp24_t c, const fp24_t a, const int *b, size_t l, int s);
void fp48_read_bin(fp48_t a, const uint8_t *bin, size_t len);
void fp48_write_bin(uint8_t *bin, size_t len, const fp48_t a, int pack);
void fp48_exp_cyc_sps(fp48_t c, const fp48_t a, const int *b, size_t l, int s);
void fp54_read_bin(fp54_t a, const uint8_t *bin, size_t len);
void fp54_write_bin(uint8_t *bin, size_t len, const fp54_t a, int pack);
void fp54_exp_cyc_sps(fp54_t c, const fp54_t a, const int *b, size_t l, int s);
void md_map_sh224(uint8_t *hash, const uint8_t *msg, size_t len);
void md_map_sh256(uint8_t *hash, const uint8_t *msg, size_t len);
void md_map_sh384(uint8_t *hash, const uint8_t *msg, size_t len);
void md_map_sh512(uint8_t *hash, const uint8_t *msg, size_t len);
void md_map_b2s160(uint8_t *hash, const uint8_t *msg, size_t len);
void md_map_b2s256(uint8_t *hash, const uint8_t *msg, size_t len);
void md_kdf(uint8_t *key, size_t key_len, const uint8_t *in, size_t in_len);
void md_mgf(uint8_t *mask, size_t mask_len, const uint8_t *in, size_t in_len);
void md_hmac(uint8_t *mac, const uint8_t *in, size_t in_len, const uint8_t *key,
		size_t key_len);
void md_xmd_sh224(uint8_t *buf, size_t buf_len, const uint8_t *in,
		size_t in_len, const uint8_t *dst, size_t dst_len);
void md_xmd_sh256(uint8_t *buf, size_t buf_len, const uint8_t *in,
		size_t in_len, const uint8_t *dst, size_t dst_len);
void md_xmd_sh384(uint8_t *buf, size_t buf_len, const uint8_t *in,
		size_t in_len, const uint8_t *dst, size_t dst_len);
void md_xmd_sh512(uint8_t *buf, size_t buf_len, const uint8_t *in,
		size_t in_len, const uint8_t *dst, size_t dst_len);
void rand_seed(uint8_t *buf, size_t size);
void rand_seed(void (*callback)(uint8_t *, size_t, void *), void *arg);
int rand_check(uint8_t *buf, size_t size);
void rand_bytes(uint8_t *buf, size_t size);
size_t util_bits_dig(dig_t a);
			if (bn_bits(x) > RLC_DIG) {
				bn_rsh(u, x, bn_bits(x) - RLC_DIG);
				bn_rsh(v, y, bn_bits(x) - RLC_DIG);
			} else {
				bn_copy(u, x);
				bn_copy(v, y);
			}
				if (bn_bits(x) > 2 * RLC_DIG) {
					bn_rsh(u, x, bn_bits(x) - 2 * RLC_DIG);
					bn_rsh(v, y, bn_bits(x) - 2 * RLC_DIG);
				} else {
					bn_copy(u, x);
					bn_copy(v, y);
				}
				if (bn_bits(u) > RLC_DIG) {
					bn_rsh(t0, u, bn_bits(u) - RLC_DIG);
					bn_rsh(t1, v, bn_bits(u) - RLC_DIG);
				} else {
					bn_copy(t0, u);
					bn_copy(t1, v);
				}
			if (bn_bits(x) > RLC_DIG) {
				bn_rsh(u, x, bn_bits(x) - RLC_DIG);
				bn_rsh(v, y, bn_bits(x) - RLC_DIG);
			} else {
				bn_copy(u, x);
				bn_copy(v, y);
			}
				if (bn_bits(x) > 2 * RLC_DIG) {
					bn_rsh(u, x, bn_bits(x) - 2 * RLC_DIG);
					bn_rsh(v, y, bn_bits(x) - 2 * RLC_DIG);
				} else {
					bn_copy(u, x);
					bn_copy(v, y);
				}
				if (bn_bits(u) > RLC_DIG) {
					bn_rsh(t0, u, bn_bits(u) - RLC_DIG);
					bn_rsh(t1, v, bn_bits(u) - RLC_DIG);
				} else {
					bn_copy(t0, u);
					bn_copy(t1, v);
				}
void bn_make(bn_t a, size_t digits) {
void bn_grow(bn_t a, size_t digits) {
		if (a->used == 0) {
	size_t l, w = 1;
	for (size_t i = 0; i < RLC_TABLE_SIZE; i++) {
	l = bn_bits(b);
	if (l <= 21) {
	} else if (l <= 32) {
	} else if (l <= 128) {
	} else if (l <= 256) {
	} else if (l <= 512) {
		for (size_t i = 0; i < (1 << (w - 1)); i++) {
		for (size_t i = 1; i < 1 << (w - 1); i++) {
		for (size_t i = 0; i < l; i++) {
				for (size_t j = 0; j < util_bits_dig(win[i]); j++) {
		for (size_t i = 0; i < (1 << (w - 1)); i++) {
		while (!bn_is_zero(r) && bn_is_even(r)) {
void bn_gen_prime_basic(bn_t a, size_t bits) {
void bn_gen_prime_safep(bn_t a, size_t bits) {
void bn_gen_prime_stron(bn_t a, size_t bits) {
int bn_gen_prime_factor(bn_t a, bn_t b, size_t abits, size_t bbits) {
static char get_bits(const bn_t a, size_t from, size_t to) {
void bn_rec_win(uint8_t *win, size_t *len, const bn_t k, size_t w) {
void bn_rec_slw(uint8_t *win, size_t *len, const bn_t k, size_t w) {
void bn_rec_naf(int8_t *naf, size_t *len, const bn_t k, size_t w) {
void bn_rec_tnaf_get(uint8_t *t, int8_t *beta, int8_t *gama, int8_t u,
		size_t w) {
void bn_rec_tnaf_mod(bn_t r0, bn_t r1, const bn_t k, int u, size_t m) {
void bn_rec_tnaf(int8_t *tnaf, size_t *len, const bn_t k, int8_t u, size_t m,
		size_t w) {
void bn_rec_rtnaf(int8_t *tnaf, size_t *len, const bn_t k, int8_t u, size_t m,
		size_t w) {
void bn_rec_reg(int8_t *naf, size_t *len, const bn_t k, size_t n, size_t w) {
void bn_rec_jsf(int8_t *jsf, size_t *len, const bn_t k, const bn_t l) {
	int r1, r2;
	size_t bits;
void bn_lsh(bn_t c, const bn_t a, unsigned int bits) {
void bn_rsh(bn_t c, const bn_t a, unsigned int bits) {

	if (a->used > digits) {
		c->used = a->used - digits;
	} else {
		c->used = 0;
	}
			while (bn_is_even(t0) && !bn_is_zero(t0)) {
	size_t bits;
	int cmp;
		bn_zero(l);
		if (bits >= 2) {
			bn_set_2b(l, (bits >> 1) - 1);
		}
size_t bn_bits(const bn_t a) {
int bn_get_bit(const bn_t a, size_t bit) {
void bn_set_bit(bn_t a, size_t bit, int value) {
size_t bn_ham(const bn_t a) {
void bn_set_2b(bn_t a, size_t b) {
	if (b >= RLC_BN_SIZE * RLC_DIG) {
		RLC_THROW(ERR_NO_VALID);
void bn_rand(bn_t a, int sign, size_t bits) {
size_t bn_size_str(const bn_t a, unsigned int radix) {
void bn_read_str(bn_t a, const char *str, size_t len, unsigned int radix) {
void bn_write_str(char *str, size_t len, const bn_t a, unsigned int radix) {
size_t bn_size_bin(const bn_t a) {
void bn_read_bin(bn_t a, const uint8_t *bin, size_t len) {
void bn_write_bin(uint8_t *bin, size_t len, const bn_t a) {
size_t bn_size_raw(const bn_t a) {
void bn_read_raw(bn_t a, const dig_t *raw, size_t len) {
void bn_write_raw(dig_t *raw, size_t len, const bn_t a) {
int cp_bls_sig(g1_t s, const uint8_t *msg, size_t len, const bn_t d) {

		bn_rand_mod(d, n);
		g2_mul_gen(y, d);
		if (bls) {
			result = cp_bls_gen(sk, pk);
		} else {
			if (cp_ecdsa_gen(sk, g1) == RLC_OK) {
				fp_copy(pk->x[0], g1->x);
				fp_copy(pk->y[0], g1->y);
			} else {
				result = RLC_ERR;
			}
		}
	size_t len, dlen = strlen(data);
	int result = RLC_OK;
	size_t len, dlen = strlen(data);
	int result = 1;
	size_t len, dlen = strlen(data);
	int result = 1;
		RLC_FREE(_x);
static int pad_pkcs1(bn_t m, int *p_len, size_t m_len, size_t k_len, int op) {
	size_t len;
	int result = RLC_ERR;
		switch (op) {
static int pad_pkcs2(bn_t m, int *p_len, size_t m_len, size_t k_len, int op) {
		switch (op) {
int cp_rsa_gen(rsa_t pub, rsa_t prv, size_t bits) {
	size_t size, len1 = strlen(id1), len2 = strlen(id2);
	int first = 0, result = RLC_OK;
	size_t len;
	int result = RLC_OK;
	size_t len;
	int result = RLC_OK;
	size_t len;
	ec_t Z, t;
	int result = 0;
void eb_map(eb_t p, const uint8_t *msg, size_t len) {
	int i, n;
	size_t l;
	int i, n;
	size_t l;
	int i, n;
	size_t l;
	int i, n;
	size_t l;
	size_t bits;
		for (int i = bits - 1; i >= 0; i--) {
			int j = bn_get_bit(t, i);
	int i, j, trc, cof;
	size_t l;
	int i, n0, n1, w, g;
	size_t l, l0, l1;
	int i, n0, n1, w, g;
	size_t l, l0, l1;
	size_t l0, l1, w = EB_WIDTH / 2;
	int i, u_i, offset;
	size_t len;
void eb_read_bin(eb_t a, const uint8_t *bin, size_t len) {
void eb_write_bin(uint8_t *bin, size_t len, const eb_t a, int pack) {
void ed_map_dst(ed_t p, const uint8_t *msg, size_t len, const uint8_t *dst,
		size_t dst_len) {
void ed_map(ed_t p, const uint8_t *msg, size_t len) {
	int i, n;
	size_t l;
	int i, j, n;
	size_t l;
	size_t l;
		for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i ++) {
		for (size_t i = 1; i < (1 << (EP_WIDTH - 1)); i++) {
		for (size_t i = 0; i < l; i++) {
				for (size_t j = 0; j < util_bits_dig(win[i]); j++) {
		for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i++) {
	size_t l;
	int i, n;
	size_t l;
	int i, n0, n1, w, gen;
	size_t l, l0, l1;
	size_t l0, l1, w = ED_WIDTH / 2;
	int i, u_i, offset;
	size_t l;
	int i, j;
	ed_t *_p = RLC_ALLOCA(ed_t, n);
	size_t l, *_l = RLC_ALLOCA(size_t, n);
void ed_read_bin(ed_t a, const uint8_t *bin, size_t len) {
void ed_write_bin(uint8_t *bin, size_t len, const ed_t a, int pack) {
TMPL_MAP_HORNER(fp, fp_st);

TMPL_MAP_ISOGENY_MAP(ep, fp, iso);


#define EP_MAP_COPY_COND(O, I, C) dv_copy_cond(O, I, RLC_FP_DIGS, C)
TMPL_MAP_SSWU(ep, fp, dig_t, EP_MAP_COPY_COND);

TMPL_MAP_SVDW(ep, fp, dig_t, EP_MAP_COPY_COND);


/* caution: this function overwrites k, which used as an auxiliary variable */
void ep_map_from_field(ep_t p, const uint8_t *uniform_bytes, size_t len) {
		void (*const map_fn)(ep_t, fp_t) = (ep_curve_is_ctmap() ||
#define EP_MAP_CONVERT_BYTES(IDX)											\
		do {																\
			bn_read_bin(k, uniform_bytes + IDX * len_per_elm, len_per_elm);	\
			fp_prime_conv(t, k);											\
		} while (0)

#define EP_MAP_APPLY_MAP(PT)												\
		do {																\
			/* check sign of t */											\
			neg = fp_sgn0(t, k);											\
			/* convert */													\
			map_fn(PT, t);													\
			/* compare sign of y and sign of t; fix if necessary */			\
			neg = neg != fp_sgn0(PT->y, k);									\
			fp_neg(t, PT->y);												\
			dv_copy_cond(PT->y, t, RLC_FP_DIGS, neg);						\
		} while (0)
void ep_map_dst(ep_t p, const uint8_t *msg, size_t len, const uint8_t *dst,
		size_t dst_len) {
void ep_map(ep_t p, const uint8_t *msg, size_t len) {
	int i, n0, n1, s0, s1;
	size_t l, l0, l1;
	size_t l;
		for (int i = 0; i < (1 << (EP_WIDTH - 2)); i++) {
		for (int i = l - 1; i >= 0; i--) {
		for (int i = 0; i < (1 << (EP_WIDTH - 2)); i++) {
	int i, j, n0, n1, s0, s1, b0, b1;
	size_t l;
	int i, j, n;
	size_t l;
	size_t l;
		for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i ++) {
		for (size_t i = 1; i < (1 << (EP_WIDTH - 1)); i++) {
		for (size_t i = 0; i < l; i++) {
				for (size_t j = 0; j < util_bits_dig(win[i]); j++) {
		for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i++) {
	size_t bits;
		for (int i = bits - 1; i >= 0; i--) {
			int j = bn_get_bit(l, i);
	size_t l;
	int i, n;
	size_t l;
	int i, sk0, sk1, sl0, sl1, w, g = 0;
	size_t l, l0, l1, l2, l3;
	int i, j, m, sk;
	size_t l, _l[2];
	int i, w, gen;
	size_t l, l0, l1;
	int i, j;
	ep_t *_p = RLC_ALLOCA(ep_t, n);
	size_t l, *_l = RLC_ALLOCA(size_t, n);
	size_t l0, l1, w = EP_WIDTH / 2;
	int i, u_i, offset;
	size_t l;
void ep_read_bin(ep_t a, const uint8_t *bin, size_t len) {
void ep_write_bin(uint8_t *bin, size_t len, const ep_t a, int pack) {
#define EP2_MAP_COPY_COND(O, I, C)											\
	do {																	\
		dv_copy_cond(O[0], I[0], RLC_FP_DIGS, C);							\
		dv_copy_cond(O[1], I[1], RLC_FP_DIGS, C);							\
void ep2_map_from_field(ep2_t p, const uint8_t *uniform_bytes, size_t len) {
	bn_t k;
	fp2_t t;
	ep2_t q;
	int neg;
	/* enough space for two extension field elements plus extra bytes for uniformity */
	const int lpe = (FP_PRIME + ep_param_level() + 7) / 8;

	bn_null(k);
	fp2_null(t);
	ep2_null(q);

	RLC_TRY {
		if (len != 2 * lpe) {
			RLC_THROW(ERR_NO_VALID);
		}

		bn_new(k);
		fp2_new(t);
		ep2_new(q);

		/* which hash function should we use? */
		const int abNeq0 = (ep2_curve_opt_a() != RLC_ZERO) &&
				(ep2_curve_opt_b() != RLC_ZERO);
		void (*const map_fn)(ep2_t, fp2_t) = (ep2_curve_is_ctmap() ||
				abNeq0) ? ep2_map_sswu : ep2_map_svdw;

#define EP2_MAP_CONVERT_BYTES(IDX)											\
		do {																\
			bn_read_bin(k, uniform_bytes + 2 * IDX * lpe, lpe);				\
			fp_prime_conv(t[0], k);											\
			bn_read_bin(k, uniform_bytes + (2 * IDX + 1) * lpe, lpe);		\
			fp_prime_conv(t[1], k);											\
	    } while (0)

#define EP2_MAP_APPLY_MAP(PT)												\
		do {																\
            /* sign of t */													\
            neg = fp2_sgn0(t, k);											\
            /* convert */													\
            map_fn(PT, t);													\
            /* compare sign of y to sign of t; fix if necessary */			\
            neg = neg != fp2_sgn0(PT->y, k);								\
            fp2_neg(t, PT->y);												\
            dv_copy_cond(PT->y[0], t[0], RLC_FP_DIGS, neg);					\
            dv_copy_cond(PT->y[1], t[1], RLC_FP_DIGS, neg);					\
		} while (0)

		/* first map invocation */
		EP2_MAP_CONVERT_BYTES(0);
		EP2_MAP_APPLY_MAP(p);
		TMPL_MAP_CALL_ISOMAP(ep2, p);

		/* second map invocation */
		EP2_MAP_CONVERT_BYTES(1);
		EP2_MAP_APPLY_MAP(q);
		TMPL_MAP_CALL_ISOMAP(ep2, q);

		/* XXX(rsw) could add p and q and then apply isomap,
		 * but need ep_add to support addition on isogeny curves */
		/* sum the result */
		ep2_add(p, p, q);
		ep2_norm(p, p);
		ep2_mul_cof(p, p);
	}
	RLC_CATCH_ANY {
		RLC_THROW(ERR_CAUGHT);
	}
	RLC_FINALLY {
		bn_free(k);
		fp2_free(t);
		ep2_free(q);
	}
void ep2_map_dst(ep2_t p, const uint8_t *msg, size_t len, const uint8_t *dst,
		size_t dst_len) {
	/* enough space for two field elements plus extra bytes for uniformity */
	const int lpe = (FP_PRIME + ep_param_level() + 7) / 8;
	uint8_t *pseudo_random_bytes = RLC_ALLOCA(uint8_t, 4 * lpe);

	RLC_TRY {
		/* XXX(rsw) See note in ep/relic_ep_map.c about using MD_MAP. */
		/* hash to a pseudorandom string using md_xmd */
		md_xmd(pseudo_random_bytes, 4 * lpe, msg, len, dst, dst_len);
		ep2_map_from_field(p, pseudo_random_bytes, 2 * lpe);
	}
	RLC_CATCH_ANY {
		RLC_THROW(ERR_CAUGHT);
	}
	RLC_FINALLY {
		RLC_FREE(pseudo_random_bytes);
	}
void ep2_map(ep2_t p, const uint8_t *msg, size_t len) {
	size_t l, _l[4];
		for (int i = 0; i < 4; i++) {
		for (int i = 0; i < 4; i++) {
		for (int j = l - 1; j >= 0; j--) {
			for (int i = 0; i < 4; i++) {
		for (int i = 0; i < 4; i++) {
	size_t l, n;
		for (int i = 0; i < (1 << (EP_WIDTH - 2)); i++) {
		for (int i = l - 1; i >= 0; i--) {
		for (int i = 0; i < (1 << (EP_WIDTH - 2)); i++) {
	size_t l;
		for (int i = l - 2; i >= 0; i--) {
	size_t l;
		for (int i = 0; i < (1 << (EP_WIDTH - 1)); i ++) {
		for (size_t i = 1; i < (1 << (EP_WIDTH - 1)); i++) {
		for (size_t i = 0; i < l; i++) {
				for (size_t j = 0; j < util_bits_dig(win[i]); j++) {
		for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i++) {
	size_t l;
	size_t len;
	int n;
	for (int i = len - 1; i >= 0; i--, t--) {
	size_t l, _l[4];
		for (int i = 0; i < 4; i++) {
		for (int i = 0; i < 4; i++) {
		for (int i = l - 1; i >= 0; i--) {
			for (int j = 0; j < 4; j++) {
		for (int i = 0; i < 4; i++) {
	int i, n0, n1, w, gen;
	size_t l, l0, l1;
	size_t l0, l1, w = EP_WIDTH / 2;
	int i, u_i, offset;
	size_t l;
void ep2_mul_sim_dig(ep2_t r, const ep2_t p[], const dig_t k[], size_t len) {
void ep2_mul_sim_lot(ep2_t r, const ep2_t p[], const bn_t k[], size_t n) {
	const size_t len = RLC_FP_BITS + 1;
	int i, j, m;
	size_t l, _l[4];
void ep2_read_bin(ep2_t a, const uint8_t *bin, size_t len) {
void ep2_write_bin(uint8_t *bin, size_t len, const ep2_t a, int pack) {
void ep4_map(ep4_t p, const uint8_t *msg, size_t len) {
	int sign, i, j;
	size_t l, _l[8];
	int i, n;
	size_t l;
	size_t l;
		for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i ++) {
		for (size_t i = 1; i < (1 << (EP_WIDTH - 1)); i++) {
		for (size_t i = 0; i < l; i++) {
				for (size_t j = 0; j < util_bits_dig(win[i]); j++) {
		for (size_t i = 0; i < (1 << (EP_WIDTH - 1)); i++) {
	for (int i = 2; i < (1 << (EP_DEPTH - 2)); i++) {
	for (int i = 1; i < (1 << (EP_DEPTH - 2)); i++) {
	size_t len;
	int n;
	for (int i = len - 1; i >= 0; i--, t--) {
	int i, n0, n1, w, gen;
	size_t l, l0, l1;
	size_t l0, l1, w = EP_WIDTH / 2;
	int i, u_i, offset;
	size_t l;
void ep4_mul_sim_dig(ep4_t r, const ep4_t p[], const dig_t k[], size_t len) {
void ep4_mul_sim_lot(ep4_t r, const ep4_t p[], const bn_t k[], size_t n) {
	const size_t len = RLC_FP_BITS + 1;
	int i, j, m;
	size_t l, *_l = RLC_ALLOCA(size_t, 8 * n);
void ep4_read_bin(ep4_t a, const uint8_t *bin, size_t len) {
void ep4_write_bin(uint8_t *bin, size_t len, const ep4_t a, int pack) {
	size_t l;
		for (int i = l - 2; i >= 0; i--) {
	size_t l;
	for (size_t i = 0; i < (1 << (FB_WIDTH - 1)); i++) {
		for (size_t i = 0; i < (1 << (FB_WIDTH - 1)); i ++) {
		for (size_t i = 1; i < 1 << (FB_WIDTH - 1); i++) {
		for (size_t i = 0; i < l; i++) {
				for (size_t j = 0; j < util_bits_dig(win[i]); j++) {
		for (size_t i = 0; i < (1 << (FB_WIDTH - 1)); i++) {
static int valid_radix(unsigned int radix) {
static int log_radix(unsigned int radix) {
int fb_get_bit(const fb_t a, size_t bit) {
void fb_set_bit(fb_t a, size_t bit, int value) {
size_t fb_bits(const fb_t a) {
	size_t bits, digits;
	for (int i = RLC_FB_DIGS - 1; i > 0; i--) {
size_t fb_size_str(const fb_t a, unsigned int radix) {
	size_t digits = 0;
void fb_read_str(fb_t a, const char *str, size_t len, unsigned int radix) {
void fb_write_str(char *str, size_t len, const fb_t a, unsigned int radix) {
void fb_read_bin(fb_t a, const uint8_t *bin, size_t len) {
void fb_write_bin(uint8_t *bin, size_t len, const fb_t a) {
	size_t l;
		for (int i = l - 2; i >= 0; i--) {
	size_t l;
	for (size_t i = 0; i < (1 << (FP_WIDTH - 1)); i++) {
		for (size_t i = 0; i < (1 << (FP_WIDTH - 1)); i ++) {
		for (size_t i = 1; i < 1 << (FP_WIDTH - 1); i++) {
		for (size_t i = 0; i < l; i++) {
				for (size_t j = 0; j < util_bits_dig(win[i]); j++) {
		for (size_t i = 0; i < (1 << (FP_WIDTH - 1)); i++) {
	size_t len = bn_bits(x) + 1;
void fp_prime_set_pmers(const int *f, size_t len) {
int fp_get_bit(const fp_t a, size_t bit) {
void fp_set_bit(fp_t a, size_t bit, int value) {
size_t fp_bits(const fp_t a) {
size_t fp_size_str(const fp_t a, unsigned int radix) {
	size_t digits = 0;
void fp_read_str(fp_t a, const char *str, size_t len, unsigned int radix) {
void fp_write_str(char *str, size_t len, const fp_t a, unsigned int radix) {
void fp_read_bin(fp_t a, const uint8_t *bin, size_t len) {
			}
void fp_write_bin(uint8_t *bin, size_t len, const fp_t a) {
	size_t l;
		for (int i = 0; i < (1 << (FP_WIDTH - 2)); i ++) {
		for (int i = l - 1; i >= 0; i--, k--) {
		for (int i = 0; i < (1 << (FP_WIDTH - 2)); i++) {
	size_t l;
		for (int i = 0; i < (1 << (FP_WIDTH - 2)); i ++) {
		for (int i = l - 1; i >= 0; i--, k--) {
		for (int i = 0; i < (1 << (FP_WIDTH - 2)); i++) {
	size_t j, k, l, w = bn_ham(b);
		size_t _l[4];
			for (int i = 0; i < 4; i++) {
				for (int i = 0; i < 4; i++) {
				for (int i = l - 1; i >= 0; i--) {
					for (int j = 0; j < 4; j++) {
				for (int i = bn_bits(b) - 2; i >= 0; i--) {
			for (int i = 0; i < 4; i++) {
			for (int i = 0; i < w; i++) {
			for (size_t i = 1; i < bn_bits(b); i++) {
			for (size_t i = j; i < k; i++) {
			for (size_t i = 0; i < w; i++) {
	int n0, n1;
	size_t l, l0, l1;
		for (int i = 0; i < (1 << (FP_WIDTH - 2)); i ++) {
			for (size_t i = 0; i < l0; i++) {
			for (size_t i = 0; i < l1; i++) {
		for (int i = l - 1; i >= 0; i--, _k--, _m--) {
		for (int i = 0; i < (1 << (FP_WIDTH - 2)); i++) {
void fp12_exp_cyc_sps(fp12_t c, const fp12_t a, const int *b, size_t len,
		int sign) {
	size_t i, j, k, w = len;
	size_t j, k, w = bn_ham(b);
		size_t l, _l[8];
			for (int i = 0; i < 8; i++) {
				for (int i = 0; i < 8; i++) {
				for (int i = 0; i < 8; i++) {
				for (int i = l - 1; i >= 0; i--) {
					for (int j = 0; j < 8; j++) {
				for (int i = bn_bits(b) - 2; i >= 0; i--) {
			for (int i = 0; i < 8; i++) {
			for (size_t i = 0; i < w; i++) {
			for (size_t i = 1; i < bn_bits(b); i++) {
			for (size_t i = j; i < k; i++) {
			for (size_t i = 0; i < w; i++) {
	int n0, n1;
	size_t l, l0, l1;
		for (int i = 0; i < (1 << (FP_WIDTH - 2)); i ++) {
			for (size_t i = 0; i < l0; i++) {
			for (size_t i = 0; i < l1; i++) {
		for (int i = l - 1; i >= 0; i--, _k--, _m--) {
		for (int i = 0; i < (1 << (FP_WIDTH - 2)); i++) {
void fp24_exp_cyc_sps(fp24_t c, const fp24_t a, const int *b, size_t len,
		int sign) {
	size_t i, j, k, w = len;
void fp48_exp_cyc_sps(fp48_t c, const fp48_t a, const int *b, size_t len,
		int sign) {
	size_t i, j, k, w = len;
void fp54_exp_cyc_sps(fp54_t c, const fp54_t a, const int *b, size_t len,
		int sign) {
	size_t i, j, k, w = len;
	size_t l;
	size_t l;
	size_t l;
	size_t l;
void fp2_read_bin(fp2_t a, const uint8_t *bin, size_t len) {
void fp2_write_bin(uint8_t *bin, size_t len, const fp2_t a, int pack) {
void fp3_read_bin(fp3_t a, const uint8_t *bin, size_t len) {
void fp3_write_bin(uint8_t *bin, size_t len, const fp3_t a) {
void fp4_read_bin(fp4_t a, const uint8_t *bin, size_t len) {
void fp4_write_bin(uint8_t *bin, size_t len, const fp4_t a) {
void fp6_read_bin(fp6_t a, const uint8_t *bin, size_t len) {
void fp6_write_bin(uint8_t *bin, size_t len, const fp6_t a) {
void fp8_read_bin(fp8_t a, const uint8_t *bin, size_t len) {
void fp8_write_bin(uint8_t *bin, size_t len, const fp8_t a) {
void fp9_read_bin(fp9_t a, const uint8_t *bin, size_t len) {
void fp9_write_bin(uint8_t *bin, size_t len, const fp9_t a) {
void fp12_read_bin(fp12_t a, const uint8_t *bin, size_t len) {
void fp12_write_bin(uint8_t *bin, size_t len, const fp12_t a, int pack) {
void fp18_read_bin(fp18_t a, const uint8_t *bin, size_t len) {
void fp18_write_bin(uint8_t *bin, size_t len, const fp18_t a) {
void fp24_read_bin(fp24_t a, const uint8_t *bin, size_t len) {
void fp24_write_bin(uint8_t *bin, size_t len, const fp24_t a, int pack) {
void fp48_read_bin(fp48_t a, const uint8_t *bin, size_t len) {
void fp48_write_bin(uint8_t *bin, size_t len, const fp48_t a, int pack) {
void fp54_read_bin(fp54_t a, const uint8_t *bin, size_t len) {
void fp54_write_bin(uint8_t *bin, size_t len, const fp54_t a, int pack) {
void md_map_b2s160(uint8_t *hash, const uint8_t *msg, size_t len) {
void md_map_b2s256(uint8_t *hash, const uint8_t *msg, size_t len) {
void md_hmac(uint8_t *mac, const uint8_t *in, size_t in_len, const uint8_t *key,
    size_t key_len) {
void md_kdf(uint8_t *key, size_t key_len, const uint8_t *in, size_t in_len) {
void md_mgf(uint8_t *key, size_t key_len, const uint8_t *in, size_t in_len) {
void md_map_sh224(uint8_t *hash, const uint8_t *msg, size_t len) {
void md_map_sh256(uint8_t *hash, const uint8_t *msg, size_t len) {
void md_map_sh384(uint8_t *hash, const uint8_t *msg, size_t len) {
void md_map_sh512(uint8_t *hash, const uint8_t *msg, size_t len) {
	size_t len = bn_bits(a) + 1;
	int i, j;
	size_t len = bn_bits(a) + 1;
	int i, j;
	size_t len = bn_bits(a) + 1;
	int i;
	size_t len = bn_bits(a) + 1;
	int i;
	size_t len = bn_bits(a) + 1;
	int i, j;
int rand_check(uint8_t *buf, size_t size) {
static void rand_hash(uint8_t *out, size_t out_len, uint8_t *in,
		size_t in_len) {
	size_t len = RLC_CEIL(out_len, RLC_MD_LEN);
static int rand_inc(uint8_t *data, size_t size, int digit) {
static int rand_add(uint8_t *state, uint8_t *hash, size_t size) {
static void rand_gen(uint8_t *out, size_t out_len) {
void rand_bytes(uint8_t *buf, size_t size) {
void rand_seed(uint8_t *buf, size_t size) {
	size_t len = (RLC_RAND_SIZE - 1) / 2;
size_t util_bits_dig(dig_t a) {
			size_t len = RLC_CEIL(RLC_BN_BITS, 8);
			size_t len = RLC_CEIL(RLC_BN_BITS, 8);
	size_t bits;
	int code = RLC_ERR;
	int w, k;
	size_t l;
		core_clean();
	int code = RLC_ERR;
	size_t len = sizeof(out) / 2, code = RLC_ERR;