tclTomMathDecls.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  2. *----------------------------------------------------------------------
  3. *
  4. * tclTomMathDecls.h --
  5. *
  6. * This file contains the declarations for the 'libtommath'
  7. * functions that are exported by the Tcl library.
  8. *
  9. * Copyright (c) 2005 by Kevin B. Kenny. All rights reserved.
  10. *
  11. * See the file "license.terms" for information on usage and redistribution
  12. * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13. */
  14. #ifndef _TCLTOMMATHDECLS
  15. #define _TCLTOMMATHDECLS
  16. #include "tcl.h"
  17. #ifndef BN_H_
  18. #include "tclTomMath.h"
  19. #endif
  20. /*
  21. * Define the version of the Stubs table that's exported for tommath
  22. */
  23. #define TCLTOMMATH_EPOCH 0
  24. #define TCLTOMMATH_REVISION 0
  25. #define Tcl_TomMath_InitStubs(interp,version) \
  26. (TclTomMathInitializeStubs((interp),(version),\
  27. TCLTOMMATH_EPOCH,TCLTOMMATH_REVISION))
  28. /* Define custom memory allocation for libtommath */
  29. /* MODULE_SCOPE void* TclBNAlloc( size_t ); */
  30. #define TclBNAlloc(s) ((void*)ckalloc((size_t)(s)))
  31. /* MODULE_SCOPE void* TclBNCalloc( size_t, size_t ); */
  32. #define TclBNCalloc(m,s) memset(ckalloc((size_t)(m)*(size_t)(s)),0,(size_t)(m)*(size_t)(s))
  33. /* MODULE_SCOPE void* TclBNRealloc( void*, size_t ); */
  34. #define TclBNRealloc(x,s) ((void*)ckrealloc((char*)(x),(size_t)(s)))
  35. /* MODULE_SCOPE void TclBNFree( void* ); */
  36. #define TclBNFree(x) (ckfree((char*)(x)))
  37. #define MP_MALLOC(size) TclBNAlloc(size)
  38. #define MP_CALLOC(nmemb, size) TclBNCalloc(nmemb, size)
  39. #define MP_REALLOC(mem, oldsize, newsize) TclBNRealloc(mem, newsize)
  40. #define MP_FREE(mem, size) TclBNFree(mem)
  41. /* Rename the global symbols in libtommath to avoid linkage conflicts */
  42. #define bn_reverse TclBN_reverse
  43. #define mp_add TclBN_mp_add
  44. #define mp_add_d TclBN_mp_add_d
  45. #define mp_and TclBN_mp_and
  46. #define mp_clamp TclBN_mp_clamp
  47. #define mp_clear TclBN_mp_clear
  48. #define mp_clear_multi TclBN_mp_clear_multi
  49. #define mp_cmp TclBN_mp_cmp
  50. #define mp_cmp_d TclBN_mp_cmp_d
  51. #define mp_cmp_mag TclBN_mp_cmp_mag
  52. #define mp_cnt_lsb TclBN_mp_cnt_lsb
  53. #define mp_copy TclBN_mp_copy
  54. #define mp_count_bits TclBN_mp_count_bits
  55. #define mp_div TclBN_mp_div
  56. #define mp_div_2 TclBN_mp_div_2
  57. #define mp_div_2d TclBN_mp_div_2d
  58. #define mp_div_3 TclBN_mp_div_3
  59. #define mp_div_d TclBN_mp_div_d
  60. #define mp_exch TclBN_mp_exch
  61. #define mp_expt_d TclBN_mp_expt_d
  62. #define mp_expt_d_ex TclBN_mp_expt_d_ex
  63. #define mp_expt_u32 TclBN_mp_expt_d
  64. #define mp_get_mag_ull TclBN_mp_get_mag_ull
  65. #define mp_grow TclBN_mp_grow
  66. #define mp_init TclBN_mp_init
  67. #define mp_init_copy TclBN_mp_init_copy
  68. #define mp_init_multi TclBN_mp_init_multi
  69. #define mp_init_set TclBN_mp_init_set
  70. #define mp_init_set_int TclBN_mp_init_set_int
  71. #define mp_init_size TclBN_mp_init_size
  72. #define mp_lshd TclBN_mp_lshd
  73. #define mp_mod TclBN_mp_mod
  74. #define mp_mod_2d TclBN_mp_mod_2d
  75. #define mp_mul TclBN_mp_mul
  76. #define mp_mul_2 TclBN_mp_mul_2
  77. #define mp_mul_2d TclBN_mp_mul_2d
  78. #define mp_mul_d TclBN_mp_mul_d
  79. #define mp_neg TclBN_mp_neg
  80. #define mp_or TclBN_mp_or
  81. #define mp_radix_size TclBN_mp_radix_size
  82. #define mp_read_radix TclBN_mp_read_radix
  83. #define mp_rshd TclBN_mp_rshd
  84. #define mp_set TclBN_mp_set
  85. #define mp_set_int(a,b) (TclBN_mp_set_int(a,(unsigned int)(b)),MP_OKAY)
  86. #define mp_set_ll TclBN_mp_set_ll
  87. #define mp_set_long(a,b) (TclBN_mp_set_int(a,b),MP_OKAY)
  88. #define mp_set_ul(a,b) (void)TclBN_mp_set_int(a,b)
  89. #define mp_set_ull TclBN_mp_set_ull
  90. #define mp_set_u64 TclBN_mp_set_ull
  91. #define mp_shrink TclBN_mp_shrink
  92. #define mp_sqr TclBN_mp_sqr
  93. #define mp_sqrt TclBN_mp_sqrt
  94. #define mp_sub TclBN_mp_sub
  95. #define mp_sub_d TclBN_mp_sub_d
  96. #define mp_signed_rsh TclBN_mp_signed_rsh
  97. #define mp_tc_and TclBN_mp_and
  98. #define mp_tc_div_2d TclBN_mp_signed_rsh
  99. #define mp_tc_or TclBN_mp_or
  100. #define mp_tc_xor TclBN_mp_xor
  101. #define mp_to_unsigned_bin TclBN_mp_to_unsigned_bin
  102. #define mp_to_unsigned_bin_n TclBN_mp_to_unsigned_bin_n
  103. #define mp_toradix_n TclBN_mp_toradix_n
  104. #define mp_to_radix TclBN_mp_to_radix
  105. #define mp_to_ubin TclBN_mp_to_ubin
  106. #define mp_ubin_size TclBN_mp_unsigned_bin_size
  107. #define mp_unsigned_bin_size(a) ((int)TclBN_mp_unsigned_bin_size(a))
  108. #define mp_xor TclBN_mp_xor
  109. #define mp_zero TclBN_mp_zero
  110. #define s_mp_add TclBN_s_mp_add
  111. #define s_mp_balance_mul TclBN_mp_balance_mul
  112. #define s_mp_karatsuba_mul TclBN_mp_karatsuba_mul
  113. #define s_mp_karatsuba_sqr TclBN_mp_karatsuba_sqr
  114. #define s_mp_mul_digs TclBN_s_mp_mul_digs
  115. #define s_mp_mul_digs_fast TclBN_fast_s_mp_mul_digs
  116. #define s_mp_reverse TclBN_s_mp_reverse
  117. #define s_mp_sqr TclBN_s_mp_sqr
  118. #define s_mp_sqr_fast TclBN_fast_s_mp_sqr
  119. #define s_mp_sub TclBN_s_mp_sub
  120. #define s_mp_toom_mul TclBN_mp_toom_mul
  121. #define s_mp_toom_sqr TclBN_mp_toom_sqr
  122. #undef TCL_STORAGE_CLASS
  123. #ifdef BUILD_tcl
  124. # define TCL_STORAGE_CLASS DLLEXPORT
  125. #else
  126. # ifdef USE_TCL_STUBS
  127. # define TCL_STORAGE_CLASS
  128. # else
  129. # define TCL_STORAGE_CLASS DLLIMPORT
  130. # endif
  131. #endif
  132. /*
  133. * WARNING: This file is automatically generated by the tools/genStubs.tcl
  134. * script. Any modifications to the function declarations below should be made
  135. * in the generic/tclInt.decls script.
  136. */
  137. /* !BEGIN!: Do not edit below this line. */
  138. #ifdef __cplusplus
  139. extern "C" {
  140. #endif
  141. /*
  142. * Exported function declarations:
  143. */
  144. /* 0 */
  145. EXTERN int TclBN_epoch(void);
  146. /* 1 */
  147. EXTERN int TclBN_revision(void);
  148. /* 2 */
  149. EXTERN mp_err TclBN_mp_add(const mp_int *a, const mp_int *b,
  150. mp_int *c);
  151. /* 3 */
  152. EXTERN mp_err TclBN_mp_add_d(const mp_int *a, mp_digit b,
  153. mp_int *c);
  154. /* 4 */
  155. EXTERN mp_err TclBN_mp_and(const mp_int *a, const mp_int *b,
  156. mp_int *c);
  157. /* 5 */
  158. EXTERN void TclBN_mp_clamp(mp_int *a);
  159. /* 6 */
  160. EXTERN void TclBN_mp_clear(mp_int *a);
  161. /* 7 */
  162. EXTERN void TclBN_mp_clear_multi(mp_int *a, ...);
  163. /* 8 */
  164. EXTERN mp_ord TclBN_mp_cmp(const mp_int *a, const mp_int *b);
  165. /* 9 */
  166. EXTERN mp_ord TclBN_mp_cmp_d(const mp_int *a, mp_digit b);
  167. /* 10 */
  168. EXTERN mp_ord TclBN_mp_cmp_mag(const mp_int *a, const mp_int *b);
  169. /* 11 */
  170. EXTERN mp_err TclBN_mp_copy(const mp_int *a, mp_int *b);
  171. /* 12 */
  172. EXTERN int TclBN_mp_count_bits(const mp_int *a);
  173. /* 13 */
  174. EXTERN mp_err TclBN_mp_div(const mp_int *a, const mp_int *b,
  175. mp_int *q, mp_int *r);
  176. /* 14 */
  177. EXTERN mp_err TclBN_mp_div_d(const mp_int *a, mp_digit b,
  178. mp_int *q, mp_digit *r);
  179. /* 15 */
  180. EXTERN mp_err TclBN_mp_div_2(const mp_int *a, mp_int *q);
  181. /* 16 */
  182. EXTERN mp_err TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q,
  183. mp_int *r);
  184. /* 17 */
  185. EXTERN mp_err TclBN_mp_div_3(const mp_int *a, mp_int *q,
  186. mp_digit *r);
  187. /* 18 */
  188. EXTERN void TclBN_mp_exch(mp_int *a, mp_int *b);
  189. /* 19 */
  190. EXTERN mp_err TclBN_mp_expt_d(const mp_int *a, unsigned int b,
  191. mp_int *c);
  192. /* 20 */
  193. EXTERN mp_err TclBN_mp_grow(mp_int *a, int size);
  194. /* 21 */
  195. EXTERN mp_err TclBN_mp_init(mp_int *a);
  196. /* 22 */
  197. EXTERN mp_err TclBN_mp_init_copy(mp_int *a, const mp_int *b);
  198. /* 23 */
  199. EXTERN mp_err TclBN_mp_init_multi(mp_int *a, ...);
  200. /* 24 */
  201. EXTERN mp_err TclBN_mp_init_set(mp_int *a, mp_digit b);
  202. /* 25 */
  203. EXTERN mp_err TclBN_mp_init_size(mp_int *a, int size);
  204. /* 26 */
  205. EXTERN mp_err TclBN_mp_lshd(mp_int *a, int shift);
  206. /* 27 */
  207. EXTERN mp_err TclBN_mp_mod(const mp_int *a, const mp_int *b,
  208. mp_int *r);
  209. /* 28 */
  210. EXTERN mp_err TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r);
  211. /* 29 */
  212. EXTERN mp_err TclBN_mp_mul(const mp_int *a, const mp_int *b,
  213. mp_int *p);
  214. /* 30 */
  215. EXTERN mp_err TclBN_mp_mul_d(const mp_int *a, mp_digit b,
  216. mp_int *p);
  217. /* 31 */
  218. EXTERN mp_err TclBN_mp_mul_2(const mp_int *a, mp_int *p);
  219. /* 32 */
  220. EXTERN mp_err TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p);
  221. /* 33 */
  222. EXTERN mp_err TclBN_mp_neg(const mp_int *a, mp_int *b);
  223. /* 34 */
  224. EXTERN mp_err TclBN_mp_or(const mp_int *a, const mp_int *b,
  225. mp_int *c);
  226. /* 35 */
  227. EXTERN mp_err TclBN_mp_radix_size(const mp_int *a, int radix,
  228. int *size);
  229. /* 36 */
  230. EXTERN mp_err TclBN_mp_read_radix(mp_int *a, const char *str,
  231. int radix);
  232. /* 37 */
  233. EXTERN void TclBN_mp_rshd(mp_int *a, int shift);
  234. /* 38 */
  235. EXTERN mp_err TclBN_mp_shrink(mp_int *a);
  236. /* 39 */
  237. EXTERN void TclBN_mp_set(mp_int *a, mp_digit b);
  238. /* 40 */
  239. EXTERN mp_err TclBN_mp_sqr(const mp_int *a, mp_int *b);
  240. /* 41 */
  241. EXTERN mp_err TclBN_mp_sqrt(const mp_int *a, mp_int *b);
  242. /* 42 */
  243. EXTERN mp_err TclBN_mp_sub(const mp_int *a, const mp_int *b,
  244. mp_int *c);
  245. /* 43 */
  246. EXTERN mp_err TclBN_mp_sub_d(const mp_int *a, mp_digit b,
  247. mp_int *c);
  248. /* 44 */
  249. EXTERN mp_err TclBN_mp_to_unsigned_bin(const mp_int *a,
  250. unsigned char *b);
  251. /* 45 */
  252. EXTERN mp_err TclBN_mp_to_unsigned_bin_n(const mp_int *a,
  253. unsigned char *b, unsigned long *outlen);
  254. /* 46 */
  255. EXTERN mp_err TclBN_mp_toradix_n(const mp_int *a, char *str,
  256. int radix, int maxlen);
  257. /* 47 */
  258. EXTERN size_t TclBN_mp_unsigned_bin_size(const mp_int *a);
  259. /* 48 */
  260. EXTERN mp_err TclBN_mp_xor(const mp_int *a, const mp_int *b,
  261. mp_int *c);
  262. /* 49 */
  263. EXTERN void TclBN_mp_zero(mp_int *a);
  264. /* 50 */
  265. EXTERN void TclBN_reverse(unsigned char *s, int len);
  266. /* 51 */
  267. EXTERN mp_err TclBN_fast_s_mp_mul_digs(const mp_int *a,
  268. const mp_int *b, mp_int *c, int digs);
  269. /* 52 */
  270. EXTERN mp_err TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b);
  271. /* 53 */
  272. EXTERN mp_err TclBN_mp_karatsuba_mul(const mp_int *a,
  273. const mp_int *b, mp_int *c);
  274. /* 54 */
  275. EXTERN mp_err TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b);
  276. /* 55 */
  277. EXTERN mp_err TclBN_mp_toom_mul(const mp_int *a, const mp_int *b,
  278. mp_int *c);
  279. /* 56 */
  280. EXTERN mp_err TclBN_mp_toom_sqr(const mp_int *a, mp_int *b);
  281. /* 57 */
  282. EXTERN mp_err TclBN_s_mp_add(const mp_int *a, const mp_int *b,
  283. mp_int *c);
  284. /* 58 */
  285. EXTERN mp_err TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b,
  286. mp_int *c, int digs);
  287. /* 59 */
  288. EXTERN mp_err TclBN_s_mp_sqr(const mp_int *a, mp_int *b);
  289. /* 60 */
  290. EXTERN mp_err TclBN_s_mp_sub(const mp_int *a, const mp_int *b,
  291. mp_int *c);
  292. /* 61 */
  293. EXTERN mp_err TclBN_mp_init_set_int(mp_int *a, unsigned long i);
  294. /* 62 */
  295. EXTERN mp_err TclBN_mp_set_int(mp_int *a, unsigned long i);
  296. /* 63 */
  297. EXTERN int TclBN_mp_cnt_lsb(const mp_int *a);
  298. /* 64 */
  299. EXTERN int TclBNInitBignumFromLong(mp_int *bignum, long initVal);
  300. /* 65 */
  301. EXTERN int TclBNInitBignumFromWideInt(mp_int *bignum,
  302. Tcl_WideInt initVal);
  303. /* 66 */
  304. EXTERN int TclBNInitBignumFromWideUInt(mp_int *bignum,
  305. Tcl_WideUInt initVal);
  306. /* 67 */
  307. EXTERN mp_err TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b,
  308. mp_int *c, int fast);
  309. /* 68 */
  310. EXTERN void TclBN_mp_set_ull(mp_int *a, Tcl_WideUInt i);
  311. /* 69 */
  312. EXTERN Tcl_WideUInt TclBN_mp_get_mag_ull(const mp_int *a);
  313. /* 70 */
  314. EXTERN void TclBN_mp_set_ll(mp_int *a, Tcl_WideInt i);
  315. /* Slot 71 is reserved */
  316. /* Slot 72 is reserved */
  317. /* 73 */
  318. EXTERN mp_err TclBN_mp_tc_and(const mp_int *a, const mp_int *b,
  319. mp_int *c);
  320. /* 74 */
  321. EXTERN mp_err TclBN_mp_tc_or(const mp_int *a, const mp_int *b,
  322. mp_int *c);
  323. /* 75 */
  324. EXTERN mp_err TclBN_mp_tc_xor(const mp_int *a, const mp_int *b,
  325. mp_int *c);
  326. /* 76 */
  327. EXTERN mp_err TclBN_mp_signed_rsh(const mp_int *a, int b,
  328. mp_int *c);
  329. /* Slot 77 is reserved */
  330. /* 78 */
  331. EXTERN int TclBN_mp_to_ubin(const mp_int *a, unsigned char *buf,
  332. size_t maxlen, size_t *written);
  333. /* 79 */
  334. EXTERN mp_err TclBN_mp_div_ld(const mp_int *a, Tcl_WideUInt b,
  335. mp_int *q, Tcl_WideUInt *r);
  336. /* 80 */
  337. EXTERN int TclBN_mp_to_radix(const mp_int *a, char *str,
  338. size_t maxlen, size_t *written, int radix);
  339. typedef struct TclTomMathStubs {
  340. int magic;
  341. void *hooks;
  342. int (*tclBN_epoch) (void); /* 0 */
  343. int (*tclBN_revision) (void); /* 1 */
  344. mp_err (*tclBN_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 2 */
  345. mp_err (*tclBN_mp_add_d) (const mp_int *a, mp_digit b, mp_int *c); /* 3 */
  346. mp_err (*tclBN_mp_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 4 */
  347. void (*tclBN_mp_clamp) (mp_int *a); /* 5 */
  348. void (*tclBN_mp_clear) (mp_int *a); /* 6 */
  349. void (*tclBN_mp_clear_multi) (mp_int *a, ...); /* 7 */
  350. mp_ord (*tclBN_mp_cmp) (const mp_int *a, const mp_int *b); /* 8 */
  351. mp_ord (*tclBN_mp_cmp_d) (const mp_int *a, mp_digit b); /* 9 */
  352. mp_ord (*tclBN_mp_cmp_mag) (const mp_int *a, const mp_int *b); /* 10 */
  353. mp_err (*tclBN_mp_copy) (const mp_int *a, mp_int *b); /* 11 */
  354. int (*tclBN_mp_count_bits) (const mp_int *a); /* 12 */
  355. mp_err (*tclBN_mp_div) (const mp_int *a, const mp_int *b, mp_int *q, mp_int *r); /* 13 */
  356. mp_err (*tclBN_mp_div_d) (const mp_int *a, mp_digit b, mp_int *q, mp_digit *r); /* 14 */
  357. mp_err (*tclBN_mp_div_2) (const mp_int *a, mp_int *q); /* 15 */
  358. mp_err (*tclBN_mp_div_2d) (const mp_int *a, int b, mp_int *q, mp_int *r); /* 16 */
  359. mp_err (*tclBN_mp_div_3) (const mp_int *a, mp_int *q, mp_digit *r); /* 17 */
  360. void (*tclBN_mp_exch) (mp_int *a, mp_int *b); /* 18 */
  361. mp_err (*tclBN_mp_expt_d) (const mp_int *a, unsigned int b, mp_int *c); /* 19 */
  362. mp_err (*tclBN_mp_grow) (mp_int *a, int size); /* 20 */
  363. mp_err (*tclBN_mp_init) (mp_int *a); /* 21 */
  364. mp_err (*tclBN_mp_init_copy) (mp_int *a, const mp_int *b); /* 22 */
  365. mp_err (*tclBN_mp_init_multi) (mp_int *a, ...); /* 23 */
  366. mp_err (*tclBN_mp_init_set) (mp_int *a, mp_digit b); /* 24 */
  367. mp_err (*tclBN_mp_init_size) (mp_int *a, int size); /* 25 */
  368. mp_err (*tclBN_mp_lshd) (mp_int *a, int shift); /* 26 */
  369. mp_err (*tclBN_mp_mod) (const mp_int *a, const mp_int *b, mp_int *r); /* 27 */
  370. mp_err (*tclBN_mp_mod_2d) (const mp_int *a, int b, mp_int *r); /* 28 */
  371. mp_err (*tclBN_mp_mul) (const mp_int *a, const mp_int *b, mp_int *p); /* 29 */
  372. mp_err (*tclBN_mp_mul_d) (const mp_int *a, mp_digit b, mp_int *p); /* 30 */
  373. mp_err (*tclBN_mp_mul_2) (const mp_int *a, mp_int *p); /* 31 */
  374. mp_err (*tclBN_mp_mul_2d) (const mp_int *a, int d, mp_int *p); /* 32 */
  375. mp_err (*tclBN_mp_neg) (const mp_int *a, mp_int *b); /* 33 */
  376. mp_err (*tclBN_mp_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 34 */
  377. mp_err (*tclBN_mp_radix_size) (const mp_int *a, int radix, int *size); /* 35 */
  378. mp_err (*tclBN_mp_read_radix) (mp_int *a, const char *str, int radix); /* 36 */
  379. void (*tclBN_mp_rshd) (mp_int *a, int shift); /* 37 */
  380. mp_err (*tclBN_mp_shrink) (mp_int *a); /* 38 */
  381. void (*tclBN_mp_set) (mp_int *a, mp_digit b); /* 39 */
  382. mp_err (*tclBN_mp_sqr) (const mp_int *a, mp_int *b); /* 40 */
  383. mp_err (*tclBN_mp_sqrt) (const mp_int *a, mp_int *b); /* 41 */
  384. mp_err (*tclBN_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 42 */
  385. mp_err (*tclBN_mp_sub_d) (const mp_int *a, mp_digit b, mp_int *c); /* 43 */
  386. mp_err (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */
  387. mp_err (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
  388. mp_err (*tclBN_mp_toradix_n) (const mp_int *a, char *str, int radix, int maxlen); /* 46 */
  389. size_t (*tclBN_mp_unsigned_bin_size) (const mp_int *a); /* 47 */
  390. mp_err (*tclBN_mp_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 48 */
  391. void (*tclBN_mp_zero) (mp_int *a); /* 49 */
  392. void (*tclBN_reverse) (unsigned char *s, int len); /* 50 */
  393. mp_err (*tclBN_fast_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 51 */
  394. mp_err (*tclBN_fast_s_mp_sqr) (const mp_int *a, mp_int *b); /* 52 */
  395. mp_err (*tclBN_mp_karatsuba_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 53 */
  396. mp_err (*tclBN_mp_karatsuba_sqr) (const mp_int *a, mp_int *b); /* 54 */
  397. mp_err (*tclBN_mp_toom_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 55 */
  398. mp_err (*tclBN_mp_toom_sqr) (const mp_int *a, mp_int *b); /* 56 */
  399. mp_err (*tclBN_s_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 57 */
  400. mp_err (*tclBN_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 58 */
  401. mp_err (*tclBN_s_mp_sqr) (const mp_int *a, mp_int *b); /* 59 */
  402. mp_err (*tclBN_s_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 60 */
  403. mp_err (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */
  404. mp_err (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */
  405. int (*tclBN_mp_cnt_lsb) (const mp_int *a); /* 63 */
  406. int (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
  407. int (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
  408. int (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
  409. mp_err (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
  410. void (*tclBN_mp_set_ull) (mp_int *a, Tcl_WideUInt i); /* 68 */
  411. Tcl_WideUInt (*tclBN_mp_get_mag_ull) (const mp_int *a); /* 69 */
  412. void (*tclBN_mp_set_ll) (mp_int *a, Tcl_WideInt i); /* 70 */
  413. void (*reserved71)(void);
  414. void (*reserved72)(void);
  415. mp_err (*tclBN_mp_tc_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 73 */
  416. mp_err (*tclBN_mp_tc_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 74 */
  417. mp_err (*tclBN_mp_tc_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 75 */
  418. mp_err (*tclBN_mp_signed_rsh) (const mp_int *a, int b, mp_int *c); /* 76 */
  419. void (*reserved77)(void);
  420. int (*tclBN_mp_to_ubin) (const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written); /* 78 */
  421. mp_err (*tclBN_mp_div_ld) (const mp_int *a, Tcl_WideUInt b, mp_int *q, Tcl_WideUInt *r); /* 79 */
  422. int (*tclBN_mp_to_radix) (const mp_int *a, char *str, size_t maxlen, size_t *written, int radix); /* 80 */
  423. } TclTomMathStubs;
  424. extern const TclTomMathStubs *tclTomMathStubsPtr;
  425. #ifdef __cplusplus
  426. }
  427. #endif
  428. #if defined(USE_TCL_STUBS)
  429. /*
  430. * Inline function declarations:
  431. */
  432. #define TclBN_epoch \
  433. (tclTomMathStubsPtr->tclBN_epoch) /* 0 */
  434. #define TclBN_revision \
  435. (tclTomMathStubsPtr->tclBN_revision) /* 1 */
  436. #define TclBN_mp_add \
  437. (tclTomMathStubsPtr->tclBN_mp_add) /* 2 */
  438. #define TclBN_mp_add_d \
  439. (tclTomMathStubsPtr->tclBN_mp_add_d) /* 3 */
  440. #define TclBN_mp_and \
  441. (tclTomMathStubsPtr->tclBN_mp_and) /* 4 */
  442. #define TclBN_mp_clamp \
  443. (tclTomMathStubsPtr->tclBN_mp_clamp) /* 5 */
  444. #define TclBN_mp_clear \
  445. (tclTomMathStubsPtr->tclBN_mp_clear) /* 6 */
  446. #define TclBN_mp_clear_multi \
  447. (tclTomMathStubsPtr->tclBN_mp_clear_multi) /* 7 */
  448. #define TclBN_mp_cmp \
  449. (tclTomMathStubsPtr->tclBN_mp_cmp) /* 8 */
  450. #define TclBN_mp_cmp_d \
  451. (tclTomMathStubsPtr->tclBN_mp_cmp_d) /* 9 */
  452. #define TclBN_mp_cmp_mag \
  453. (tclTomMathStubsPtr->tclBN_mp_cmp_mag) /* 10 */
  454. #define TclBN_mp_copy \
  455. (tclTomMathStubsPtr->tclBN_mp_copy) /* 11 */
  456. #define TclBN_mp_count_bits \
  457. (tclTomMathStubsPtr->tclBN_mp_count_bits) /* 12 */
  458. #define TclBN_mp_div \
  459. (tclTomMathStubsPtr->tclBN_mp_div) /* 13 */
  460. #define TclBN_mp_div_d \
  461. (tclTomMathStubsPtr->tclBN_mp_div_d) /* 14 */
  462. #define TclBN_mp_div_2 \
  463. (tclTomMathStubsPtr->tclBN_mp_div_2) /* 15 */
  464. #define TclBN_mp_div_2d \
  465. (tclTomMathStubsPtr->tclBN_mp_div_2d) /* 16 */
  466. #define TclBN_mp_div_3 \
  467. (tclTomMathStubsPtr->tclBN_mp_div_3) /* 17 */
  468. #define TclBN_mp_exch \
  469. (tclTomMathStubsPtr->tclBN_mp_exch) /* 18 */
  470. #define TclBN_mp_expt_d \
  471. (tclTomMathStubsPtr->tclBN_mp_expt_d) /* 19 */
  472. #define TclBN_mp_grow \
  473. (tclTomMathStubsPtr->tclBN_mp_grow) /* 20 */
  474. #define TclBN_mp_init \
  475. (tclTomMathStubsPtr->tclBN_mp_init) /* 21 */
  476. #define TclBN_mp_init_copy \
  477. (tclTomMathStubsPtr->tclBN_mp_init_copy) /* 22 */
  478. #define TclBN_mp_init_multi \
  479. (tclTomMathStubsPtr->tclBN_mp_init_multi) /* 23 */
  480. #define TclBN_mp_init_set \
  481. (tclTomMathStubsPtr->tclBN_mp_init_set) /* 24 */
  482. #define TclBN_mp_init_size \
  483. (tclTomMathStubsPtr->tclBN_mp_init_size) /* 25 */
  484. #define TclBN_mp_lshd \
  485. (tclTomMathStubsPtr->tclBN_mp_lshd) /* 26 */
  486. #define TclBN_mp_mod \
  487. (tclTomMathStubsPtr->tclBN_mp_mod) /* 27 */
  488. #define TclBN_mp_mod_2d \
  489. (tclTomMathStubsPtr->tclBN_mp_mod_2d) /* 28 */
  490. #define TclBN_mp_mul \
  491. (tclTomMathStubsPtr->tclBN_mp_mul) /* 29 */
  492. #define TclBN_mp_mul_d \
  493. (tclTomMathStubsPtr->tclBN_mp_mul_d) /* 30 */
  494. #define TclBN_mp_mul_2 \
  495. (tclTomMathStubsPtr->tclBN_mp_mul_2) /* 31 */
  496. #define TclBN_mp_mul_2d \
  497. (tclTomMathStubsPtr->tclBN_mp_mul_2d) /* 32 */
  498. #define TclBN_mp_neg \
  499. (tclTomMathStubsPtr->tclBN_mp_neg) /* 33 */
  500. #define TclBN_mp_or \
  501. (tclTomMathStubsPtr->tclBN_mp_or) /* 34 */
  502. #define TclBN_mp_radix_size \
  503. (tclTomMathStubsPtr->tclBN_mp_radix_size) /* 35 */
  504. #define TclBN_mp_read_radix \
  505. (tclTomMathStubsPtr->tclBN_mp_read_radix) /* 36 */
  506. #define TclBN_mp_rshd \
  507. (tclTomMathStubsPtr->tclBN_mp_rshd) /* 37 */
  508. #define TclBN_mp_shrink \
  509. (tclTomMathStubsPtr->tclBN_mp_shrink) /* 38 */
  510. #define TclBN_mp_set \
  511. (tclTomMathStubsPtr->tclBN_mp_set) /* 39 */
  512. #define TclBN_mp_sqr \
  513. (tclTomMathStubsPtr->tclBN_mp_sqr) /* 40 */
  514. #define TclBN_mp_sqrt \
  515. (tclTomMathStubsPtr->tclBN_mp_sqrt) /* 41 */
  516. #define TclBN_mp_sub \
  517. (tclTomMathStubsPtr->tclBN_mp_sub) /* 42 */
  518. #define TclBN_mp_sub_d \
  519. (tclTomMathStubsPtr->tclBN_mp_sub_d) /* 43 */
  520. #define TclBN_mp_to_unsigned_bin \
  521. (tclTomMathStubsPtr->tclBN_mp_to_unsigned_bin) /* 44 */
  522. #define TclBN_mp_to_unsigned_bin_n \
  523. (tclTomMathStubsPtr->tclBN_mp_to_unsigned_bin_n) /* 45 */
  524. #define TclBN_mp_toradix_n \
  525. (tclTomMathStubsPtr->tclBN_mp_toradix_n) /* 46 */
  526. #define TclBN_mp_unsigned_bin_size \
  527. (tclTomMathStubsPtr->tclBN_mp_unsigned_bin_size) /* 47 */
  528. #define TclBN_mp_xor \
  529. (tclTomMathStubsPtr->tclBN_mp_xor) /* 48 */
  530. #define TclBN_mp_zero \
  531. (tclTomMathStubsPtr->tclBN_mp_zero) /* 49 */
  532. #define TclBN_reverse \
  533. (tclTomMathStubsPtr->tclBN_reverse) /* 50 */
  534. #define TclBN_fast_s_mp_mul_digs \
  535. (tclTomMathStubsPtr->tclBN_fast_s_mp_mul_digs) /* 51 */
  536. #define TclBN_fast_s_mp_sqr \
  537. (tclTomMathStubsPtr->tclBN_fast_s_mp_sqr) /* 52 */
  538. #define TclBN_mp_karatsuba_mul \
  539. (tclTomMathStubsPtr->tclBN_mp_karatsuba_mul) /* 53 */
  540. #define TclBN_mp_karatsuba_sqr \
  541. (tclTomMathStubsPtr->tclBN_mp_karatsuba_sqr) /* 54 */
  542. #define TclBN_mp_toom_mul \
  543. (tclTomMathStubsPtr->tclBN_mp_toom_mul) /* 55 */
  544. #define TclBN_mp_toom_sqr \
  545. (tclTomMathStubsPtr->tclBN_mp_toom_sqr) /* 56 */
  546. #define TclBN_s_mp_add \
  547. (tclTomMathStubsPtr->tclBN_s_mp_add) /* 57 */
  548. #define TclBN_s_mp_mul_digs \
  549. (tclTomMathStubsPtr->tclBN_s_mp_mul_digs) /* 58 */
  550. #define TclBN_s_mp_sqr \
  551. (tclTomMathStubsPtr->tclBN_s_mp_sqr) /* 59 */
  552. #define TclBN_s_mp_sub \
  553. (tclTomMathStubsPtr->tclBN_s_mp_sub) /* 60 */
  554. #define TclBN_mp_init_set_int \
  555. (tclTomMathStubsPtr->tclBN_mp_init_set_int) /* 61 */
  556. #define TclBN_mp_set_int \
  557. (tclTomMathStubsPtr->tclBN_mp_set_int) /* 62 */
  558. #define TclBN_mp_cnt_lsb \
  559. (tclTomMathStubsPtr->tclBN_mp_cnt_lsb) /* 63 */
  560. #define TclBNInitBignumFromLong \
  561. (tclTomMathStubsPtr->tclBNInitBignumFromLong) /* 64 */
  562. #define TclBNInitBignumFromWideInt \
  563. (tclTomMathStubsPtr->tclBNInitBignumFromWideInt) /* 65 */
  564. #define TclBNInitBignumFromWideUInt \
  565. (tclTomMathStubsPtr->tclBNInitBignumFromWideUInt) /* 66 */
  566. #define TclBN_mp_expt_d_ex \
  567. (tclTomMathStubsPtr->tclBN_mp_expt_d_ex) /* 67 */
  568. #define TclBN_mp_set_ull \
  569. (tclTomMathStubsPtr->tclBN_mp_set_ull) /* 68 */
  570. #define TclBN_mp_get_mag_ull \
  571. (tclTomMathStubsPtr->tclBN_mp_get_mag_ull) /* 69 */
  572. #define TclBN_mp_set_ll \
  573. (tclTomMathStubsPtr->tclBN_mp_set_ll) /* 70 */
  574. /* Slot 71 is reserved */
  575. /* Slot 72 is reserved */
  576. #define TclBN_mp_tc_and \
  577. (tclTomMathStubsPtr->tclBN_mp_tc_and) /* 73 */
  578. #define TclBN_mp_tc_or \
  579. (tclTomMathStubsPtr->tclBN_mp_tc_or) /* 74 */
  580. #define TclBN_mp_tc_xor \
  581. (tclTomMathStubsPtr->tclBN_mp_tc_xor) /* 75 */
  582. #define TclBN_mp_signed_rsh \
  583. (tclTomMathStubsPtr->tclBN_mp_signed_rsh) /* 76 */
  584. /* Slot 77 is reserved */
  585. #define TclBN_mp_to_ubin \
  586. (tclTomMathStubsPtr->tclBN_mp_to_ubin) /* 78 */
  587. #define TclBN_mp_div_ld \
  588. (tclTomMathStubsPtr->tclBN_mp_div_ld) /* 79 */
  589. #define TclBN_mp_to_radix \
  590. (tclTomMathStubsPtr->tclBN_mp_to_radix) /* 80 */
  591. #endif /* defined(USE_TCL_STUBS) */
  592. /* !END!: Do not edit above this line. */
  593. #undef TCL_STORAGE_CLASS
  594. #define TCL_STORAGE_CLASS DLLIMPORT
  595. #ifdef USE_TCL_STUBS
  596. #undef TclBNInitBignumFromLong
  597. #define TclBNInitBignumFromLong(a,b) \
  598. do { \
  599. (a)->dp = NULL; \
  600. (void)tclTomMathStubsPtr->tclBNInitBignumFromLong((a),(b)); \
  601. if ((a)->dp == NULL) { \
  602. Tcl_Panic("initialization failure in TclBNInitBignumFromLong"); \
  603. } \
  604. } while (0)
  605. #undef TclBNInitBignumFromWideInt
  606. #define TclBNInitBignumFromWideInt(a,b) \
  607. do { \
  608. (a)->dp = NULL; \
  609. (void)tclTomMathStubsPtr->tclBNInitBignumFromWideInt((a),(b)); \
  610. if ((a)->dp == NULL) { \
  611. Tcl_Panic("initialization failure in TclBNInitBignumFromWideInt"); \
  612. } \
  613. } while (0)
  614. #undef TclBNInitBignumFromWideUInt
  615. #define TclBNInitBignumFromWideUInt(a,b) \
  616. do { \
  617. (a)->dp = NULL; \
  618. (void)tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(b)); \
  619. if ((a)->dp == NULL) { \
  620. Tcl_Panic("initialization failure in TclBNInitBignumFromWideUInt"); \
  621. } \
  622. } while (0)
  623. #define mp_init_i32(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromLong((a),(int32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
  624. #define mp_init_l(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromLong((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
  625. #define mp_init_ll(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
  626. #define mp_init_i64(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
  627. #define mp_init_u32(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(uint32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
  628. #define mp_init_ul(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(unsigned long)(b)),(a)->dp)?MP_OKAY:MP_ERR)
  629. #define mp_init_ull(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
  630. #define mp_init_u64(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
  631. #else
  632. #define mp_init_i32(a,b) (((a)->dp=NULL,(TclBNInitBignumFromLong)((a),(int32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
  633. #define mp_init_l(a,b) (((a)->dp=NULL,(TclBNInitBignumFromLong)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
  634. #define mp_init_ll(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
  635. #define mp_init_i64(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
  636. #define mp_init_u32(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(uint32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
  637. #define mp_init_ul(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(unsigned long)(b)),(a)->dp)?MP_OKAY:MP_ERR)
  638. #define mp_init_ull(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
  639. #define mp_init_u64(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
  640. #endif /* USE_TCL_STUBS */
  641. #endif /* _TCLINTDECLS */