Merged silc_1_0_branch to trunk.
[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_uninit
79  *
80  * SYNOPSIS
81  *
82  *    void silc_mp_uninit(SilcMPInt *mp);
83  *
84  * DESCRIPTION
85  *
86  *    Uninitializes the MP Integer.
87  *
88  ***/
89 void silc_mp_uninit(SilcMPInt *mp);
90
91 /****f* silcmath/SilcMPAPI/silc_mp_size
92  *
93  * SYNOPSIS
94  *
95  *    size_t silc_mp_size(SilcMPInt *mp);
96  *
97  * DESCRIPTION
98  *
99  *    Return the precision size of the integer `mp'.
100  *
101  ***/
102 size_t silc_mp_size(SilcMPInt *mp);
103
104 /****f* silcmath/SilcMPAPI/silc_mp_sizeinbase
105  *
106  * SYNOPSIS
107  *
108  *    size_t silc_mp_sizeinbase(SilcMPInt *mp, int base);
109  *
110  * DESCRIPTION
111  *
112  *    Return the size of the integer in base `base'.
113  *
114  * NOTES
115  *
116  *    For any other base but 2 this function usually returns only an
117  *    approximated size in the base.  It is however guaranteed that the
118  *    the returned size is always at least the size of the integer or
119  *    larger.
120  *
121  *    For base 2 this returns the exact bit-size of the integer.
122  *
123  ***/
124 size_t silc_mp_sizeinbase(SilcMPInt *mp, int base);
125
126 /****f* silcmath/SilcMPAPI/silc_mp_set
127  *
128  * SYNOPSIS
129  *
130  *    void silc_mp_set(SilcMPInt *dst, SilcMPInt *src);
131  *
132  * DESCRIPTION
133  *
134  *    Set `dst' integer from `src' integer. The `dst' must already be
135  *    initialized.
136  *
137  ***/
138 void silc_mp_set(SilcMPInt *dst, SilcMPInt *src);
139
140 /****f* silcmath/SilcMPAPI/silc_mp_set_ui
141  *
142  * SYNOPSIS
143  *
144  *    void silc_mp_set_ui(SilcMPInt *dst, SilcUInt32 ui);
145  *
146  * DESCRIPTION
147  *
148  *    Set `dst' integer from unsigned word `ui'. The `dst' must already be
149  *    initialized.
150  *
151  ***/
152 void silc_mp_set_ui(SilcMPInt *dst, SilcUInt32 ui);
153
154 /****f* silcmath/SilcMPAPI/silc_mp_set_si
155  *
156  * SYNOPSIS
157  *
158  *    void silc_mp_set_si(SilcMPInt *dst, SilcInt32 si);
159  *
160  * DESCRIPTION
161  *
162  *    Set `dst' integer from single word `si'. The `dst' must
163  *    already be initialized.
164  *
165  ***/
166 void silc_mp_set_si(SilcMPInt *dst, SilcInt32 si);
167
168 /****f* silcmath/SilcMPAPI/silc_mp_set_str
169  *
170  * SYNOPSIS
171  *
172  *    void silc_mp_set_str(SilcMPInt *dst, const char *str, int base);
173  *
174  * DESCRIPTION
175  *
176  *    Set `dst' integer from string `str' of base `base'. The `dst' must
177  *    already be initialized.
178  *
179  * NOTES
180  *
181  *    For base 2 the string must be in ASCII bit presentation, not in
182  *    binary.  Use the silc_mp_bin2mp to decode binary into integer.
183  *
184  ***/
185 void silc_mp_set_str(SilcMPInt *dst, const char *str, int base);
186
187 /****f* silcmath/SilcMPAPI/silc_mp_get_ui
188  *
189  * SYNOPSIS
190  *
191  *    SilcUInt32 silc_mp_get_ui(SilcMPInt *mp);
192  *
193  * DESCRIPTION
194  *
195  *    Returns the least significant unsigned word from `mp'.
196  *
197  ***/
198 SilcUInt32 silc_mp_get_ui(SilcMPInt *mp);
199
200 /****f* silcmath/SilcMPAPI/silc_mp_get_str
201  *
202  * SYNOPSIS
203  *
204  *    void silc_mp_get_str(char *str, SilcMPInt *mp, int base);
205  *
206  * DESCRIPTION
207  *
208  *    Converts integer `mp' into a string of base `base'. The `str'
209  *    must already have space allocated. The function returns the same
210  *    as `str' or NULL on error.
211  *
212  * NOTES
213  *
214  *    For base 2 the returned string is in ASCII bit presentation, not
215  *    in binary.  Use the silc_mp_mp2bin to encode integer into binary.
216  *
217  ***/
218 char *silc_mp_get_str(char *str, SilcMPInt *mp, int base);
219
220 /****f* silcmath/SilcMPAPI/silc_mp_add
221  *
222  * SYNOPSIS
223  *
224  *    void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
225  *
226  * DESCRIPTION
227  *
228  *    Add two integers `mp1' and `mp2' and save the result to `dst'.
229  *
230  ***/
231 void silc_mp_add(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
232
233 /****f* silcmath/SilcMPAPI/silc_mp_add_ui
234  *
235  * SYNOPSIS
236  *
237  *    void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
238  *
239  * DESCRIPTION
240  *
241  *    Add two integers `mp1' and unsigned word `ui' and save the result
242  *    to `dst'.
243  *
244  ***/
245 void silc_mp_add_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
246
247 /****f* silcmath/SilcMPAPI/silc_mp_sub
248  *
249  * SYNOPSIS
250  *
251  *    void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
252  *
253  * DESCRIPTION
254  *
255  *    Subtract two integers `mp1' and `mp2' and save the result to `dst'.
256  *
257  ***/
258 void silc_mp_sub(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
259
260 /****f* silcmath/SilcMPAPI/silc_mp_sub_ui
261  *
262  * SYNOPSIS
263  *
264  *    void silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
265  *
266  * DESCRIPTION
267  *
268  *    Subtract integers `mp1' and unsigned word `ui' and save the result
269  *    to `dst'.
270  *
271  ***/
272 void silc_mp_sub_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
273
274 /****f* silcmath/SilcMPAPI/silc_mp_mul
275  *
276  * SYNOPSIS
277  *
278  *    void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
279  *
280  * DESCRIPTION
281  *
282  *    Multiply two integers `mp1' and `mp2' and save the result to `dst'.
283  *
284  ***/
285 void silc_mp_mul(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
286
287 /****f* silcmath/SilcMPAPI/silc_mp_mul_ui
288  *
289  * SYNOPSIS
290  *
291  *    void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
292  *
293  * DESCRIPTION
294  *
295  *    Multiply integer `mp1' and unsigned word `ui' and save the result
296  *    to `dst'.
297  *
298  ***/
299 void silc_mp_mul_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
300
301 /****f* silcmath/SilcMPAPI/silc_mp_mul_2exp
302  *
303  * SYNOPSIS
304  *
305  *    void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp);
306  *
307  * DESCRIPTION
308  *
309  *    Multiply integers `mp1' with 2 ** `exp' and save the result to
310  *    `dst'. This is equivalent to dst = mp1 * (2 ^ exp).
311  *
312  ***/
313 void silc_mp_mul_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp);
314
315 /****f* silcmath/SilcMPAPI/silc_mp_sqrt
316  *
317  * SYNOPSIS
318  *
319  *    void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src);
320  *
321  * DESCRIPTION
322  *
323  *    Compute square root of floor(sqrt(src)) and save the result to `dst'.
324  *
325  ***/
326 void silc_mp_sqrt(SilcMPInt *dst, SilcMPInt *src);
327
328 /****f* silcmath/SilcMPAPI/silc_mp_div
329  *
330  * SYNOPSIS
331  *
332  *    void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
333  *
334  * DESCRIPTION
335  *
336  *    Divide the `mp1' and `mp2' and save the result to the `dst'. This
337  *    is equivalent to dst = mp1 / mp2;
338  *
339  ***/
340 void silc_mp_div(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
341
342 /****f* silcmath/SilcMPAPI/silc_mp_div_ui
343  *
344  * SYNOPSIS
345  *
346  *    void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
347  *
348  * DESCRIPTION
349  *
350  *    Divide the `mp1' and unsigned word `ui' and save the result to the
351  *    `dst'. This is equivalent to dst = mp1 / ui;
352  *
353  ***/
354 void silc_mp_div_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
355
356 /****f* silcmath/SilcMPAPI/silc_mp_div_qr
357  *
358  * SYNOPSIS
359  *
360  *    void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1,
361  *                        SilcMPInt *mp2);
362  *
363  * DESCRIPTION
364  *
365  *    Divide the `mp1' and `mp2' and save the quotient to the `q' and
366  *    the remainder to the `r'.  This is equivalent to the q = mp1 / mp2,
367  *    r = mp1 mod mp2 (or mp1 = mp2 * q + r). If the `q' or `r' is NULL
368  *    then the operation is omitted.
369  *
370  ***/
371 void silc_mp_div_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1,
372                     SilcMPInt *mp2);
373
374 /****f* silcmath/SilcMPAPI/silc_mp_div_2exp
375  *
376  * SYNOPSIS
377  *
378  *    void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
379  *
380  * DESCRIPTION
381  *
382  *    Divide the `mp1' with 2 ** `exp' and save the result to `dst'.
383  *    This is equivalent to dst = mp1 / (2 ^ exp).
384  *
385  ***/
386 void silc_mp_div_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp);
387
388 /****f* silcmath/SilcMPAPI/silc_mp_div_2exp_qr
389  *
390  * SYNOPSIS
391  *
392  *    void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1,
393  *                             SilcUInt32 exp);
394  *
395  * DESCRIPTION
396  *
397  *    Divide the `mp1' with 2 ** `exp' and save the quotient to `q' and
398  *    the remainder to `r'. This is equivalent to q = mp1 / (2 ^ exp),
399  *    r = mp1 mod (2 ^ exp). If the `q' or `r' is NULL then the operation
400  *    is omitted.
401  *
402  ***/
403 void silc_mp_div_2exp_qr(SilcMPInt *q, SilcMPInt *r, SilcMPInt *mp1,
404                          SilcUInt32 exp);
405
406 /****f* silcmath/SilcMPAPI/silc_mp_mod
407  *
408  * SYNOPSIS
409  *
410  *    void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
411  *
412  * DESCRIPTION
413  *
414  *    Mathematical MOD function. Produces the remainder of `mp1' and `mp2'
415  *    and saves the result to `dst'. This is equivalent to dst = mp1 mod mp2.
416  *    The same result can also be get with silc_mp_div_qr as that function
417  *    returns the remainder as well.
418  *
419  ***/
420 void silc_mp_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
421
422 /****f* silcmath/SilcMPAPI/silc_mp_mod_ui
423  *
424  * SYNOPSIS
425  *
426  *    void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
427  *
428  * DESCRIPTION
429  *
430  *    Mathematical MOD function. Produces the remainder of `mp1' and
431  *    unsigned word `ui' and saves the result to `dst'. This is equivalent
432  *    to dst = mp1 mod ui.
433  *
434  ***/
435 void silc_mp_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
436
437 /****f* silcmath/SilcMPAPI/silc_mp_mod_2exp
438  *
439  * SYNOPSIS
440  *
441  *    void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
442  *
443  * DESCRIPTION
444  *
445  *    Computes the remainder of `mp1' with 2 ** `exp' and saves the
446  *    result to `dst'. This is equivalent to dst = mp1 mod (2 ^ exp).
447  *    The same result can also be get with silc_mp_div_2exp_qr as that
448  *    function returns the remainder as well.
449  *
450  ***/
451 void silc_mp_mod_2exp(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 ui);
452
453 /****f* silcmath/SilcMPAPI/silc_mp_pow
454  *
455  * SYNOPSIS
456  *
457  *    void silc_mp_pow(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp);
458  *
459  * DESCRIPTION
460  *
461  *    Compute `mp1' ** `exp' and save the result to `dst'. This is
462  *    equivalent to dst = mp1 ^ exp.
463  *
464  ***/
465 void silc_mp_pow(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp);
466
467 /****f* silcmath/SilcMPAPI/silc_mp_pow_ui
468  *
469  * SYNOPSIS
470  *
471  *    void silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp);
472  *
473  * DESCRIPTION
474  *
475  *    Compute `mp1' ** `exp' and save the result to `dst'. This is
476  *    equivalent to dst = mp1 ^ exp.
477  *
478  ***/
479 void silc_mp_pow_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp);
480
481 /****f* silcmath/SilcMPAPI/silc_mp_pow_mod
482  *
483  * SYNOPSIS
484  *
485  *    void silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp,
486  *                         SilcMPInt *mod);
487  *
488  * DESCRIPTION
489  *
490  *    Compute (`mp1' ** `exp') mod `mod' and save the result to `dst'.
491  *    This is equivalent to dst = (mp1 ^ exp) mod mod.
492  *
493  ***/
494 void silc_mp_pow_mod(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *exp,
495                      SilcMPInt *mod);
496
497 /****f* silcmath/SilcMPAPI/silc_mp_pow_mod_ui
498  *
499  * SYNOPSIS
500  *
501  *    void silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp,
502  *                            SilcMPInt *mod);
503  *
504  * DESCRIPTION
505  *
506  *    Compute (`mp1' ** `exp') mod `mod' and save the result to `dst'.
507  *    This is equivalent to dst = (mp1 ^ exp) mod mod.
508  *
509  ***/
510 void silc_mp_pow_mod_ui(SilcMPInt *dst, SilcMPInt *mp1, SilcUInt32 exp,
511                         SilcMPInt *mod);
512
513 /****f* silcmath/SilcMPAPI/silc_mp_modinv
514  *
515  * SYNOPSIS
516  *
517  *    void silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n);
518  *
519  * DESCRIPTION
520  *
521  *    Find multiplicative inverse using Euclid's extended algorithm.
522  *    Computes inverse such that a * inv mod n = 1, where 0 < a < n.
523  *    Algorithm goes like this:
524  *
525  *    g(0) = n    v(0) = 0
526  *    g(1) = a    v(1) = 1
527  *
528  *    y = g(i-1) / g(i)
529  *    g(i+1) = g(i-1) - y * g(i) = g(i)-1 mod g(i)
530  *    v(i+1) = v(i-1) - y * v(i)
531  *
532  *    do until g(i) = 0, then inverse = v(i-1). If inverse is negative then n,
533  *    is added to inverse making it positive again. (Sometimes the algorithm
534  *    has a variable u defined too and it behaves just like v, except that
535  *    initalize values are swapped (i.e. u(0) = 1, u(1) = 0). However, u is
536  *    not needed by the algorithm so it does not have to be included.)
537  *
538  ***/
539 void silc_mp_modinv(SilcMPInt *inv, SilcMPInt *a, SilcMPInt *n);
540
541 /****f* silcmath/SilcMPAPI/silc_mp_gcd
542  *
543  * SYNOPSIS
544  *
545  *    void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
546  *
547  * DESCRIPTION
548  *
549  *    Calculate the greatest common divisor of the integers `mp1' and `mp2'
550  *    and save the result to `dst'.
551  *
552  ***/
553 void silc_mp_gcd(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
554
555 /****f* silcmath/SilcMPAPI/silc_mp_gcdext
556  *
557  * SYNOPSIS
558  *
559  *    void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t,
560  *                        SilcMPInt *mp1, SilcMPInt *mp2);
561  *
562  * DESCRIPTION
563  *
564  *    Calculate the extended greatest common divisor `g', `s' and `t' such
565  *    that g = mp1 * s + mp2 * + t.
566  *
567  ***/
568 void silc_mp_gcdext(SilcMPInt *g, SilcMPInt *s, SilcMPInt *t, SilcMPInt *mp1,
569                     SilcMPInt *mp2);
570
571 /****f* silcmath/SilcMPAPI/silc_mp_cmp
572  *
573  * SYNOPSIS
574  *
575  *    int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2);
576  *
577  * DESCRIPTION
578  *
579  *    Compare `mp1' and `mp2'. Returns posivite, zero, or negative
580  *    if `mp1' > `mp2', `mp1' == `mp2', or `mp1' < `mp2', respectively.
581  *
582  ***/
583 int silc_mp_cmp(SilcMPInt *mp1, SilcMPInt *mp2);
584
585 /****f* silcmath/SilcMPAPI/silc_mp_cmp_si
586  *
587  * SYNOPSIS
588  *
589  *    int silc_mp_cmp_si(SilcMPInt *mp1, SilcInt32 si);
590  *
591  * DESCRIPTION
592  *
593  *    Compare `mp1' and single word `si'. Returns posivite, zero, or negative
594  *    if `mp1' > `si', `mp1' == `si', or `mp1' < `si', respectively.
595  *
596  ***/
597 int silc_mp_cmp_si(SilcMPInt *mp1, SilcInt32 si);
598
599 /****f* silcmath/SilcMPAPI/silc_mp_cmp_ui
600  *
601  * SYNOPSIS
602  *
603  *    int silc_mp_cmp_ui(SilcMPInt *mp1, SilcUInt32 ui);
604  *
605  * DESCRIPTION
606  *
607  *    Compare `mp1' and unsigned word `ui'. Returns posivite, zero, or
608  *    negative if `mp1' > `ui', `mp1' == `ui', or `mp1' < `ui',
609  *    respectively.
610  *
611  ***/
612 int silc_mp_cmp_ui(SilcMPInt *mp1, SilcUInt32 ui);
613
614 /****f* silcmath/SilcMPAPI/silc_mp_mp2bin
615  *
616  * SYNOPSIS
617  *
618  *    unsigned char *silc_mp_mp2bin(SilcMPInt *val, SilcUInt32 len,
619  *                                  SilcUInt32 *ret_len);
620  *
621  * DESCRIPTION
622  *
623  *    Encodes MP integer into binary data. Returns allocated data that
624  *    must be free'd by the caller. If `len' is provided the destination
625  *    buffer is allocated that large. If zero then the size is approximated.
626  *
627  ***/
628 unsigned char *silc_mp_mp2bin(SilcMPInt *val, SilcUInt32 len,
629                               SilcUInt32 *ret_len);
630
631 /****f* silcmath/SilcMPAPI/silc_mp_mp2bin_noalloc
632  *
633  * SYNOPSIS
634  *
635  *    void silc_mp_mp2bin_noalloc(SilcMPInt *val, unsigned char *dst,
636  *                                SilcUInt32 dst_len);
637  *
638  * DESCRIPTION
639  *
640  *    Same as silc_mp_mp2bin but does not allocate any memory.  The
641  *    encoded data is returned into `dst' and it's length to the `ret_len'.
642  *
643  ***/
644 void silc_mp_mp2bin_noalloc(SilcMPInt *val, unsigned char *dst,
645                             SilcUInt32 dst_len);
646
647 /****f* silcmath/SilcMPAPI/silc_mp_bin2mp
648  *
649  * SYNOPSIS
650  *
651  *    void silc_mp_bin2mp(unsigned char *data, SilcUInt32 len,
652  *                        SilcMPInt *ret);
653  *
654  * DESCRIPTION
655  *
656  *    Decodes binary data into MP integer. The integer sent as argument
657  *    must be initialized.
658  *
659  ***/
660 void silc_mp_bin2mp(unsigned char *data, SilcUInt32 len, SilcMPInt *ret);
661
662 /****f* silcmath/SilcMPAPI/silc_mp_abs
663  *
664  * SYNOPSIS
665  *
666  *    void silc_mp_abs(SilcMPInt *src, SilcMPInt *dst);
667  *
668  * DESCRIPTION
669  *
670  *    Assign the absolute value of `src' to `dst'.
671  *
672  ***/
673 void silc_mp_abs(SilcMPInt *dst, SilcMPInt *src);
674
675 /****f* silcmath/SilcMPAPI/silc_mp_neg
676  *
677  * SYNOPSIS
678  *
679  *    void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src);
680  *
681  * DESCRIPTION
682  *
683  *    Negate `src' and save the result to `dst'.
684  *
685  ***/
686 void silc_mp_neg(SilcMPInt *dst, SilcMPInt *src);
687
688 /****f* silcmath/SilcMPAPI/silc_mp_and
689  *
690  * SYNOPSIS
691  *
692  *    void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
693  *
694  * DESCRIPTION
695  *
696  *    Logical and operator. The result is saved to `dst'.
697  *
698  ***/
699 void silc_mp_and(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
700
701 /****f* silcmath/SilcMPAPI/silc_mp_or
702  *
703  * SYNOPSIS
704  *
705  *    void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
706  *
707  * DESCRIPTION
708  *
709  *    Logical inclusive OR operator. The result is saved to `dst'.
710  *
711  ***/
712 void silc_mp_or(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
713
714 /****f* silcmath/SilcMPAPI/silc_mp_xor
715  *
716  * SYNOPSIS
717  *
718  *    void silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
719  *
720  * DESCRIPTION
721  *
722  *    Logical exclusive OR operator. The result is saved to `dst'.
723  *
724  ***/
725 void silc_mp_xor(SilcMPInt *dst, SilcMPInt *mp1, SilcMPInt *mp2);
726
727 #endif