Initial code commit for Toolkit 1.1.
[silc.git] / lib / silcmath / silcmp.h
1 /*
2
3   silcmp.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2005 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silcmath/SILC MP Interface
21  *
22  * DESCRIPTION
23  *
24  * SILC MP Library Interface. This interface defines the arbitrary
25  * precision arithmetic routines for SILC. The interface is generic but
26  * is mainly intended for crypto usage. This interface is used by SILC
27  * routines that needs big numbers, such as RSA implementation,
28  * Diffie-Hellman implementation etc.
29  *
30  ***/
31
32 #ifndef SILCMP_H
33 #define SILCMP_H
34
35 #if defined(SILC_MP_GMP)
36 #include "mp_gmp.h"             /* SILC_MP_GMP */
37 #else
38 #ifdef SILC_DIST_TMA
39 #include "mp_tma.h"
40 #endif /* SILC_DIST_TMA */
41 #ifdef SILC_DIST_TFM
42 #include "mp_tfm.h"
43 #endif /* SILC_DIST_TFM */
44 #endif
45
46 /****d* silcmath/SilcMPAPI/SilcMPInt
47  *
48  * NAME
49  *
50  *    typedef SILC_MP_INT SilcMPInt;
51  *
52  * DESCRIPTION
53  *
54  *    The SILC MP Integer definition. This is the actual MP integer.
55  *    The type is defined as SILC_MP_INT as it is implementation specific
56  *    and is unknown to the application.
57  *
58  * SOURCE
59  */
60 typedef SILC_MP_INT SilcMPInt;
61 /***/
62
63 /****f* silcmath/SilcMPAPI/silc_mp_init
64  *
65  * SYNOPSIS
66  *
67  *    void silc_mp_init(SilcMPInt mp);
68  *
69  * DESCRIPTION
70  *
71  *    Initializes the SilcMPInt *that is the actual MP Integer.
72  *    This must be called before any of the silc_mp_ routines can be
73  *    used. The integer is uninitialized with the silc_mp_uninit function.
74  *
75  ***/
76 void silc_mp_init(SilcMPInt *mp);
77
78 /****f* silcmath/SilcMPAPI/silc_mp_sinit
79  *
80  * SYNOPSIS
81  *
82  *    bool silc_mp_sinit(SilcStack stack, SilcMPInt *mp);
83  *
84  * DESCRIPTION
85  *
86  *    Initializes the SilcMPInt *that is the actual MP Integer.
87  *    This must be called before any of the silc_mp_ routines can be
88  *    used. The integer is uninitialized with the silc_mp_uninit function.
89  *    This routine is equivalent to silc_mp_init but allocates the memory
90  *    from `stack'.
91  *
92  * NOTES
93  *
94  *    The `stack' is saved into the `mp' for the duration of the existence
95  *    of `mp'.  This means that `stack' must not become invalid while `mp'
96  *    is used.  It also means that any routine that may need memory allocation
97  *    to for example enlarge `mp' will allocate the memory from `stack'.
98  *
99  ***/
100 bool silc_mp_sinit(SilcStack stack, SilcMPInt *mp);
101
102 /****f* silcmath/SilcMPAPI/silc_mp_uninit
103  *
104  * SYNOPSIS
105  *
106  *    void silc_mp_uninit(SilcMPInt *mp);
107  *
108  * DESCRIPTION
109  *
110  *    Uninitializes the MP Integer.
111  *
112  ***/
113 void silc_mp_uninit(SilcMPInt *mp);
114
115 /****f* silcmath/SilcMPAPI/silc_mp_size
116  *
117  * SYNOPSIS
118  *
119  *    size_t silc_mp_size(SilcMPInt *mp);
120  *
121  * DESCRIPTION
122  *
123  *    Return the precision size of the integer `mp'.
124  *
125  ***/
126 size_t silc_mp_size(SilcMPInt *mp);
127
128 /****f* silcmath/SilcMPAPI/silc_mp_sizeinbase
129  *
130  * SYNOPSIS
131  *
132  *    size_t silc_mp_sizeinbase(SilcMPInt *mp, int base);
133  *
134  * DESCRIPTION
135  *
136  *    Return the size of the integer in base `base'.
137  *
138  * NOTES
139  *
140  *    For any other base but 2 this function usually returns only an
141  *    approximated size in the base.  It is however guaranteed that the
142  *    the returned size is always at least the size of the integer or
143  *    larger.
144  *
145  *    For base 2 this returns the exact bit-size of the integer.
146  *
147  ***/
148 size_t silc_mp_sizeinbase(SilcMPInt *mp, int base);
149
150 /****f* silcmath/SilcMPAPI/silc_mp_set
151  *
152  * SYNOPSIS
153  *
154  *    void silc_mp_set(SilcMPInt *dst, SilcMPInt *src);
155  *
156  * DESCRIPTION
157  *
158  *    Set `dst' integer from `src' integer. The `dst' must already be
159  *    initialized.
160  *
161  ***/
162 void silc_mp_set(SilcMPInt *dst, SilcMPInt *src);
163
164 /****f* silcmath/SilcMPAPI/silc_mp_set_ui
165  *
166  * SYNOPSIS
167  *
168  *    void silc_mp_set_ui(SilcMPInt *dst, SilcUInt32 ui);
169  *
170  * DESCRIPTION
171  *
172  *    Set `dst' integer from unsigned word `ui'. The `dst' must already be
173  *    initialized.
174  *
175  ***/
176 void silc_mp_set_ui(SilcMPInt *dst, SilcUInt32 ui);
177
178 /****f* silcmath/SilcMPAPI/silc_mp_set_si
179  *
180  * SYNOPSIS
181  *
182  *    void silc_mp_set_si(SilcMPInt *dst, SilcInt32 si);
183  *
184  * DESCRIPTION
185  *
186  *    Set `dst' integer from single word `si'. The `dst' must
187  *    already be initialized.
188  *
189  ***/
190 void silc_mp_set_si(SilcMPInt *dst, SilcInt32 si);
191
192 /****f* silcmath/SilcMPAPI/silc_mp_set_str
193  *
194  * SYNOPSIS
195  *
196  *    void silc_mp_set_str(SilcMPInt *dst, const char *str, int base);
197  *
198  * DESCRIPTION
199  *
200  *    Set `dst' integer from string `str' of base `base'. The `dst' must
201  *    already be initialized.
202  *
203  * NOTES
204  *
205  *    For base 2 the string must be in ASCII bit presentation, not in
206  *    binary.  Use the silc_mp_bin2mp to decode binary into integer.
207  *
208  ***/
209 void silc_mp_set_str(SilcMPInt *dst, const char *str, int base);
210
211 /****f* silcmath/SilcMPAPI/silc_mp_get_ui
212  *
213  * SYNOPSIS
214  *
215  *    SilcUInt32 silc_mp_get_ui(SilcMPInt *mp);
216  *
217  * DESCRIPTION
218  *
219  *    Returns the least significant unsigned word from `mp'.
220  *
221  ***/
222 SilcUInt32 silc_mp_get_ui(SilcMPInt *mp);
223
224 /****f* silcmath/SilcMPAPI/silc_mp_get_str
225  *
226  * SYNOPSIS
227  *
228  *    void silc_mp_get_str(char *str, SilcMPInt *mp, int base);
229  *
230  * DESCRIPTION
231  *
232  *    Converts integer `mp' into a string of base `base'. The `str'
233  *    must already have space allocated. The function returns the same
234  *    as `str' or NULL on error.
235  *
236  * NOTES
237  *
238  *    For base 2 the returned string is in ASCII bit presentation, not
239  *    in binary.  Use the silc_mp_mp2bin to encode integer into binary.
240  *
241  ***/
242 char *silc_mp_get_str(char *str, SilcMPInt *mp, int base);
243
244 /****f* silcmath/SilcMPAPI/silc_mp_add
245  *
246  * SYNOPSIS
247  *
248  *    void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
249  *
250  * DESCRIPTION
251  *
252  *    Add two integers `mp1' and `mp2' and save the result to `dst'.
253  *
254  ***/
255 void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
256
257 /****f* silcmath/SilcMPAPI/silc_mp_add_ui
258  *
259  * SYNOPSIS
260  *
261  *    void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
262  *
263  * DESCRIPTION
264  *
265  *    Add two integers `mp1' and unsigned word `ui' and save the result
266  *    to `dst'.
267  *
268  ***/
269 void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
270
271 /****f* silcmath/SilcMPAPI/silc_mp_sub
272  *
273  * SYNOPSIS
274  *
275  *    void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
276  *
277  * DESCRIPTION
278  *
279  *    Subtract two integers `mp1' and `mp2' and save the result to `dst'.
280  *
281  ***/
282 void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
283
284 /****f* silcmath/SilcMPAPI/silc_mp_sub_ui
285  *
286  * SYNOPSIS
287  *
288  *    void silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
289  *
290  * DESCRIPTION
291  *
292  *    Subtract integers `mp1' and unsigned word `ui' and save the result
293  *    to `dst'.
294  *
295  ***/
296 void silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
297
298 /****f* silcmath/SilcMPAPI/silc_mp_mul
299  *
300  * SYNOPSIS
301  *
302  *    void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
303  *
304  * DESCRIPTION
305  *
306  *    Multiply two integers `mp1' and `mp2' and save the result to `dst'.
307  *
308  ***/
309 void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
310
311 /****f* silcmath/SilcMPAPI/silc_mp_mul_ui
312  *
313  * SYNOPSIS
314  *
315  *    void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
316  *
317  * DESCRIPTION
318  *
319  *    Multiply integer `mp1' and unsigned word `ui' and save the result
320  *    to `dst'.
321  *
322  ***/
323 void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
324
325 /****f* silcmath/SilcMPAPI/silc_mp_mul_2exp
326  *
327  * SYNOPSIS
328  *
329  *    void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp);
330  *
331  * DESCRIPTION
332  *
333  *    Multiply integers `mp1' with 2 ** `exp' and save the result to
334  *    `dst'. This is equivalent to dst = mp1 * (2 ^ exp).
335  *
336  ***/
337 void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp);
338
339 /****f* silcmath/SilcMPAPI/silc_mp_sqrt
340  *
341  * SYNOPSIS
342  *
343  *    void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src);
344  *
345  * DESCRIPTION
346  *
347  *    Compute square root of floor(sqrt(src)) and save the result to `dst'.
348  *
349  ***/
350 void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src);
351
352 /****f* silcmath/SilcMPAPI/silc_mp_div
353  *
354  * SYNOPSIS
355  *
356  *    void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
357  *
358  * DESCRIPTION
359  *
360  *    Divide the `mp1' and `mp2' and save the result to the `dst'. This
361  *    is equivalent to dst = mp1 / mp2;
362  *
363  ***/
364 void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
365
366 /****f* silcmath/SilcMPAPI/silc_mp_div_ui
367  *
368  * SYNOPSIS
369  *
370  *    void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
371  *
372  * DESCRIPTION
373  *
374  *    Divide the `mp1' and unsigned word `ui' and save the result to the
375  *    `dst'. This is equivalent to dst = mp1 / ui;
376  *
377  ***/
378 void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
379
380 /****f* silcmath/SilcMPAPI/silc_mp_div_qr
381  *
382  * SYNOPSIS
383  *
384  *    void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1,
385  *                        SilcMPInt *mp2);
386  *
387  * DESCRIPTION
388  *
389  *    Divide the `mp1' and `mp2' and save the quotient to the `q' and
390  *    the remainder to the `r'.  This is equivalent to the q = mp1 / mp2,
391  *    r = mp1 mod mp2 (or mp1 = mp2 * q + r). If the `q' or `r' is NULL
392  *    then the operation is omitted.
393  *
394  ***/
395 void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1,
396                     SilcMPInt *mp2);
397
398 /****f* silcmath/SilcMPAPI/silc_mp_div_2exp
399  *
400  * SYNOPSIS
401  *
402  *    void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
403  *
404  * DESCRIPTION
405  *
406  *    Divide the `mp1' with 2 ** `exp' and save the result to `dst'.
407  *    This is equivalent to dst = mp1 / (2 ^ exp).
408  *
409  ***/
410 void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp);
411
412 /****f* silcmath/SilcMPAPI/silc_mp_div_2exp_qr
413  *
414  * SYNOPSIS
415  *
416  *    void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1,
417  *                             SilcUInt32 exp);
418  *
419  * DESCRIPTION
420  *
421  *    Divide the `mp1' with 2 ** `exp' and save the quotient to `q' and
422  *    the remainder to `r'. This is equivalent to q = mp1 / (2 ^ exp),
423  *    r = mp1 mod (2 ^ exp). If the `q' or `r' is NULL then the operation
424  *    is omitted.
425  *
426  ***/
427 void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1,
428                          SilcUInt32 exp);
429
430 /****f* silcmath/SilcMPAPI/silc_mp_mod
431  *
432  * SYNOPSIS
433  *
434  *    void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
435  *
436  * DESCRIPTION
437  *
438  *    Mathematical MOD function. Produces the remainder of `mp1' and `mp2'
439  *    and saves the result to `dst'. This is equivalent to dst = mp1 mod mp2.
440  *    The same result can also be get with silc_mp_div_qr as that function
441  *    returns the remainder as well.
442  *
443  ***/
444 void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
445
446 /****f* silcmath/SilcMPAPI/silc_mp_mod_ui
447  *
448  * SYNOPSIS
449  *
450  *    void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
451  *
452  * DESCRIPTION
453  *
454  *    Mathematical MOD function. Produces the remainder of `mp1' and
455  *    unsigned word `ui' and saves the result to `dst'. This is equivalent
456  *    to dst = mp1 mod ui.
457  *
458  ***/
459 void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
460
461 /****f* silcmath/SilcMPAPI/silc_mp_mod_2exp
462  *
463  * SYNOPSIS
464  *
465  *    void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
466  *
467  * DESCRIPTION
468  *
469  *    Computes the remainder of `mp1' with 2 ** `exp' and saves the
470  *    result to `dst'. This is equivalent to dst = mp1 mod (2 ^ exp).
471  *    The same result can also be get with silc_mp_div_2exp_qr as that
472  *    function returns the remainder as well.
473  *
474  ***/
475 void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
476
477 /****f* silcmath/SilcMPAPI/silc_mp_pow
478  *
479  * SYNOPSIS
480  *
481  *    void silc_mp_pow(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp);
482  *
483  * DESCRIPTION
484  *
485  *    Compute `mp1' ** `exp' and save the result to `dst'. This is
486  *    equivalent to dst = mp1 ^ exp.
487  *
488  ***/
489 void silc_mp_pow(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp);
490
491 /****f* silcmath/SilcMPAPI/silc_mp_pow_ui
492  *
493  * SYNOPSIS
494  *
495  *    void silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp);
496  *
497  * DESCRIPTION
498  *
499  *    Compute `mp1' ** `exp' and save the result to `dst'. This is
500  *    equivalent to dst = mp1 ^ exp.
501  *
502  ***/
503 void silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp);
504
505 /****f* silcmath/SilcMPAPI/silc_mp_pow_mod
506  *
507  * SYNOPSIS
508  *
509  *    void silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp,
510  *                         SilcMPInt *mod);
511  *
512  * DESCRIPTION
513  *
514  *    Compute (`mp1' ** `exp') mod `mod' and save the result to `dst'.
515  *    This is equivalent to dst = (mp1 ^ exp) mod mod.
516  *
517  ***/
518 void silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp,
519                      SilcMPInt *mod);
520
521 /****f* silcmath/SilcMPAPI/silc_mp_pow_mod_ui
522  *
523  * SYNOPSIS
524  *
525  *    void silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp,
526  *                            SilcMPInt *mod);
527  *
528  * DESCRIPTION
529  *
530  *    Compute (`mp1' ** `exp') mod `mod' and save the result to `dst'.
531  *    This is equivalent to dst = (mp1 ^ exp) mod mod.
532  *
533  ***/
534 void silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp,
535                         SilcMPInt *mod);
536
537 /****f* silcmath/SilcMPAPI/silc_mp_modinv
538  *
539  * SYNOPSIS
540  *
541  *    void silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n);
542  *
543  * DESCRIPTION
544  *
545  *    Find multiplicative inverse using Euclid's extended algorithm.
546  *    Computes inverse such that a * inv mod n = 1, where 0 < a < n.
547  *    Algorithm goes like this:
548  *
549  *    g(0) = n    v(0) = 0
550  *    g(1) = a    v(1) = 1
551  *
552  *    y = g(i-1) / g(i)
553  *    g(i+1) = g(i-1) - y * g(i) = g(i)-1 mod g(i)
554  *    v(i+1) = v(i-1) - y * v(i)
555  *
556  *    do until g(i) = 0, then inverse = v(i-1). If inverse is negative then n,
557  *    is added to inverse making it positive again. (Sometimes the algorithm
558  *    has a variable u defined too and it behaves just like v, except that
559  *    initalize values are swapped (i.e. u(0) = 1, u(1) = 0). However, u is
560  *    not needed by the algorithm so it does not have to be included.)
561  *
562  ***/
563 void silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n);
564
565 /****f* silcmath/SilcMPAPI/silc_mp_gcd
566  *
567  * SYNOPSIS
568  *
569  *    void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
570  *
571  * DESCRIPTION
572  *
573  *    Calculate the greatest common divisor of the integers `mp1' and `mp2'
574  *    and save the result to `dst'.
575  *
576  ***/
577 void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
578
579 /****f* silcmath/SilcMPAPI/silc_mp_gcdext
580  *
581  * SYNOPSIS
582  *
583  *    void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t,
584  *                        SilcMPInt *mp1, SilcMPInt *mp2);
585  *
586  * DESCRIPTION
587  *
588  *    Calculate the extended greatest common divisor `g', `s' and `t' such
589  *    that g = mp1 * s + mp2 * + t.
590  *
591  ***/
592 void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t, SilcMPInt *mp1,
593                     SilcMPInt *mp2);
594
595 /****f* silcmath/SilcMPAPI/silc_mp_cmp
596  *
597  * SYNOPSIS
598  *
599  *    int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2);
600  *
601  * DESCRIPTION
602  *
603  *    Compare `mp1' and `mp2'. Returns posivite, zero, or negative
604  *    if `mp1' > `mp2', `mp1' == `mp2', or `mp1' < `mp2', respectively.
605  *
606  ***/
607 int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2);
608
609 /****f* silcmath/SilcMPAPI/silc_mp_cmp_si
610  *
611  * SYNOPSIS
612  *
613  *    int silc_mp_cmp_si(SilcMPInt *mp1, SilcInt32 si);
614  *
615  * DESCRIPTION
616  *
617  *    Compare `mp1' and single word `si'. Returns posivite, zero, or negative
618  *    if `mp1' > `si', `mp1' == `si', or `mp1' < `si', respectively.
619  *
620  ***/
621 int silc_mp_cmp_si(SilcMPInt *mp1, SilcInt32 si);
622
623 /****f* silcmath/SilcMPAPI/silc_mp_cmp_ui
624  *
625  * SYNOPSIS
626  *
627  *    int silc_mp_cmp_ui(SilcMPInt *mp1, SilcUInt32 ui);
628  *
629  * DESCRIPTION
630  *
631  *    Compare `mp1' and unsigned word `ui'. Returns posivite, zero, or
632  *    negative if `mp1' > `ui', `mp1' == `ui', or `mp1' < `ui',
633  *    respectively.
634  *
635  ***/
636 int silc_mp_cmp_ui(SilcMPInt *mp1, SilcUInt32 ui);
637
638 /****f* silcmath/SilcMPAPI/silc_mp_mp2bin
639  *
640  * SYNOPSIS
641  *
642  *    unsigned char *silc_mp_mp2bin(SilcMPInt *val, SilcUInt32 len,
643  *                                  SilcUInt32 *ret_len);
644  *
645  * DESCRIPTION
646  *
647  *    Encodes MP integer into binary data. Returns allocated data that
648  *    must be free'd by the caller. If `len' is provided the destination
649  *    buffer is allocated that large. If zero then the size is approximated.
650  *
651  ***/
652 unsigned char *silc_mp_mp2bin(SilcMPInt *val, SilcUInt32 len,
653                               SilcUInt32 *ret_len);
654
655 /****f* silcmath/SilcMPAPI/silc_mp_mp2bin_noalloc
656  *
657  * SYNOPSIS
658  *
659  *    void silc_mp_mp2bin_noalloc(SilcMPInt *val, unsigned char *dst,
660  *                                SilcUInt32 dst_len);
661  *
662  * DESCRIPTION
663  *
664  *    Same as silc_mp_mp2bin but does not allocate any memory.  The
665  *    encoded data is returned into `dst' and it's length to the `ret_len'.
666  *
667  ***/
668 void silc_mp_mp2bin_noalloc(SilcMPInt *val, unsigned char *dst,
669                             SilcUInt32 dst_len);
670
671 /****f* silcmath/SilcMPAPI/silc_mp_bin2mp
672  *
673  * SYNOPSIS
674  *
675  *    void silc_mp_bin2mp(unsigned char *data, SilcUInt32 len,
676  *                        SilcMPInt *ret);
677  *
678  * DESCRIPTION
679  *
680  *    Decodes binary data into MP integer. The integer sent as argument
681  *    must be initialized.
682  *
683  ***/
684 void silc_mp_bin2mp(unsigned char *data, SilcUInt32 len, SilcMPInt *ret);
685
686 /****f* silcmath/SilcMPAPI/silc_mp_abs
687  *
688  * SYNOPSIS
689  *
690  *    void silc_mp_abs(SilcMPInt *src, SilcMPInt *dst);
691  *
692  * DESCRIPTION
693  *
694  *    Assign the absolute value of `src' to `dst'.
695  *
696  ***/
697 void silc_mp_abs(SilcMPInt *dst, SilcMPInt *src);
698
699 /****f* silcmath/SilcMPAPI/silc_mp_neg
700  *
701  * SYNOPSIS
702  *
703  *    void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src);
704  *
705  * DESCRIPTION
706  *
707  *    Negate `src' and save the result to `dst'.
708  *
709  ***/
710 void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src);
711
712 /****f* silcmath/SilcMPAPI/silc_mp_and
713  *
714  * SYNOPSIS
715  *
716  *    void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
717  *
718  * DESCRIPTION
719  *
720  *    Logical and operator. The result is saved to `dst'.
721  *
722  ***/
723 void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
724
725 /****f* silcmath/SilcMPAPI/silc_mp_or
726  *
727  * SYNOPSIS
728  *
729  *    void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
730  *
731  * DESCRIPTION
732  *
733  *    Logical inclusive OR operator. The result is saved to `dst'.
734  *
735  ***/
736 void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
737
738 /****f* silcmath/SilcMPAPI/silc_mp_xor
739  *
740  * SYNOPSIS
741  *
742  *    void silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
743  *
744  * DESCRIPTION
745  *
746  *    Logical exclusive OR operator. The result is saved to `dst'.
747  *
748  ***/
749 void silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
750
751 #endif