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