Mercurial > dropbear
comparison bn.tex @ 142:d29b64170cf0 libtommath-orig
import of libtommath 0.32
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 19 Dec 2004 11:33:56 +0000 |
parents | e1037a1e12e7 |
children | d8254fc979e9 |
comparison
equal
deleted
inserted
replaced
19:e1037a1e12e7 | 142:d29b64170cf0 |
---|---|
47 \def\gap{\vspace{0.5ex}} | 47 \def\gap{\vspace{0.5ex}} |
48 \makeindex | 48 \makeindex |
49 \begin{document} | 49 \begin{document} |
50 \frontmatter | 50 \frontmatter |
51 \pagestyle{empty} | 51 \pagestyle{empty} |
52 \title{LibTomMath User Manual \\ v0.30} | 52 \title{LibTomMath User Manual \\ v0.32} |
53 \author{Tom St Denis \\ [email protected]} | 53 \author{Tom St Denis \\ [email protected]} |
54 \maketitle | 54 \maketitle |
55 This text, the library and the accompanying textbook are all hereby placed in the public domain. This book has been | 55 This text, the library and the accompanying textbook are all hereby placed in the public domain. This book has been |
56 formatted for B5 [176x250] paper using the \LaTeX{} {\em book} macro package. | 56 formatted for B5 [176x250] paper using the \LaTeX{} {\em book} macro package. |
57 | 57 |
94 | 94 |
95 LibTomMath is meant to be very ``GCC friendly'' as it comes with a makefile well suited for GCC. However, the library will | 95 LibTomMath is meant to be very ``GCC friendly'' as it comes with a makefile well suited for GCC. However, the library will |
96 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 | 96 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 |
97 developer. | 97 developer. |
98 | 98 |
99 To build the library for GCC simply issue the | 99 \subsection{Static Libraries} |
100 | 100 To build as a static library for GCC issue the following |
101 \begin{alltt} | 101 \begin{alltt} |
102 make | 102 make |
103 \end{alltt} | 103 \end{alltt} |
104 | 104 |
105 command. This will build the library and archive the object files in ``libtommath.a''. Now you simply link against that | 105 command. This will build the library and archive the object files in ``libtommath.a''. Now you link against |
106 and include ``tommath.h'' within your programs. | 106 that and include ``tommath.h'' within your programs. Alternatively to build with MSVC issue the following |
107 | |
108 Alternatively to build with MSVC type | |
109 | |
110 \begin{alltt} | 107 \begin{alltt} |
111 nmake -f makefile.msvc | 108 nmake -f makefile.msvc |
112 \end{alltt} | 109 \end{alltt} |
113 | 110 |
114 This will build the library and archive the object files in ``tommath.lib''. This has been tested with MSVC version 6.00 | 111 This will build the library and archive the object files in ``tommath.lib''. This has been tested with MSVC |
115 with service pack 5. | 112 version 6.00 with service pack 5. |
116 | 113 |
117 There is limited support for making a ``DLL'' in windows via the ``makefile.cygwin\_dll'' makefile. It requires Cygwin | 114 \subsection{Shared Libraries} |
118 to work with since it requires the auto-export/import functionality. The resulting DLL and imprt library ``libtomcrypt.dll.a'' | 115 To build as a shared library for GCC issue the following |
119 can be used to link LibTomMath dynamically to any Windows program using Cygwin. | 116 \begin{alltt} |
117 make -f makefile.shared | |
118 \end{alltt} | |
119 This requires the ``libtool'' package (common on most Linux/BSD systems). It will build LibTomMath as both shared | |
120 and static then install (by default) into /usr/lib as well as install the header files in /usr/include. The shared | |
121 library (resource) will be called ``libtommath.la'' while the static library called ``libtommath.a''. Generally | |
122 you use libtool to link your application against the shared object. | |
123 | |
124 There is limited support for making a ``DLL'' in windows via the ``makefile.cygwin\_dll'' makefile. It requires | |
125 Cygwin to work with since it requires the auto-export/import functionality. The resulting DLL and import library | |
126 ``libtommath.dll.a'' can be used to link LibTomMath dynamically to any Windows program using Cygwin. | |
120 | 127 |
121 \subsection{Testing} | 128 \subsection{Testing} |
122 To build the library and the test harness type | 129 To build the library and the test harness type |
123 | 130 |
124 \begin{alltt} | 131 \begin{alltt} |
141 \end{alltt} | 148 \end{alltt} |
142 | 149 |
143 This will output a row of numbers that are increasing. Each column is a different test (such as addition, multiplication, etc) | 150 This will output a row of numbers that are increasing. Each column is a different test (such as addition, multiplication, etc) |
144 that is being performed. The numbers represent how many times the test was invoked. If an error is detected the program | 151 that is being performed. The numbers represent how many times the test was invoked. If an error is detected the program |
145 will exit with a dump of the relevent numbers it was working with. | 152 will exit with a dump of the relevent numbers it was working with. |
153 | |
154 \section{Build Configuration} | |
155 LibTomMath can configured at build time in three phases we shall call ``depends'', ``tweaks'' and ``trims''. | |
156 Each phase changes how the library is built and they are applied one after another respectively. | |
157 | |
158 To make the system more powerful you can tweak the build process. Classes are defined in the file | |
159 ``tommath\_superclass.h''. By default, the symbol ``LTM\_ALL'' shall be defined which simply | |
160 instructs the system to build all of the functions. This is how LibTomMath used to be packaged. This will give you | |
161 access to every function LibTomMath offers. | |
162 | |
163 However, there are cases where such a build is not optional. For instance, you want to perform RSA operations. You | |
164 don't need the vast majority of the library to perform these operations. Aside from LTM\_ALL there is | |
165 another pre--defined class ``SC\_RSA\_1'' which works in conjunction with the RSA from LibTomCrypt. Additional | |
166 classes can be defined base on the need of the user. | |
167 | |
168 \subsection{Build Depends} | |
169 In the file tommath\_class.h you will see a large list of C ``defines'' followed by a series of ``ifdefs'' | |
170 which further define symbols. All of the symbols (technically they're macros $\ldots$) represent a given C source | |
171 file. For instance, BN\_MP\_ADD\_C represents the file ``bn\_mp\_add.c''. When a define has been enabled the | |
172 function in the respective file will be compiled and linked into the library. Accordingly when the define | |
173 is absent the file will not be compiled and not contribute any size to the library. | |
174 | |
175 You will also note that the header tommath\_class.h is actually recursively included (it includes itself twice). | |
176 This is to help resolve as many dependencies as possible. In the last pass the symbol LTM\_LAST will be defined. | |
177 This is useful for ``trims''. | |
178 | |
179 \subsection{Build Tweaks} | |
180 A tweak is an algorithm ``alternative''. For example, to provide tradeoffs (usually between size and space). | |
181 They can be enabled at any pass of the configuration phase. | |
182 | |
183 \begin{small} | |
184 \begin{center} | |
185 \begin{tabular}{|l|l|} | |
186 \hline \textbf{Define} & \textbf{Purpose} \\ | |
187 \hline BN\_MP\_DIV\_SMALL & Enables a slower, smaller and equally \\ | |
188 & functional mp\_div() function \\ | |
189 \hline | |
190 \end{tabular} | |
191 \end{center} | |
192 \end{small} | |
193 | |
194 \subsection{Build Trims} | |
195 A trim is a manner of removing functionality from a function that is not required. For instance, to perform | |
196 RSA cryptography you only require exponentiation with odd moduli so even moduli support can be safely removed. | |
197 Build trims are meant to be defined on the last pass of the configuration which means they are to be defined | |
198 only if LTM\_LAST has been defined. | |
199 | |
200 \subsubsection{Moduli Related} | |
201 \begin{small} | |
202 \begin{center} | |
203 \begin{tabular}{|l|l|} | |
204 \hline \textbf{Restriction} & \textbf{Undefine} \\ | |
205 \hline Exponentiation with odd moduli only & BN\_S\_MP\_EXPTMOD\_C \\ | |
206 & BN\_MP\_REDUCE\_C \\ | |
207 & BN\_MP\_REDUCE\_SETUP\_C \\ | |
208 & BN\_S\_MP\_MUL\_HIGH\_DIGS\_C \\ | |
209 & BN\_FAST\_S\_MP\_MUL\_HIGH\_DIGS\_C \\ | |
210 \hline Exponentiation with random odd moduli & (The above plus the following) \\ | |
211 & BN\_MP\_REDUCE\_2K\_C \\ | |
212 & BN\_MP\_REDUCE\_2K\_SETUP\_C \\ | |
213 & BN\_MP\_REDUCE\_IS\_2K\_C \\ | |
214 & BN\_MP\_DR\_IS\_MODULUS\_C \\ | |
215 & BN\_MP\_DR\_REDUCE\_C \\ | |
216 & BN\_MP\_DR\_SETUP\_C \\ | |
217 \hline Modular inverse odd moduli only & BN\_MP\_INVMOD\_SLOW\_C \\ | |
218 \hline Modular inverse (both, smaller/slower) & BN\_FAST\_MP\_INVMOD\_C \\ | |
219 \hline | |
220 \end{tabular} | |
221 \end{center} | |
222 \end{small} | |
223 | |
224 \subsubsection{Operand Size Related} | |
225 \begin{small} | |
226 \begin{center} | |
227 \begin{tabular}{|l|l|} | |
228 \hline \textbf{Restriction} & \textbf{Undefine} \\ | |
229 \hline Moduli $\le 2560$ bits & BN\_MP\_MONTGOMERY\_REDUCE\_C \\ | |
230 & BN\_S\_MP\_MUL\_DIGS\_C \\ | |
231 & BN\_S\_MP\_MUL\_HIGH\_DIGS\_C \\ | |
232 & BN\_S\_MP\_SQR\_C \\ | |
233 \hline Polynomial Schmolynomial & BN\_MP\_KARATSUBA\_MUL\_C \\ | |
234 & BN\_MP\_KARATSUBA\_SQR\_C \\ | |
235 & BN\_MP\_TOOM\_MUL\_C \\ | |
236 & BN\_MP\_TOOM\_SQR\_C \\ | |
237 | |
238 \hline | |
239 \end{tabular} | |
240 \end{center} | |
241 \end{small} | |
242 | |
146 | 243 |
147 \section{Purpose of LibTomMath} | 244 \section{Purpose of LibTomMath} |
148 Unlike GNU MP (GMP) Library, LIP, OpenSSL or various other commercial kits (Miracl), LibTomMath was not written with | 245 Unlike GNU MP (GMP) Library, LIP, OpenSSL or various other commercial kits (Miracl), LibTomMath was not written with |
149 bleeding edge performance in mind. First and foremost LibTomMath was written to be entirely open. Not only is the | 246 bleeding edge performance in mind. First and foremost LibTomMath was written to be entirely open. Not only is the |
150 source code public domain (unlike various other GPL/etc licensed code), not only is the code freely downloadable but the | 247 source code public domain (unlike various other GPL/etc licensed code), not only is the code freely downloadable but the |