⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pbc_field.h

📁 这是一个C的源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
/*@manual earithSet ''n'' to ''a/2''*/static inline void element_halve(element_t n, element_t a){    PBC_ASSERT_MATCH2(n, a);    n->field->halve(n, a);}/*@manual earithSet ''n'' to ''a'' times ''a''.*/static inline void element_square(element_t n, element_t a){    PBC_ASSERT_MATCH2(n, a);    n->field->square(n, a);}/*@manual epowSet ''x'' to ''a'' raised to the power ''n'', that is''a'' times ''a'' times ... times ''a'' where there are ''n'' ''a'''s*/static inline void element_pow_mpz(element_t x, element_t a, mpz_t n){    PBC_ASSERT_MATCH2(x, a);    x->field->pow_mpz(x, a, n);}/*@manual epowSet ''x'' to ''a'' raised to the power ''n'', where ''n'' isan element of a ring Z_n for some n (typically the orderof the algebraic structure ''x'' lies in).*/static inline void element_pow_zn(element_t x, element_t a, element_t n){    mpz_t z;    PBC_ASSERT_MATCH2(x, a);    mpz_init(z);    element_to_mpz(z, n);    x->field->pow_mpz(x, a, z);    mpz_clear(z);}/*@manual earithSet ''n'' to -''a''.*/static inline void element_neg(element_t n, element_t a){    PBC_ASSERT_MATCH2(n, a);    n->field->neg(n, a);}/*@manual earithSet ''n'' to the inverse of ''a''.*/static inline void element_invert(element_t n, element_t a){    PBC_ASSERT_MATCH2(n, a);    n->field->invert(n, a);}/*@manual erandomIf the ''e'' lies in a finite algebraic structure,this function assigns a uniformly random element to ''e''.*/static inline void element_random(element_t e){    e->field->random(e);}/*@manual ecmpReturns nonzero if ''n'' is 1, zero otherwise.*/static inline int element_is1(element_t n){    return n->field->is1(n);}/*@manual ecmpReturns nonzero if ''n'' is 0, zero otherwise.*/static inline int element_is0(element_t n){    return n->field->is0(n);}/*@manual ecmpReturns 0 if ''a'' and ''b'' are the same, nonzero otherwise.*/static inline int element_cmp(element_t a, element_t b){    PBC_ASSERT_MATCH2(a, b);    return a->field->cmp(a, b);}/*@manual ecmpReturns nonzero if ''a'' is a perfect square (quadratic residue),zero otherwise.*/static inline int element_is_sqr(element_t a){    return a->field->is_sqr(a);}/*@manual ecmp*/static inline int element_sgn(element_t a){    return a->field->sign(a);}/*@manual ecmpIf ''a'' is zero, returns 0. For nozero ''a'' the behaviour depends onthe algebraic structure, but has the property thatelement_sgn(''a'') = -element_sgn(-''a'')andelement_sgn(''a'') = 0 implies ''a'' = 0 with overwhelming probability.*/static inline int element_sign(element_t a){    return a->field->sign(a);}static inline void element_sqrt(element_t a, element_t b){    PBC_ASSERT_MATCH2(a, b);    a->field->sqrt(a, b);}/*@manual etradeReturns the length in bytes the element ''e'' will take to represent*/static inline int element_length_in_bytes(element_t e){    if (e->field->fixed_length_in_bytes < 0) {	return e->field->length_in_bytes(e);    } else {	return e->field->fixed_length_in_bytes;    }}/*@manual etradeConverts ''e'' to byte, writing the result in the buffer ''data''.The number of bytes it will write can be determined from calling<function>element_length_in_bytes()</function>.Returns number of bytes written.*/static inline int element_to_bytes(unsigned char *data, element_t e){    return e->field->to_bytes(data, e);}/*@manual etradeReads ''e'' from the buffer ''data'', and returnsthe number of bytes read.*/static inline int element_from_bytes(element_t e, unsigned char *data){    return e->field->from_bytes(e, data);}/*@manual epowSets ''x'' = ''a1''^''n1'' times ''a2''^''n2'', and is generally faster thanperforming two separate exponentiations.*/void element_pow2_mpz(element_t x, element_t a1, mpz_t n1,                                 element_t a2, mpz_t n2);/*@manual epowAlso sets ''x'' = ''a1''^''n1'' times ''a2''^''n2'',but ''n1'', ''n2'' must be elements of a ring Z_n for some integer n.*/static inline void element_pow2_zn(element_t x, element_t a1, element_t n1,                                 element_t a2, element_t n2){    mpz_t z1, z2;    mpz_init(z1);    mpz_init(z2);    element_to_mpz(z1, n1);    element_to_mpz(z2, n2);    element_pow2_mpz(x, a1, z1, a2, z2);    mpz_clear(z1);    mpz_clear(z2);}/*@manual epowSets ''x'' = ''a1''^''n1'' times ''a2^n2'' times ''a3''^''n3'',and is generally faster thanperforming three separate exponentiations.*/void element_pow3_mpz(element_t x, element_t a1, mpz_t n1,                                 element_t a2, mpz_t n2,                                 element_t a3, mpz_t n3);/*@manual epowAlso sets ''x'' = ''a1''^''n1'' times ''a2^n2'' times ''a3''^''n3'',but ''n1'', ''n2'', ''n3'' must be elements of a ring Z_n for some integer n.*/static inline void element_pow3_zn(element_t x, element_t a1, element_t n1,                                 element_t a2, element_t n2,                                 element_t a3, element_t n3){    mpz_t z1, z2, z3;    mpz_init(z1);    mpz_init(z2);    mpz_init(z3);    element_to_mpz(z1, n1);    element_to_mpz(z2, n2);    element_to_mpz(z3, n3);    element_pow3_mpz(x, a1, z1, a2, z2, a3, z3);    mpz_clear(z1);    mpz_clear(z2);    mpz_clear(z3);}void field_clear(field_ptr f);element_ptr field_get_nqr(field_ptr f);void field_set_nqr(field_ptr f, element_t nqr);void field_gen_nqr(field_ptr f);void field_init(field_ptr f);static inline int mpz_is0(mpz_t z){    return !mpz_sgn(z);    //return !mpz_cmp_ui(z, 0);}/*@manual etradeAssumes ''e'' is a point on an elliptic curve.Writes the x-coordinate of ''e'' to the buffer ''data''*/int element_to_bytes_x_only(unsigned char *data, element_t e);/*@manual etradeAssumes ''e'' is a point on an elliptic curve.Sets ''e'' to a point withx-coordinate represented by the buffer ''data''. This is not unique.For each ''x''-coordinate, there exist two different points, at leastfor the elliptic curves in PBC. (They are inverses of each other.)*/int element_from_bytes_x_only(element_t e, unsigned char *data);/*@manual etradeAssumes ''e'' is a point on an elliptic curve.Returns the length in bytes needed to hold the x-coordinate of ''e''.*/int element_length_in_bytes_x_only(element_t e);/*@manual etradeIf possible, outputs a compressed form of the element ''e'' tothe buffer of bytes ''data''.Currently only implemented for points on an elliptic curve.*/int element_to_bytes_compressed(unsigned char *data, element_t e);/*@manual etradeSets element ''e'' to the element in compressed form in the buffer of bytes''data''.Currently only implemented for points on an elliptic curve.*/int element_from_bytes_compressed(element_t e, unsigned char *data);/*@manual etradeReturns the number of bytes needed to hold ''e'' in compressed form.Currently only implemented for points on an elliptic curve.*/int element_length_in_bytes_compressed(element_t e);void field_out_info(FILE *out, field_ptr f);/*@manual epowPrepare to exponentiate an element ''in'', and store preprocessing informationin ''p''.*/static inline void element_pp_init(element_pp_t p, element_t in) {    p->field = in->field;    in->field->pp_init(p, in);}/*@manual epowClear ''p''. Should be called after ''p'' is no longer needed.*/static inline void element_pp_clear(element_pp_t p){    p->field->pp_clear(p);}/*@manual epowRaise ''in'' to ''power'' and store the result in ''out'', where ''in''is a previously preprocessed element, that is, the second argumentpassed to a previous <function>element_pp_init</function> call.*/static inline void element_pp_pow(element_t out, mpz_ptr power, element_pp_t p){    p->field->pp_pow(out, power, p);}void pbc_mpz_out_raw_n(unsigned char *data, int n, mpz_t z);void pbc_mpz_from_hash(mpz_t z, mpz_t limit,	unsigned char *data, unsigned int len);void brute_force_dlog(element_t x, element_t g, element_t h);void pollard_rho(element_t x, element_t g, element_t h);void index_calculus_dlog(mpz_t x, mpz_t g, mpz_t h, mpz_t q);#endif //__PBC_FIELD_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -