qarith.h 741 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef _QA_ARITH_H_
  2. #define _QA_ARITH_H
  3. /* shortcut macros. */
  4. #define BN_uiadd1(a) BN_uadd(a, a, BN_value_one())
  5. /**
  6. * Fractions made of bignums.
  7. */
  8. typedef struct bigfraction {
  9. BIGNUM* h; /**< numerator */
  10. BIGNUM* k; /**< denominator */
  11. } bigfraction_t;
  12. typedef struct cf {
  13. bigfraction_t fs[3];
  14. short i;
  15. bigfraction_t x;
  16. BIGNUM* a;
  17. BN_CTX* ctx;
  18. } cf_t;
  19. /* continued fractions utilities. */
  20. cf_t* cf_new(void);
  21. cf_t* cf_init(cf_t *f, BIGNUM *num, BIGNUM *b);
  22. void cf_free(cf_t* f);
  23. bigfraction_t* cf_next(cf_t *f);
  24. /* square root calculation */
  25. int BN_sqrtmod(BIGNUM* dv, BIGNUM* rem, BIGNUM* a, BN_CTX* ctx);
  26. RSA* qa_RSA_recover(const RSA *rsapub, const BIGNUM *p, BN_CTX *ctx);
  27. #endif /* _QA_ARITH_H_ */