Permalink
Browse files

added libtommath-0.32

  • Loading branch information...
1 parent 8eaa988 commit e549ccfec53fc3e7aafd37eff590897bce340a6a Tom St Denis committed with sjaeckel Oct 29, 2004
Showing with 17,906 additions and 5,386 deletions.
  1. +78 −78 bn.ind
  2. BIN bn.pdf
  3. +110 −13 bn.tex
  4. +3 −1 bn_error.c
  5. +4 −2 bn_fast_mp_invmod.c
  6. +4 −2 bn_fast_mp_montgomery_reduce.c
  7. +33 −60 bn_fast_s_mp_mul_digs.c
  8. +50 −53 bn_fast_s_mp_mul_high_digs.c
  9. +75 −85 bn_fast_s_mp_sqr.c
  10. +3 −1 bn_mp_2expt.c
  11. +3 −1 bn_mp_abs.c
  12. +3 −1 bn_mp_add.c
  13. +3 −1 bn_mp_add_d.c
  14. +3 −1 bn_mp_addmod.c
  15. +3 −1 bn_mp_and.c
  16. +3 −1 bn_mp_clamp.c
  17. +3 −1 bn_mp_clear.c
  18. +3 −1 bn_mp_clear_multi.c
  19. +3 −1 bn_mp_cmp.c
  20. +3 −1 bn_mp_cmp_d.c
  21. +3 −1 bn_mp_cmp_mag.c
  22. +3 −1 bn_mp_cnt_lsb.c
  23. +3 −1 bn_mp_copy.c
  24. +3 −1 bn_mp_count_bits.c
  25. +78 −1 bn_mp_div.c
  26. +3 −1 bn_mp_div_2.c
  27. +3 −1 bn_mp_div_2d.c
  28. +3 −1 bn_mp_div_3.c
  29. +6 −2 bn_mp_div_d.c
  30. +3 −1 bn_mp_dr_is_modulus.c
  31. +3 −1 bn_mp_dr_reduce.c
  32. +3 −1 bn_mp_dr_setup.c
  33. +3 −1 bn_mp_exch.c
  34. +3 −1 bn_mp_expt_d.c
  35. +23 −1 bn_mp_exptmod.c
  36. +35 −4 bn_mp_exptmod_fast.c
  37. +3 −1 bn_mp_exteuclid.c
  38. +3 −1 bn_mp_fread.c
  39. +3 −1 bn_mp_fwrite.c
  40. +3 −1 bn_mp_gcd.c
  41. +3 −1 bn_mp_get_int.c
  42. +3 −1 bn_mp_grow.c
  43. +3 −1 bn_mp_init.c
  44. +3 −1 bn_mp_init_copy.c
  45. +3 −1 bn_mp_init_multi.c
  46. +3 −1 bn_mp_init_set.c
  47. +3 −1 bn_mp_init_set_int.c
  48. +13 −2 bn_mp_init_size.c
  49. +9 −144 bn_mp_invmod.c
  50. +171 −0 bn_mp_invmod_slow.c
  51. +4 −2 bn_mp_is_square.c
  52. +3 −1 bn_mp_jacobi.c
  53. +3 −1 bn_mp_karatsuba_mul.c
  54. +4 −2 bn_mp_karatsuba_sqr.c
  55. +3 −1 bn_mp_lcm.c
  56. +3 −1 bn_mp_lshd.c
  57. +3 −1 bn_mp_mod.c
  58. +3 −1 bn_mp_mod_2d.c
  59. +3 −1 bn_mp_mod_d.c
  60. +14 −11 bn_mp_montgomery_calc_normalization.c
  61. +5 −3 bn_mp_montgomery_reduce.c
  62. +4 −2 bn_mp_montgomery_setup.c
  63. +20 −6 bn_mp_mul.c
  64. +3 −1 bn_mp_mul_2.c
  65. +3 −1 bn_mp_mul_2d.c
  66. +3 −1 bn_mp_mul_d.c
  67. +3 −1 bn_mp_mulmod.c
  68. +3 −1 bn_mp_n_root.c
  69. +3 −1 bn_mp_neg.c
  70. +3 −1 bn_mp_or.c
  71. +3 −1 bn_mp_prime_fermat.c
  72. +3 −1 bn_mp_prime_is_divisible.c
  73. +4 −2 bn_mp_prime_is_prime.c
  74. +3 −1 bn_mp_prime_miller_rabin.c
  75. +3 −1 bn_mp_prime_next_prime.c
  76. +7 −10 bn_prime_sizes_tab.c → bn_mp_prime_rabin_miller_trials.c
  77. +6 −1 bn_mp_prime_random_ex.c
  78. +3 −1 bn_mp_radix_size.c
  79. +3 −1 bn_mp_radix_smap.c
  80. +3 −1 bn_mp_rand.c
  81. +3 −1 bn_mp_read_radix.c
  82. +3 −1 bn_mp_read_signed_bin.c
  83. +3 −1 bn_mp_read_unsigned_bin.c
  84. +14 −1 bn_mp_reduce.c
  85. +3 −1 bn_mp_reduce_2k.c
  86. +3 −1 bn_mp_reduce_2k_setup.c
  87. +3 −1 bn_mp_reduce_is_2k.c
  88. +4 −3 bn_mp_reduce_setup.c
  89. +3 −1 bn_mp_rshd.c
  90. +3 −1 bn_mp_set.c
  91. +3 −1 bn_mp_set_int.c
  92. +3 −1 bn_mp_shrink.c
  93. +3 −1 bn_mp_signed_bin_size.c
  94. +18 −5 bn_mp_sqr.c
  95. +3 −1 bn_mp_sqrmod.c
  96. +3 −1 bn_mp_sqrt.c
  97. +3 −1 bn_mp_sub.c
  98. +3 −1 bn_mp_sub_d.c
  99. +3 −1 bn_mp_submod.c
  100. +3 −1 bn_mp_to_signed_bin.c
  101. +3 −1 bn_mp_to_unsigned_bin.c
  102. +9 −2 bn_mp_toom_mul.c
  103. +3 −1 bn_mp_toom_sqr.c
  104. +3 −1 bn_mp_toradix.c
  105. +3 −1 bn_mp_toradix_n.c
  106. +3 −1 bn_mp_unsigned_bin_size.c
  107. +4 −2 bn_mp_xor.c
  108. +3 −1 bn_mp_zero.c
  109. +3 −1 bn_prime_tab.c
  110. +3 −1 bn_reverse.c
  111. +3 −1 bn_s_mp_add.c
  112. +3 −1 bn_s_mp_exptmod.c
  113. +3 −1 bn_s_mp_mul_digs.c
  114. +5 −1 bn_s_mp_mul_high_digs.c
  115. +3 −1 bn_s_mp_sqr.c
  116. +3 −1 bn_s_mp_sub.c
  117. +6 −8 bncore.c
  118. +1 −1 booker.pl
  119. +10,168 −0 callgraph.txt
  120. +15 −0 changes.txt
  121. +2 −0 demo/demo.c
  122. +2 −2 demo/timing.c
  123. +121 −0 dep.pl
  124. +49 −118 etc/tune.c
  125. +16 −16 logs/add.log
  126. +0 −7 logs/expt.log
  127. +0 −6 logs/expt_2k.log
  128. +0 −7 logs/expt_dr.log
  129. +143 −33 logs/mult.log
  130. +33 −33 logs/mult_kara.log
  131. +143 −33 logs/sqr.log
  132. +33 −33 logs/sqr_kara.log
  133. +16 −16 logs/sub.log
  134. +5 −4 makefile
  135. +2 −2 makefile.bcc
  136. +2 −2 makefile.cygwin_dll
  137. +2 −2 makefile.icc
  138. +2 −2 makefile.msvc
  139. +74 −0 makefile.shared
  140. +3 −2 mtest/mtest.c
  141. BIN poster.pdf
  142. +790 −402 pre_gen/mpi.c
  143. +13 −2 tommath.h
  144. BIN tommath.pdf
  145. +4,173 −4,069 tommath.tex
  146. +951 −0 tommath_class.h
  147. +72 −0 tommath_superclass.h
