- code documentation cleaned
[strongswan.git] / Source / charon / utils / gmp_helper.h
1 /**
2 * @file gmp_helper.h
3 *
4 * @brief Interface of gmp_helper_t.
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
34 typedef struct gmp_helper_t gmp_helper_t;
35
36 /**
37 * @brief Class with helper functions to manipulate gmp values.
38 *
39 * @ingroup utils
40 */
41 struct gmp_helper_t {
42
43 /**
44 * Initialize an mpz_t to a random prime of specified size.
45 *
46 *
47 * @param this calling object
48 * @param[out] var pointer to mpz_t variable to initialize
49 * @param[in] bytes length of given prime in bytes
50 * @return
51 * - SUCCCESS
52 * - OUT_OF_RES
53 */
54 status_t (*init_prime) (gmp_helper_t *this, mpz_t *var, int bytes);
55
56 /**
57 * Initialize an mpz_t to a random prime of specified size without using gmp
58 * next prime function.
59 *
60 *
61 * @param this calling object
62 * @param[out] var mpz_t variable to initialize
63 * @param[in] bytes length of given prime in bytes
64 * @return
65 * - SUCCCESS
66 * - FAILED if length of prime not as asked. Try again.
67 * - OUT_OF_RES
68 */
69 status_t (*init_prime_fast) (gmp_helper_t *this, mpz_t *prime, int bytes);
70
71 /**
72 * Convert network form (binary bytes, big-endian) to mpz_t of gmp library.
73 *
74 * The given mpz_t gets initialized in this function.
75 *
76 * @param this calling private_gmp_helper_t object
77 * @param mpz_value pointer to a mpz_t value
78 * @param data chunk_t containing the network form of data
79 */
80 void (*chunk_to_mpz) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t data);
81
82 /**
83 * Convert mpz_t to network form (binary bytes, big-endian).
84 *
85 * @param this calling private_gmp_helper_t object
86 * @param mpz_value mpz_value to convert
87 * @param data chunk_t where the data are written to
88 * @param bytes number of bytes to copy
89 *
90 * @return
91 * - SUCCESS
92 * - OUT_OF_RES
93 * - FAILED if mpz_t value was longer then given bytes count
94 */
95 status_t (*mpz_to_chunk) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t *data,size_t bytes);
96
97 /**
98 * @brief Destroys an gmp_helper_t object.
99 *
100 * @param this gmp_helper_t object to destroy
101 * @return SUCCESS in any case
102 */
103 status_t (*destroy) (gmp_helper_t *this);
104 };
105
106 /**
107 * Creates a new gmp_helper_t object
108 *
109 * @return
110 * - gmp_helper_t object
111 * - NULL if out of ressources
112 *
113 * @ingroup utils
114 */
115 gmp_helper_t *gmp_helper_create();
116
117 #endif /*GMP_HELPER_H_*/