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