one.
tma_mp_clear(mp);
}
+void silc_mp_suninit(SilcStack stack, SilcMPInt *mp)
+{
+ if (!stack)
+ tma_mp_clear(mp);
+}
+
size_t silc_mp_size(SilcMPInt *mp)
{
return tma_mp_unsigned_bin_size(mp);
*
* DESCRIPTION
*
- * Initializes the SilcMPInt *that is the actual MP Integer.
+ * Initializes the SilcMPInt that is the actual MP Integer.
* This must be called before any of the silc_mp_ routines can be
* used. The integer is uninitialized with the silc_mp_uninit function.
*
***/
void silc_mp_init(SilcMPInt *mp);
+/****f* silcmath/SilcMPAPI/silc_mp_sinit
+ *
+ * SYNOPSIS
+ *
+ * SilcBool silc_mp_sinit(SilcStack stack, SilcMPInt *mp);
+ *
+ * DESCRIPTION
+ *
+ * Initializes the SilcMPInt that is the actual MP Integer.
+ * This must be called before any of the silc_mp_ routines can be
+ * used. The integer is uninitialized with the silc_mp_suninit function.
+ * If `stack' is non-NULL it will be used as the memory source. If it
+ * is NULL, this call is equivalent to silc_mp_init.
+ *
+ ***/
SilcBool silc_mp_sinit(SilcStack stack, SilcMPInt *mp);
/****f* silcmath/SilcMPAPI/silc_mp_uninit
***/
void silc_mp_uninit(SilcMPInt *mp);
+/****f* silcmath/SilcMPAPI/silc_mp_suninit
+ *
+ * SYNOPSIS
+ *
+ * void silc_mp_suninit(SilcStack stack, SilcMPInt *mp);
+ *
+ * DESCRIPTION
+ *
+ * Uninitializes the MP Integer.
+ *
+ ***/
+void silc_mp_suninit(SilcStack stack, SilcMPInt *mp);
+
/****f* silcmath/SilcMPAPI/silc_mp_size
*
* SYNOPSIS
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2005 Pekka Riikonen
+ Copyright (C) 1997 - 2007 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
SilcBool silc_math_gen_prime(SilcMPInt *prime, SilcUInt32 bits,
SilcBool verbose, SilcRng rng)
{
- unsigned char *numbuf = NULL;
+ unsigned char *numbuf;
SilcUInt32 i, b, k;
SilcUInt32 *spmods;
SilcMPInt r, base, tmp, tmp2, oprime;
SILC_LOG_DEBUG(("Generating new prime"));
while (valid == FALSE) {
+ numbuf = silc_malloc((((bits + 7) / 8) + 1) * sizeof(*numbuf));
+ if (!numbuf)
+ return FALSE;
+
/* Get random number */
if (rng)
- numbuf = silc_rng_get_rn_data(rng, (bits / 8));
+ silc_rng_get_rn_data(rng, (bits / 8), numbuf, (bits / 8));
else
- numbuf = silc_rng_global_get_rn_data((bits / 8));
- if (!numbuf)
- return FALSE;
+ silc_rng_global_get_rn_data(rng, (bits / 8), numbuf, (bits / 8));
/* Convert into MP and set the size */
silc_mp_bin2mp(numbuf, (bits / 8), prime);