bn.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* bn.h
  2. *
  3. * Copyright (C) 2006-2017 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* bn.h for openssl */
  22. #ifndef WOLFSSL_BN_H_
  23. #define WOLFSSL_BN_H_
  24. #include <wolfssl/wolfcrypt/settings.h>
  25. #include <wolfssl/wolfcrypt/integer.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. typedef struct WOLFSSL_BIGNUM {
  30. int neg; /* openssh deference */
  31. void* internal; /* our big num */
  32. } WOLFSSL_BIGNUM;
  33. #define WOLFSSL_BN_ULONG mp_digit
  34. typedef struct WOLFSSL_BN_CTX WOLFSSL_BN_CTX;
  35. typedef struct WOLFSSL_BN_GENCB WOLFSSL_BN_GENCB;
  36. WOLFSSL_API WOLFSSL_BN_CTX* wolfSSL_BN_CTX_new(void);
  37. WOLFSSL_API void wolfSSL_BN_CTX_init(WOLFSSL_BN_CTX*);
  38. WOLFSSL_API void wolfSSL_BN_CTX_free(WOLFSSL_BN_CTX*);
  39. WOLFSSL_API WOLFSSL_BIGNUM* wolfSSL_BN_new(void);
  40. WOLFSSL_API void wolfSSL_BN_free(WOLFSSL_BIGNUM*);
  41. WOLFSSL_API void wolfSSL_BN_clear_free(WOLFSSL_BIGNUM*);
  42. WOLFSSL_API int wolfSSL_BN_sub(WOLFSSL_BIGNUM*, const WOLFSSL_BIGNUM*,
  43. const WOLFSSL_BIGNUM*);
  44. WOLFSSL_API int wolfSSL_BN_mod(WOLFSSL_BIGNUM*, const WOLFSSL_BIGNUM*,
  45. const WOLFSSL_BIGNUM*, const WOLFSSL_BN_CTX*);
  46. WOLFSSL_API int wolfSSL_BN_mod_exp(WOLFSSL_BIGNUM *r, const WOLFSSL_BIGNUM *a,
  47. const WOLFSSL_BIGNUM *p, const WOLFSSL_BIGNUM *m, WOLFSSL_BN_CTX *ctx);
  48. WOLFSSL_API int wolfSSL_BN_mod_mul(WOLFSSL_BIGNUM *r, const WOLFSSL_BIGNUM *a,
  49. const WOLFSSL_BIGNUM *b, const WOLFSSL_BIGNUM *m, WOLFSSL_BN_CTX *ctx);
  50. WOLFSSL_API const WOLFSSL_BIGNUM* wolfSSL_BN_value_one(void);
  51. WOLFSSL_API int wolfSSL_BN_num_bytes(const WOLFSSL_BIGNUM*);
  52. WOLFSSL_API int wolfSSL_BN_num_bits(const WOLFSSL_BIGNUM*);
  53. WOLFSSL_API int wolfSSL_BN_is_zero(const WOLFSSL_BIGNUM*);
  54. WOLFSSL_API int wolfSSL_BN_is_one(const WOLFSSL_BIGNUM*);
  55. WOLFSSL_API int wolfSSL_BN_is_odd(const WOLFSSL_BIGNUM*);
  56. WOLFSSL_API int wolfSSL_BN_cmp(const WOLFSSL_BIGNUM*, const WOLFSSL_BIGNUM*);
  57. WOLFSSL_API int wolfSSL_BN_bn2bin(const WOLFSSL_BIGNUM*, unsigned char*);
  58. WOLFSSL_API WOLFSSL_BIGNUM* wolfSSL_BN_bin2bn(const unsigned char*, int len,
  59. WOLFSSL_BIGNUM* ret);
  60. WOLFSSL_API int wolfSSL_mask_bits(WOLFSSL_BIGNUM*, int n);
  61. WOLFSSL_API int wolfSSL_BN_pseudo_rand(WOLFSSL_BIGNUM*, int bits, int top,
  62. int bottom);
  63. WOLFSSL_API int wolfSSL_BN_rand(WOLFSSL_BIGNUM*, int bits, int top, int bottom);
  64. WOLFSSL_API int wolfSSL_BN_is_bit_set(const WOLFSSL_BIGNUM*, int n);
  65. WOLFSSL_API int wolfSSL_BN_hex2bn(WOLFSSL_BIGNUM**, const char* str);
  66. WOLFSSL_API WOLFSSL_BIGNUM* wolfSSL_BN_dup(const WOLFSSL_BIGNUM*);
  67. WOLFSSL_API WOLFSSL_BIGNUM* wolfSSL_BN_copy(WOLFSSL_BIGNUM*,
  68. const WOLFSSL_BIGNUM*);
  69. WOLFSSL_API int wolfSSL_BN_dec2bn(WOLFSSL_BIGNUM**, const char* str);
  70. WOLFSSL_API char* wolfSSL_BN_bn2dec(const WOLFSSL_BIGNUM*);
  71. WOLFSSL_API int wolfSSL_BN_lshift(WOLFSSL_BIGNUM*, const WOLFSSL_BIGNUM*, int);
  72. WOLFSSL_API int wolfSSL_BN_add_word(WOLFSSL_BIGNUM*, WOLFSSL_BN_ULONG);
  73. WOLFSSL_API int wolfSSL_BN_set_bit(WOLFSSL_BIGNUM*, int);
  74. WOLFSSL_API int wolfSSL_BN_set_word(WOLFSSL_BIGNUM*, WOLFSSL_BN_ULONG);
  75. WOLFSSL_API unsigned long wolfSSL_BN_get_word(const WOLFSSL_BIGNUM*);
  76. WOLFSSL_API int wolfSSL_BN_add(WOLFSSL_BIGNUM*, WOLFSSL_BIGNUM*,
  77. WOLFSSL_BIGNUM*);
  78. WOLFSSL_API char *wolfSSL_BN_bn2hex(const WOLFSSL_BIGNUM*);
  79. WOLFSSL_API int wolfSSL_BN_is_prime_ex(const WOLFSSL_BIGNUM*, int,
  80. WOLFSSL_BN_CTX*, WOLFSSL_BN_GENCB*);
  81. WOLFSSL_API WOLFSSL_BN_ULONG wolfSSL_BN_mod_word(const WOLFSSL_BIGNUM*,
  82. WOLFSSL_BN_ULONG);
  83. #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
  84. WOLFSSL_API int wolfSSL_BN_print_fp(FILE*, const WOLFSSL_BIGNUM*);
  85. #endif
  86. WOLFSSL_API int wolfSSL_BN_rshift(WOLFSSL_BIGNUM*, const WOLFSSL_BIGNUM*, int);
  87. WOLFSSL_API WOLFSSL_BIGNUM *wolfSSL_BN_CTX_get(WOLFSSL_BN_CTX *ctx);
  88. WOLFSSL_API void wolfSSL_BN_CTX_start(WOLFSSL_BN_CTX *ctx);
  89. WOLFSSL_API WOLFSSL_BIGNUM *wolfSSL_BN_mod_inverse(WOLFSSL_BIGNUM*, WOLFSSL_BIGNUM*,
  90. const WOLFSSL_BIGNUM*, WOLFSSL_BN_CTX *ctx);
  91. typedef WOLFSSL_BIGNUM BIGNUM;
  92. typedef WOLFSSL_BN_CTX BN_CTX;
  93. typedef WOLFSSL_BN_GENCB BN_GENCB;
  94. #define BN_CTX_new wolfSSL_BN_CTX_new
  95. #define BN_CTX_init wolfSSL_BN_CTX_init
  96. #define BN_CTX_free wolfSSL_BN_CTX_free
  97. #define BN_new wolfSSL_BN_new
  98. #define BN_free wolfSSL_BN_free
  99. #define BN_clear_free wolfSSL_BN_clear_free
  100. #define BN_num_bytes wolfSSL_BN_num_bytes
  101. #define BN_num_bits wolfSSL_BN_num_bits
  102. #define BN_is_zero wolfSSL_BN_is_zero
  103. #define BN_is_one wolfSSL_BN_is_one
  104. #define BN_is_odd wolfSSL_BN_is_odd
  105. #define BN_cmp wolfSSL_BN_cmp
  106. #define BN_bn2bin wolfSSL_BN_bn2bin
  107. #define BN_bin2bn wolfSSL_BN_bin2bn
  108. #define BN_mod wolfSSL_BN_mod
  109. #define BN_mod_exp wolfSSL_BN_mod_exp
  110. #define BN_mod_mul wolfSSL_BN_mod_mul
  111. #define BN_sub wolfSSL_BN_sub
  112. #define BN_value_one wolfSSL_BN_value_one
  113. #define BN_mask_bits wolfSSL_mask_bits
  114. #define BN_pseudo_rand wolfSSL_BN_pseudo_rand
  115. #define BN_rand wolfSSL_BN_rand
  116. #define BN_is_bit_set wolfSSL_BN_is_bit_set
  117. #define BN_hex2bn wolfSSL_BN_hex2bn
  118. #define BN_dup wolfSSL_BN_dup
  119. #define BN_copy wolfSSL_BN_copy
  120. #define BN_get_word wolfSSL_BN_get_word
  121. #define BN_set_word wolfSSL_BN_set_word
  122. #define BN_dec2bn wolfSSL_BN_dec2bn
  123. #define BN_bn2dec wolfSSL_BN_bn2dec
  124. #define BN_bn2hex wolfSSL_BN_bn2hex
  125. #define BN_lshift wolfSSL_BN_lshift
  126. #define BN_add_word wolfSSL_BN_add_word
  127. #define BN_add wolfSSL_BN_add
  128. #define BN_set_word wolfSSL_BN_set_word
  129. #define BN_set_bit wolfSSL_BN_set_bit
  130. #define BN_is_prime_ex wolfSSL_BN_is_prime_ex
  131. #define BN_print_fp wolfSSL_BN_print_fp
  132. #define BN_rshift wolfSSL_BN_rshift
  133. #define BN_mod_word wolfSSL_BN_mod_word
  134. #define BN_CTX_get wolfSSL_BN_CTX_get
  135. #define BN_CTX_start wolfSSL_BN_CTX_start
  136. #define BN_mod_inverse wolfSSL_BN_mod_inverse
  137. #ifdef __cplusplus
  138. } /* extern "C" */
  139. #endif
  140. #endif /* WOLFSSL__H_ */