ignore list
[strongswan.git] / Source / charon / utils / gmp_helper.h
1 /**
2 * @file gmp_helper.h
3 *
4 * @brief Class with helper functions for gmp operations
5 *
6 */
7
8 /*
9 * Copyright (C) 1997 Angelos D. Keromytis.
10 * Copyright (C) 2005 Jan Hutter, Martin Willi
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24
25
26 #ifndef GMP_HELPER_H_
27 #define GMP_HELPER_H_
28
29 #include <gmp.h>
30
31 #include <types.h>
32
33 typedef struct gmp_helper_t gmp_helper_t;
34
35 /**
36 * @brief Class with helper functions to manipulate gmp values.
37 *
38 */
39 struct gmp_helper_t {
40
41 /**
42 * @brief initialize an mpz_t to a random prime of specified size
43 *
44 *
45 * @param this calling object
46 * @param[out] var mpz_t variable to initialize
47 * @param[in] bytes length of given prime in bytes
48 * @return
49 * - SUCCCESS
50 * - FAILED
51 * - OUT_OF_RES
52 */
53 status_t (*init_prime) (gmp_helper_t *this, mpz_t *var, int bytes);
54
55 /**
56 * @brief initialize an mpz_t to a random prime of specified size without using gmp
57 * next prime function! Must be faster then the gmp version
58 *
59 *
60 * @param this calling object
61 * @param[out] var mpz_t variable to initialize
62 * @param[in] bytes length of given prime in bytes
63 * @return
64 * - SUCCCESS
65 * - FAILED
66 * - OUT_OF_RES
67 */
68 status_t (*init_prime_fast) (gmp_helper_t *this, mpz_t *prime, int bytes);
69
70 /* Convert network form (binary bytes, big-endian) to mpz_t of gmp library.
71 *
72 * mpz_t gets initialized in this function.
73 *
74 * @param this calling private_gmp_helper_t object
75 * @param mpz_value pointer to a mpz_t value
76 * @param data chunk_t containing the network form of data
77 */
78 void (*chunk_to_mpz) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t data);
79
80 /* Convert mpz_t to network form (binary bytes, big-endian).
81 *
82 * @param this calling private_gmp_helper_t object
83 * @param mpz_value mpz_value to convert
84 * @param data chunk_t where the data are written to
85 * @param bytes number of bytes to copy
86 *
87 * @return
88 * - SUCCESS
89 * - OUT_OF_RES
90 * - FAILED if mpz_t value was longer then given bytes count
91 */
92 status_t (*mpz_to_chunk) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t *data,size_t bytes);
93
94 /**
95 * @brief Destroys an gmp_helper_t object.
96 *
97 * @param this gmp_helper_t object to destroy
98 * @return
99 * SUCCESS in any case
100 */
101 status_t (*destroy) (gmp_helper_t *this);
102 };
103
104 /**
105 * Creates a new gmp_helper_t object
106 *
107 * @return
108 * - gmp_helper_t if successfully
109 * - NULL if out of ressources
110 */
111 gmp_helper_t *gmp_helper_create();
112
113
114 #endif /*GMP_HELPER_H_*/