- wrote diffie_hellman_t but not tested
[strongswan.git] / Source / charon / utils / gmp_helper.h
1 /**
2 * @file gmp_helper.c
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 /**
34 * Class with helper functions to manipulate gmp values
35 *
36 */
37 typedef struct gmp_helper_s gmp_helper_t;
38
39 struct gmp_helper_s {
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 /* Convert network form (binary bytes, big-endian) to mpz_t of gmp library.
56 *
57 * mpz_t gets initialized in this function.
58 *
59 * @param this calling private_gmp_helper_t object
60 * @param mpz_value pointer to a mpz_t value
61 * @param data chunk_t containing the network form of data
62 */
63 void (*chunk_to_mpz) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t data);
64
65 /* Convert mpz_t to network form (binary bytes, big-endian).
66 *
67 * @param this calling private_gmp_helper_t object
68 * @param mpz_value mpz_value to convert
69 * @param data chunk_t where the data are written to
70 * @param bytes number of bytes to copy
71 *
72 * @return
73 * - SUCCESS
74 * - OUT_OF_RES
75 * - FAILED if mpz_t value was longer then given bytes count
76 */
77 status_t (*mpz_to_chunk) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t *data,size_t bytes);
78
79 /**
80 * @brief Destroys an gmp_helper_t object.
81 *
82 * @param this gmp_helper_t object to destroy
83 * @return
84 * SUCCESS in any case
85 */
86 status_t (*destroy) (gmp_helper_t *this);
87 };
88
89 /**
90 * Creates a new gmp_helper_t object
91 *
92 * @return
93 * - gmp_helper_t if successfully
94 * - NULL if out of ressources
95 */
96 gmp_helper_t *gmp_helper_create();
97
98
99 #endif /*GMP_HELPER_H_*/