bignum.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. from __future__ import absolute_import, division, print_function
  5. INCLUDES = """
  6. #include <openssl/bn.h>
  7. """
  8. TYPES = """
  9. typedef ... BN_CTX;
  10. typedef ... BN_MONT_CTX;
  11. typedef ... BIGNUM;
  12. typedef int... BN_ULONG;
  13. """
  14. FUNCTIONS = """
  15. #define BN_FLG_CONSTTIME ...
  16. void BN_set_flags(BIGNUM *, int);
  17. BIGNUM *BN_new(void);
  18. void BN_free(BIGNUM *);
  19. void BN_clear_free(BIGNUM *);
  20. int BN_rand_range(BIGNUM *, const BIGNUM *);
  21. BN_CTX *BN_CTX_new(void);
  22. void BN_CTX_free(BN_CTX *);
  23. void BN_CTX_start(BN_CTX *);
  24. BIGNUM *BN_CTX_get(BN_CTX *);
  25. void BN_CTX_end(BN_CTX *);
  26. BN_MONT_CTX *BN_MONT_CTX_new(void);
  27. int BN_MONT_CTX_set(BN_MONT_CTX *, const BIGNUM *, BN_CTX *);
  28. void BN_MONT_CTX_free(BN_MONT_CTX *);
  29. BIGNUM *BN_dup(const BIGNUM *);
  30. int BN_set_word(BIGNUM *, BN_ULONG);
  31. const BIGNUM *BN_value_one(void);
  32. char *BN_bn2hex(const BIGNUM *);
  33. int BN_hex2bn(BIGNUM **, const char *);
  34. int BN_bn2bin(const BIGNUM *, unsigned char *);
  35. BIGNUM *BN_bin2bn(const unsigned char *, int, BIGNUM *);
  36. int BN_num_bits(const BIGNUM *);
  37. int BN_cmp(const BIGNUM *, const BIGNUM *);
  38. int BN_is_negative(const BIGNUM *);
  39. int BN_add(BIGNUM *, const BIGNUM *, const BIGNUM *);
  40. int BN_sub(BIGNUM *, const BIGNUM *, const BIGNUM *);
  41. int BN_nnmod(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
  42. int BN_mod_add(BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
  43. BN_CTX *);
  44. int BN_mod_sub(BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
  45. BN_CTX *);
  46. int BN_mod_mul(BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
  47. BN_CTX *);
  48. int BN_mod_exp(BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
  49. BN_CTX *);
  50. int BN_mod_exp_mont(BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
  51. BN_CTX *, BN_MONT_CTX *);
  52. int BN_mod_exp_mont_consttime(BIGNUM *, const BIGNUM *, const BIGNUM *,
  53. const BIGNUM *, BN_CTX *, BN_MONT_CTX *);
  54. BIGNUM *BN_mod_inverse(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
  55. int BN_num_bytes(const BIGNUM *);
  56. int BN_mod(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *);
  57. /* The following 3 prime methods are exposed for Tribler. */
  58. int BN_generate_prime_ex(BIGNUM *, int, int, const BIGNUM *,
  59. const BIGNUM *, BN_GENCB *);
  60. int BN_is_prime_ex(const BIGNUM *, int, BN_CTX *, BN_GENCB *);
  61. const int BN_prime_checks_for_size(int);
  62. """
  63. CUSTOMIZATIONS = """
  64. """