12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #pragma once
- #include <stdint.h>
- #include <gmp.h>
- extern const char* p_str;
- extern mpz_t p, q;
- extern const uint64_t gg;
- void group_init();
- void group_clear();
- #define SIZ(x) ((x)->_mp_size)
- #define PTR(x) ((x)->_mp_d)
- #define MPN_NORMALIZE(DST, NLIMBS) \
- do { \
- while (1) \
- { \
- if ((DST)[(NLIMBS) - 1] != 0) \
- break; \
- (NLIMBS)--; \
- } \
- } while (0)
- static inline
- void remp(mpz_t rop)
- {
- int32_t limbs = SIZ(rop) - 24;
- while (limbs > 0) {
-
- uint64_t a[limbs+1];
-
- for (int i = 24; i < SIZ(rop); i++) {
- a[i-24] = PTR(rop)[i];
- PTR(rop)[i] = 0;
- }
- a[limbs] = 0;
- mpn_addmul_1(PTR(rop), a, limbs+1, gg);
- MPN_NORMALIZE(PTR(rop), SIZ(rop));
- limbs = SIZ(rop) - 24;
- }
- if (mpn_cmp(PTR(rop), PTR(p), SIZ(rop)) >= 0) {
- mpn_sub(PTR(rop), PTR(rop), 24, PTR(p), 24);
- MPN_NORMALIZE(PTR(rop), SIZ(rop));
- }
- }
- void powmp_ui(mpz_t rop, const mpz_t base, uint64_t exp);
- #define mpz_mul_modp(rop, op1, op2) mpz_mul(rop, op1, op2); remp(rop);
|