GNU General Public License for more details.
*/
-/*
- * Created: Mon Dec 8 16:35:37 GMT+0200 1997
- */
-/*
- * $Id$
- * $Log$
- * Revision 1.1 2000/06/27 11:36:51 priikone
- * Initial revision
- *
- *
- */
+/* Created: Mon Dec 8 16:35:37 GMT+0200 1997 */
+/* $Id$ */
#include "silcincludes.h"
-/* XXX This must be temporary solution!! yucky! */
-/* Global random pool used for all prime generation. All primes generated
- in SILC uses this same pool. Before primes can be generated one must
- call silc_math_primegen_init. */
-static SilcRng primegen_rng;
-
/*
Fixed primetable for small prime division. We use this primetable to
test if possible prime is divisible any of these. Primetable is NULL
*/
-static unsigned int primetable[] =
+static uint32 primetable[] =
{
2, 3, 5, 7, 11, 13, 17, 19,
23, 29, 31, 37, 41, 43, 47, 53,
If argument verbose is TRUE this will display some status information
about the progress of generation. */
-int silc_math_gen_prime(SilcInt *prime, unsigned int bits, int verbose)
+int silc_math_gen_prime(SilcInt *prime, uint32 bits, int verbose)
{
unsigned char *numbuf;
- unsigned int i, b, k;
- unsigned int *spmods;
+ uint32 i, b, k;
+ uint32 *spmods;
SilcInt r, base, tmp, tmp2, oprime;
- /* XXX */
- assert(primegen_rng != NULL);
-
silc_mp_init(&r);
silc_mp_init_set_ui(&base, 2);
silc_mp_init(&tmp);
SILC_LOG_DEBUG(("Generating new prime"));
/* Get random number */
- numbuf = silc_rng_get_rn_string(primegen_rng, (bits / 8));
+ numbuf = silc_rng_global_get_rn_string((bits / 8));
if (!numbuf)
return FALSE;
/* Init modulo table with the prime candidate and the primes
in the primetable. */
- spmods = silc_malloc(sizeof(primetable) * sizeof(unsigned int));
+ spmods = silc_calloc(1, sizeof(primetable) * sizeof(uint32));
for (i = 0; primetable[i] != 0; i++) {
silc_mp_mod_ui(&tmp, prime, primetable[i]);
spmods[i] = silc_mp_get_ui(&tmp);
/* Number is probably a prime */
return TRUE;
}
-
-/* XXX This must temporary solution!! */
-/* Initializes the random pool used to generated primes */
-
-void silc_math_primegen_init()
-{
- SILC_LOG_DEBUG(("Start"));
-
- if (primegen_rng == NULL) {
- primegen_rng = silc_rng_alloc();
- silc_rng_init(primegen_rng);
- }
-}
-
-/* XXX This must temporary solution!! */
-/* Uninitializes random pool */
-
-void silc_math_primegen_uninit()
-{
- silc_rng_free(primegen_rng);
-}