View
@@ -1,82 +1,82 @@
\begin{theindex}
- \item mp\_add, \hyperpage{25}
- \item mp\_add\_d, \hyperpage{48}
- \item mp\_and, \hyperpage{25}
- \item mp\_clear, \hyperpage{7}
- \item mp\_clear\_multi, \hyperpage{8}
- \item mp\_cmp, \hyperpage{20}
- \item mp\_cmp\_d, \hyperpage{21}
- \item mp\_cmp\_mag, \hyperpage{19}
- \item mp\_div, \hyperpage{26}
- \item mp\_div\_2, \hyperpage{22}
- \item mp\_div\_2d, \hyperpage{24}
- \item mp\_div\_d, \hyperpage{48}
- \item mp\_dr\_reduce, \hyperpage{36}
- \item mp\_dr\_setup, \hyperpage{36}
- \item MP\_EQ, \hyperpage{18}
- \item mp\_error\_to\_string, \hyperpage{6}
- \item mp\_expt\_d, \hyperpage{39}
- \item mp\_exptmod, \hyperpage{39}
- \item mp\_exteuclid, \hyperpage{47}
- \item mp\_gcd, \hyperpage{47}
- \item mp\_get\_int, \hyperpage{16}
- \item mp\_grow, \hyperpage{12}
- \item MP\_GT, \hyperpage{18}
- \item mp\_init, \hyperpage{7}
- \item mp\_init\_copy, \hyperpage{9}
- \item mp\_init\_multi, \hyperpage{8}
- \item mp\_init\_set, \hyperpage{17}
- \item mp\_init\_set\_int, \hyperpage{17}
- \item mp\_init\_size, \hyperpage{10}
- \item mp\_int, \hyperpage{6}
- \item mp\_invmod, \hyperpage{48}
- \item mp\_jacobi, \hyperpage{48}
- \item mp\_lcm, \hyperpage{47}
- \item mp\_lshd, \hyperpage{24}
- \item MP\_LT, \hyperpage{18}
- \item MP\_MEM, \hyperpage{5}
- \item mp\_mod, \hyperpage{31}
- \item mp\_mod\_d, \hyperpage{48}
- \item mp\_montgomery\_calc\_normalization, \hyperpage{34}
- \item mp\_montgomery\_reduce, \hyperpage{33}
- \item mp\_montgomery\_setup, \hyperpage{33}
- \item mp\_mul, \hyperpage{27}
- \item mp\_mul\_2, \hyperpage{22}
- \item mp\_mul\_2d, \hyperpage{24}
- \item mp\_mul\_d, \hyperpage{48}
- \item mp\_n\_root, \hyperpage{40}
- \item mp\_neg, \hyperpage{25}
- \item MP\_NO, \hyperpage{5}
- \item MP\_OKAY, \hyperpage{5}
- \item mp\_or, \hyperpage{25}
- \item mp\_prime\_fermat, \hyperpage{41}
- \item mp\_prime\_is\_divisible, \hyperpage{41}
- \item mp\_prime\_is\_prime, \hyperpage{42}
- \item mp\_prime\_miller\_rabin, \hyperpage{41}
- \item mp\_prime\_next\_prime, \hyperpage{42}
- \item mp\_prime\_rabin\_miller\_trials, \hyperpage{42}
- \item mp\_prime\_random, \hyperpage{43}
- \item mp\_prime\_random\_ex, \hyperpage{43}
- \item mp\_radix\_size, \hyperpage{45}
- \item mp\_read\_radix, \hyperpage{45}
- \item mp\_read\_unsigned\_bin, \hyperpage{46}
- \item mp\_reduce, \hyperpage{32}
- \item mp\_reduce\_2k, \hyperpage{37}
- \item mp\_reduce\_2k\_setup, \hyperpage{37}
- \item mp\_reduce\_setup, \hyperpage{32}
- \item mp\_rshd, \hyperpage{24}
- \item mp\_set, \hyperpage{15}
- \item mp\_set\_int, \hyperpage{16}
- \item mp\_shrink, \hyperpage{11}
- \item mp\_sqr, \hyperpage{29}
- \item mp\_sub, \hyperpage{25}
- \item mp\_sub\_d, \hyperpage{48}
- \item mp\_to\_unsigned\_bin, \hyperpage{46}
- \item mp\_toradix, \hyperpage{45}
- \item mp\_unsigned\_bin\_size, \hyperpage{46}
- \item MP\_VAL, \hyperpage{5}
- \item mp\_xor, \hyperpage{25}
- \item MP\_YES, \hyperpage{5}
+ \item mp\_add, \hyperpage{29}
+ \item mp\_add\_d, \hyperpage{52}
+ \item mp\_and, \hyperpage{29}
+ \item mp\_clear, \hyperpage{11}
+ \item mp\_clear\_multi, \hyperpage{12}
+ \item mp\_cmp, \hyperpage{24}
+ \item mp\_cmp\_d, \hyperpage{25}
+ \item mp\_cmp\_mag, \hyperpage{23}
+ \item mp\_div, \hyperpage{30}
+ \item mp\_div\_2, \hyperpage{26}
+ \item mp\_div\_2d, \hyperpage{28}
+ \item mp\_div\_d, \hyperpage{52}
+ \item mp\_dr\_reduce, \hyperpage{40}
+ \item mp\_dr\_setup, \hyperpage{40}
+ \item MP\_EQ, \hyperpage{22}
+ \item mp\_error\_to\_string, \hyperpage{10}
+ \item mp\_expt\_d, \hyperpage{43}
+ \item mp\_exptmod, \hyperpage{43}
+ \item mp\_exteuclid, \hyperpage{51}
+ \item mp\_gcd, \hyperpage{51}
+ \item mp\_get\_int, \hyperpage{20}
+ \item mp\_grow, \hyperpage{16}
+ \item MP\_GT, \hyperpage{22}
+ \item mp\_init, \hyperpage{11}
+ \item mp\_init\_copy, \hyperpage{13}
+ \item mp\_init\_multi, \hyperpage{12}
+ \item mp\_init\_set, \hyperpage{21}
+ \item mp\_init\_set\_int, \hyperpage{21}
+ \item mp\_init\_size, \hyperpage{14}
+ \item mp\_int, \hyperpage{10}
+ \item mp\_invmod, \hyperpage{52}
+ \item mp\_jacobi, \hyperpage{52}
+ \item mp\_lcm, \hyperpage{51}
+ \item mp\_lshd, \hyperpage{28}
+ \item MP\_LT, \hyperpage{22}
+ \item MP\_MEM, \hyperpage{9}
+ \item mp\_mod, \hyperpage{35}
+ \item mp\_mod\_d, \hyperpage{52}
+ \item mp\_montgomery\_calc\_normalization, \hyperpage{38}
+ \item mp\_montgomery\_reduce, \hyperpage{37}
+ \item mp\_montgomery\_setup, \hyperpage{37}
+ \item mp\_mul, \hyperpage{31}
+ \item mp\_mul\_2, \hyperpage{26}
+ \item mp\_mul\_2d, \hyperpage{28}
+ \item mp\_mul\_d, \hyperpage{52}
+ \item mp\_n\_root, \hyperpage{44}
+ \item mp\_neg, \hyperpage{29}
+ \item MP\_NO, \hyperpage{9}
+ \item MP\_OKAY, \hyperpage{9}
+ \item mp\_or, \hyperpage{29}
+ \item mp\_prime\_fermat, \hyperpage{45}
+ \item mp\_prime\_is\_divisible, \hyperpage{45}
+ \item mp\_prime\_is\_prime, \hyperpage{46}
+ \item mp\_prime\_miller\_rabin, \hyperpage{45}
+ \item mp\_prime\_next\_prime, \hyperpage{46}
+ \item mp\_prime\_rabin\_miller\_trials, \hyperpage{46}
+ \item mp\_prime\_random, \hyperpage{47}
+ \item mp\_prime\_random\_ex, \hyperpage{47}
+ \item mp\_radix\_size, \hyperpage{49}
+ \item mp\_read\_radix, \hyperpage{49}
+ \item mp\_read\_unsigned\_bin, \hyperpage{50}
+ \item mp\_reduce, \hyperpage{36}
+ \item mp\_reduce\_2k, \hyperpage{41}
+ \item mp\_reduce\_2k\_setup, \hyperpage{41}
+ \item mp\_reduce\_setup, \hyperpage{36}
+ \item mp\_rshd, \hyperpage{28}
+ \item mp\_set, \hyperpage{19}
+ \item mp\_set\_int, \hyperpage{20}
+ \item mp\_shrink, \hyperpage{15}
+ \item mp\_sqr, \hyperpage{33}
+ \item mp\_sub, \hyperpage{29}
+ \item mp\_sub\_d, \hyperpage{52}
+ \item mp\_to\_unsigned\_bin, \hyperpage{50}
+ \item mp\_toradix, \hyperpage{49}
+ \item mp\_unsigned\_bin\_size, \hyperpage{50}
+ \item MP\_VAL, \hyperpage{9}
+ \item mp\_xor, \hyperpage{29}
+ \item MP\_YES, \hyperpage{9}
\end{theindex}
View
Binary file not shown.
View
@@ -49,7 +49,7 @@
\begin{document}
\frontmatter
\pagestyle{empty}
-\title{LibTomMath User Manual \\ v0.31}
+\title{LibTomMath User Manual \\ v0.32}
\author{Tom St Denis \\ tomstdenis@iahu.ca}
\maketitle
This text, the library and the accompanying textbook are all hereby placed in the public domain. This book has been
@@ -96,27 +96,34 @@ \section{Building LibTomMath}
also build in MSVC, Borland C out of the box. For any other ISO C compiler a makefile will have to be made by the end
developer.
-To build the library for GCC simply issue the
-
+\subsection{Static Libraries}
+To build as a static library for GCC issue the following
\begin{alltt}
make
\end{alltt}
-command. This will build the library and archive the object files in ``libtommath.a''. Now you simply link against that
-and include ``tommath.h'' within your programs.
-
-Alternatively to build with MSVC type
-
+command. This will build the library and archive the object files in ``libtommath.a''. Now you link against
+that and include ``tommath.h'' within your programs. Alternatively to build with MSVC issue the following
\begin{alltt}
nmake -f makefile.msvc
\end{alltt}
-This will build the library and archive the object files in ``tommath.lib''. This has been tested with MSVC version 6.00
-with service pack 5.
+This will build the library and archive the object files in ``tommath.lib''. This has been tested with MSVC
+version 6.00 with service pack 5.
+
+\subsection{Shared Libraries}
+To build as a shared library for GCC issue the following
+\begin{alltt}
+make -f makefile.shared
+\end{alltt}
+This requires the ``libtool'' package (common on most Linux/BSD systems). It will build LibTomMath as both shared
+and static then install (by default) into /usr/lib as well as install the header files in /usr/include. The shared
+library (resource) will be called ``libtommath.la'' while the static library called ``libtommath.a''. Generally
+you use libtool to link your application against the shared object.
-There is limited support for making a ``DLL'' in windows via the ``makefile.cygwin\_dll'' makefile. It requires Cygwin
-to work with since it requires the auto-export/import functionality. The resulting DLL and imprt library ``libtomcrypt.dll.a''
-can be used to link LibTomMath dynamically to any Windows program using Cygwin.
+There is limited support for making a ``DLL'' in windows via the ``makefile.cygwin\_dll'' makefile. It requires
+Cygwin to work with since it requires the auto-export/import functionality. The resulting DLL and import library
+``libtommath.dll.a'' can be used to link LibTomMath dynamically to any Windows program using Cygwin.
\subsection{Testing}
To build the library and the test harness type
@@ -144,6 +151,96 @@ \subsection{Testing}
that is being performed. The numbers represent how many times the test was invoked. If an error is detected the program
will exit with a dump of the relevent numbers it was working with.
+\section{Build Configuration}
+LibTomMath can configured at build time in three phases we shall call ``depends'', ``tweaks'' and ``trims''.
+Each phase changes how the library is built and they are applied one after another respectively.
+
+To make the system more powerful you can tweak the build process. Classes are defined in the file
+``tommath\_superclass.h''. By default, the symbol ``LTM\_ALL'' shall be defined which simply
+instructs the system to build all of the functions. This is how LibTomMath used to be packaged. This will give you
+access to every function LibTomMath offers.
+
+However, there are cases where such a build is not optional. For instance, you want to perform RSA operations. You
+don't need the vast majority of the library to perform these operations. Aside from LTM\_ALL there is
+another pre--defined class ``SC\_RSA\_1'' which works in conjunction with the RSA from LibTomCrypt. Additional
+classes can be defined base on the need of the user.
+
+\subsection{Build Depends}
+In the file tommath\_class.h you will see a large list of C ``defines'' followed by a series of ``ifdefs''
+which further define symbols. All of the symbols (technically they're macros $\ldots$) represent a given C source
+file. For instance, BN\_MP\_ADD\_C represents the file ``bn\_mp\_add.c''. When a define has been enabled the
+function in the respective file will be compiled and linked into the library. Accordingly when the define
+is absent the file will not be compiled and not contribute any size to the library.
+
+You will also note that the header tommath\_class.h is actually recursively included (it includes itself twice).
+This is to help resolve as many dependencies as possible. In the last pass the symbol LTM\_LAST will be defined.
+This is useful for ``trims''.
+
+\subsection{Build Tweaks}
+A tweak is an algorithm ``alternative''. For example, to provide tradeoffs (usually between size and space).
+They can be enabled at any pass of the configuration phase.
+
+\begin{small}
+\begin{center}
+\begin{tabular}{|l|l|}
+\hline \textbf{Define} & \textbf{Purpose} \\
+\hline BN\_MP\_DIV\_SMALL & Enables a slower, smaller and equally \\
+ & functional mp\_div() function \\
+\hline
+\end{tabular}
+\end{center}
+\end{small}
+
+\subsection{Build Trims}
+A trim is a manner of removing functionality from a function that is not required. For instance, to perform
+RSA cryptography you only require exponentiation with odd moduli so even moduli support can be safely removed.
+Build trims are meant to be defined on the last pass of the configuration which means they are to be defined
+only if LTM\_LAST has been defined.
+
+\subsubsection{Moduli Related}
+\begin{small}
+\begin{center}
+\begin{tabular}{|l|l|}
+\hline \textbf{Restriction} & \textbf{Undefine} \\
+\hline Exponentiation with odd moduli only & BN\_S\_MP\_EXPTMOD\_C \\
+ & BN\_MP\_REDUCE\_C \\
+ & BN\_MP\_REDUCE\_SETUP\_C \\
+ & BN\_S\_MP\_MUL\_HIGH\_DIGS\_C \\
+ & BN\_FAST\_S\_MP\_MUL\_HIGH\_DIGS\_C \\
+\hline Exponentiation with random odd moduli & (The above plus the following) \\
+ & BN\_MP\_REDUCE\_2K\_C \\
+ & BN\_MP\_REDUCE\_2K\_SETUP\_C \\
+ & BN\_MP\_REDUCE\_IS\_2K\_C \\
+ & BN\_MP\_DR\_IS\_MODULUS\_C \\
+ & BN\_MP\_DR\_REDUCE\_C \\
+ & BN\_MP\_DR\_SETUP\_C \\
+\hline Modular inverse odd moduli only & BN\_MP\_INVMOD\_SLOW\_C \\
+\hline Modular inverse (both, smaller/slower) & BN\_FAST\_MP\_INVMOD\_C \\
+\hline
+\end{tabular}
+\end{center}
+\end{small}
+
+\subsubsection{Operand Size Related}
+\begin{small}
+\begin{center}
+\begin{tabular}{|l|l|}
+\hline \textbf{Restriction} & \textbf{Undefine} \\
+\hline Moduli $\le 2560$ bits & BN\_MP\_MONTGOMERY\_REDUCE\_C \\
+ & BN\_S\_MP\_MUL\_DIGS\_C \\
+ & BN\_S\_MP\_MUL\_HIGH\_DIGS\_C \\
+ & BN\_S\_MP\_SQR\_C \\
+\hline Polynomial Schmolynomial & BN\_MP\_KARATSUBA\_MUL\_C \\
+ & BN\_MP\_KARATSUBA\_SQR\_C \\
+ & BN\_MP\_TOOM\_MUL\_C \\
+ & BN\_MP\_TOOM\_SQR\_C \\
+
+\hline
+\end{tabular}
+\end{center}
+\end{small}
+
+
\section{Purpose of LibTomMath}
Unlike GNU MP (GMP) Library, LIP, OpenSSL or various other commercial kits (Miracl), LibTomMath was not written with
bleeding edge performance in mind. First and foremost LibTomMath was written to be entirely open. Not only is the
View
@@ -1,3 +1,5 @@
+#include <tommath.h>
+#ifdef BN_ERROR_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
* LibTomMath is a library that provides multiple-precision
@@ -12,7 +14,6 @@
*
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
*/
-#include <tommath.h>
static const struct {
int code;
@@ -39,3 +40,4 @@ char *mp_error_to_string(int code)
return "Invalid error code";
}
+#endif
View
@@ -1,3 +1,5 @@
+#include <tommath.h>
+#ifdef BN_FAST_MP_INVMOD_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
* LibTomMath is a library that provides multiple-precision
@@ -12,12 +14,11 @@
*
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
*/
-#include <tommath.h>
/* computes the modular inverse via binary extended euclidean algorithm,
* that is c = 1/a mod b
*
- * Based on mp_invmod except this is optimized for the case where b is
+ * Based on slow invmod except this is optimized for the case where b is
* odd as per HAC Note 14.64 on pp. 610
*/
int
@@ -141,3 +142,4 @@ fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
__ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
return res;
}
+#endif
@@ -1,3 +1,5 @@
+#include <tommath.h>
+#ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
* LibTomMath is a library that provides multiple-precision
@@ -12,11 +14,10 @@
*
* Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
*/
-#include <tommath.h>
/* computes xR**-1 == x (mod N) via Montgomery Reduction
*
- * This is an optimized implementation of mp_montgomery_reduce
+ * This is an optimized implementation of montgomery_reduce
* which uses the comba method to quickly calculate the columns of the
* reduction.
*
@@ -165,3 +166,4 @@ fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
}
return MP_OKAY;
}
+#endif
Oops, something went wrong.

0 comments on commit e549ccf

Please sign in to comment.