2c971852581a0e496921c44fc9dc28efa7f25040
[strongswan.git] / src / pluto / mp_defs.h
1 /* some multiprecision utilities
2 * Copyright (C) 1997 Angelos D. Keromytis.
3 * Copyright (C) 1998-2001 D. Hugh Redelmeier.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #ifndef _MP_DEFS_H
17 #define _MP_DEFS_H
18
19 #include <gmp.h>
20
21 #include <utils.h>
22
23 extern void n_to_mpz(MP_INT *mp, const u_char *nbytes, size_t nlen);
24 extern chunk_t mpz_to_n(const MP_INT *mp, size_t bytes);
25 extern chunk_t asn1_integer_from_mpz(const mpz_t value);
26
27 /* var := mod(base ** exp, mod), ensuring var is mpz_inited */
28 #define mpz_init_powm(flag, var, base, exp, mod) { \
29 if (!(flag)) \
30 mpz_init(&(var)); \
31 (flag) = TRUE; \
32 mpz_powm(&(var), &(base), &(exp), (mod)); \
33 }
34
35 #endif /* _MP_DEFS_H */