- code documentation cleaned

This commit is contained in:
Jan Hutter
2005-11-25 08:22:27 +00:00
parent f596c9a527
commit 2b4ec18f48
2 changed files with 45 additions and 51 deletions
+12 -21
View File
@@ -1,7 +1,7 @@
/** /**
* @file gmp_helper.c * @file gmp_helper.c
* *
* @brief Class with helper functions for gmp operations * @brief Implementation of gmp_helper_t.
* *
*/ */
@@ -29,10 +29,11 @@
#include <utils/randomizer.h> #include <utils/randomizer.h>
/** /**
* Number of times the probabilistic primality test is applied * Number of times the probabilistic primality test is applied.
*/ */
#define PRIMECHECK_ROUNDS 30 #define PRIMECHECK_ROUNDS 30
typedef struct private_gmp_helper_t private_gmp_helper_t; typedef struct private_gmp_helper_t private_gmp_helper_t;
/** /**
@@ -40,7 +41,7 @@ typedef struct private_gmp_helper_t private_gmp_helper_t;
*/ */
struct private_gmp_helper_t { struct private_gmp_helper_t {
/** /**
* public gmp_helper_t interface * Public gmp_helper_t interface.
*/ */
gmp_helper_t public; gmp_helper_t public;
@@ -48,8 +49,7 @@ struct private_gmp_helper_t {
/** /**
* Implements private_gmp_helper_t's chunk_to_mpz function. * Implementation of gmp_helper_t.chunk_to_mpz.
* See #private_gmp_helper_t.chunk_to_mpz for description.
*/ */
static void chunk_to_mpz(private_gmp_helper_t *this, mpz_t *mpz_value, chunk_t data) static void chunk_to_mpz(private_gmp_helper_t *this, mpz_t *mpz_value, chunk_t data)
{ {
@@ -65,8 +65,7 @@ static void chunk_to_mpz(private_gmp_helper_t *this, mpz_t *mpz_value, chunk_t d
} }
/** /**
* Implements private_gmp_helper_t's mpz_to_chunk function. * Implementation of gmp_helper_t.mpz_to_chunk.
* See #private_gmp_helper_t.mpz_to_chunk for description.
*/ */
static status_t mpz_to_chunk (private_gmp_helper_t *this,mpz_t *mpz_value, chunk_t *data,size_t bytes) static status_t mpz_to_chunk (private_gmp_helper_t *this,mpz_t *mpz_value, chunk_t *data,size_t bytes)
{ {
@@ -115,8 +114,7 @@ static status_t mpz_to_chunk (private_gmp_helper_t *this,mpz_t *mpz_value, chunk
} }
/** /**
* Implements gmp_helper_t's init_prime function. * Implementation of gmp_helper_t.init_prime.
* See #gmp_helper_t.init_prime for description.
*/ */
static status_t init_prime (private_gmp_helper_t *this, mpz_t *prime, int bytes) static status_t init_prime (private_gmp_helper_t *this, mpz_t *prime, int bytes)
{ {
@@ -140,10 +138,6 @@ static status_t init_prime (private_gmp_helper_t *this, mpz_t *prime, int bytes)
/* not needed anymore */ /* not needed anymore */
randomizer->destroy(randomizer); randomizer->destroy(randomizer);
if (status != SUCCESS)
{
return status;
}
/* convert chunk to mpz value */ /* convert chunk to mpz value */
this->public.chunk_to_mpz(&(this->public),prime, random_bytes); this->public.chunk_to_mpz(&(this->public),prime, random_bytes);
@@ -158,7 +152,9 @@ static status_t init_prime (private_gmp_helper_t *this, mpz_t *prime, int bytes)
return SUCCESS; return SUCCESS;
} }
/**
* Implementation of gmp_helper_t.init_prime_fast.
*/
static status_t init_prime_fast (private_gmp_helper_t *this, mpz_t *prime, int bytes){ static status_t init_prime_fast (private_gmp_helper_t *this, mpz_t *prime, int bytes){
randomizer_t *randomizer; randomizer_t *randomizer;
chunk_t random_bytes; chunk_t random_bytes;
@@ -182,10 +178,6 @@ static status_t init_prime_fast (private_gmp_helper_t *this, mpz_t *prime, int b
random_bytes.ptr[0] = random_bytes.ptr[0] | 0x80; random_bytes.ptr[0] = random_bytes.ptr[0] | 0x80;
/* not needed anymore */ /* not needed anymore */
randomizer->destroy(randomizer); randomizer->destroy(randomizer);
if (status != SUCCESS)
{
return status;
}
/* convert chunk to mpz value */ /* convert chunk to mpz value */
this->public.chunk_to_mpz(&(this->public),prime, random_bytes); this->public.chunk_to_mpz(&(this->public),prime, random_bytes);
@@ -214,7 +206,7 @@ static status_t init_prime_fast (private_gmp_helper_t *this, mpz_t *prime, int b
length = mpz_sizeinbase(*prime, 2); length = mpz_sizeinbase(*prime, 2);
/* check bit length of primee */ /* check bit length of prime */
if ((length < (bytes * 8)) || (length > ((bytes * 8) + 1))) if ((length < (bytes * 8)) || (length > ((bytes * 8) + 1)))
{ {
return FAILED; return FAILED;
@@ -235,8 +227,7 @@ static status_t init_prime_fast (private_gmp_helper_t *this, mpz_t *prime, int b
/** /**
* Implements gmp_helper_t's destroy function. * Implementation of gmp_helper_t.destroy.
* See #gmp_helper_t.destroy for description.
*/ */
static status_t destroy(private_gmp_helper_t *this) static status_t destroy(private_gmp_helper_t *this)
{ {
+31 -28
View File
@@ -1,7 +1,7 @@
/** /**
* @file gmp_helper.h * @file gmp_helper.h
* *
* @brief Class with helper functions for gmp operations * @brief Interface of gmp_helper_t.
* *
*/ */
@@ -30,64 +30,67 @@
#include <types.h> #include <types.h>
typedef struct gmp_helper_t gmp_helper_t; typedef struct gmp_helper_t gmp_helper_t;
/** /**
* @brief Class with helper functions to manipulate gmp values. * @brief Class with helper functions to manipulate gmp values.
* *
* @ingroup utils
*/ */
struct gmp_helper_t { struct gmp_helper_t {
/** /**
* @brief initialize an mpz_t to a random prime of specified size * Initialize an mpz_t to a random prime of specified size.
* *
* *
* @param this calling object * @param this calling object
* @param[out] var mpz_t variable to initialize * @param[out] var pointer to mpz_t variable to initialize
* @param[in] bytes length of given prime in bytes * @param[in] bytes length of given prime in bytes
* @return * @return
* - SUCCCESS * - SUCCCESS
* - FAILED * - OUT_OF_RES
* - OUT_OF_RES
*/ */
status_t (*init_prime) (gmp_helper_t *this, mpz_t *var, int bytes); status_t (*init_prime) (gmp_helper_t *this, mpz_t *var, int bytes);
/** /**
* @brief initialize an mpz_t to a random prime of specified size without using gmp * Initialize an mpz_t to a random prime of specified size without using gmp
* next prime function! Must be faster then the gmp version * next prime function.
* *
* *
* @param this calling object * @param this calling object
* @param[out] var mpz_t variable to initialize * @param[out] var mpz_t variable to initialize
* @param[in] bytes length of given prime in bytes * @param[in] bytes length of given prime in bytes
* @return * @return
* - SUCCCESS * - SUCCCESS
* - FAILED * - FAILED if length of prime not as asked. Try again.
* - OUT_OF_RES * - OUT_OF_RES
*/ */
status_t (*init_prime_fast) (gmp_helper_t *this, mpz_t *prime, int bytes); status_t (*init_prime_fast) (gmp_helper_t *this, mpz_t *prime, int bytes);
/* Convert network form (binary bytes, big-endian) to mpz_t of gmp library. /**
* Convert network form (binary bytes, big-endian) to mpz_t of gmp library.
* *
* mpz_t gets initialized in this function. * The given mpz_t gets initialized in this function.
* *
* @param this calling private_gmp_helper_t object * @param this calling private_gmp_helper_t object
* @param mpz_value pointer to a mpz_t value * @param mpz_value pointer to a mpz_t value
* @param data chunk_t containing the network form of data * @param data chunk_t containing the network form of data
*/ */
void (*chunk_to_mpz) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t data); void (*chunk_to_mpz) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t data);
/* Convert mpz_t to network form (binary bytes, big-endian). /**
* Convert mpz_t to network form (binary bytes, big-endian).
* *
* @param this calling private_gmp_helper_t object * @param this calling private_gmp_helper_t object
* @param mpz_value mpz_value to convert * @param mpz_value mpz_value to convert
* @param data chunk_t where the data are written to * @param data chunk_t where the data are written to
* @param bytes number of bytes to copy * @param bytes number of bytes to copy
* *
* @return * @return
* - SUCCESS * - SUCCESS
* - OUT_OF_RES * - OUT_OF_RES
* - FAILED if mpz_t value was longer then given bytes count * - FAILED if mpz_t value was longer then given bytes count
*/ */
status_t (*mpz_to_chunk) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t *data,size_t bytes); status_t (*mpz_to_chunk) (gmp_helper_t *this,mpz_t *mpz_value, chunk_t *data,size_t bytes);
@@ -95,8 +98,7 @@ struct gmp_helper_t {
* @brief Destroys an gmp_helper_t object. * @brief Destroys an gmp_helper_t object.
* *
* @param this gmp_helper_t object to destroy * @param this gmp_helper_t object to destroy
* @return * @return SUCCESS in any case
* SUCCESS in any case
*/ */
status_t (*destroy) (gmp_helper_t *this); status_t (*destroy) (gmp_helper_t *this);
}; };
@@ -105,10 +107,11 @@ struct gmp_helper_t {
* Creates a new gmp_helper_t object * Creates a new gmp_helper_t object
* *
* @return * @return
* - gmp_helper_t if successfully * - gmp_helper_t object
* - NULL if out of ressources * - NULL if out of ressources
*
* @ingroup utils
*/ */
gmp_helper_t *gmp_helper_create(); gmp_helper_t *gmp_helper_create();
#endif /*GMP_HELPER_H_*/ #endif /*GMP_HELPER_H_*/