4 * @brief Class with helper functions for gmp operations
9 * Copyright (C) 1997 Angelos D. Keromytis.
10 * Copyright (C) 2005 Jan Hutter, Martin Willi
11 * Hochschule fuer Technik Rapperswil
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>.
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
34 * Class with helper functions to manipulate gmp values
37 typedef struct gmp_helper_s gmp_helper_t
;
42 * @brief initialize an mpz_t to a random prime of specified size
45 * @param this calling object
46 * @param[out] var mpz_t variable to initialize
47 * @param[in] bytes length of given prime in bytes
53 status_t (*init_prime
) (gmp_helper_t
*this, mpz_t
*var
, int bytes
);
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
60 * @param this calling object
61 * @param[out] var mpz_t variable to initialize
62 * @param[in] bytes length of given prime in bytes
68 status_t (*init_prime_fast
) (gmp_helper_t
*this, mpz_t
*prime
, int bytes
);
70 /* Convert network form (binary bytes, big-endian) to mpz_t of gmp library.
72 * mpz_t gets initialized in this function.
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
78 void (*chunk_to_mpz
) (gmp_helper_t
*this,mpz_t
*mpz_value
, chunk_t data
);
80 /* Convert mpz_t to network form (binary bytes, big-endian).
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
90 * - FAILED if mpz_t value was longer then given bytes count
92 status_t (*mpz_to_chunk
) (gmp_helper_t
*this,mpz_t
*mpz_value
, chunk_t
*data
,size_t bytes
);
95 * @brief Destroys an gmp_helper_t object.
97 * @param this gmp_helper_t object to destroy
101 status_t (*destroy
) (gmp_helper_t
*this);
105 * Creates a new gmp_helper_t object
108 * - gmp_helper_t if successfully
109 * - NULL if out of ressources
111 gmp_helper_t
*gmp_helper_create();
114 #endif /*GMP_HELPER_H_*/