static void initialize(void) { initialize_basics (); /* The data buffer is allocated somewhat larger, so that we can use this extra space (which is allocated in secure memory) as a temporary hash buffer */ rndpool = secure_alloc ? gcry_xcalloc_secure(1,POOLSIZE+BLOCKLEN) : gcry_xcalloc(1,POOLSIZE+BLOCKLEN); keypool = secure_alloc ? gcry_xcalloc_secure(1,POOLSIZE+BLOCKLEN) : gcry_xcalloc(1,POOLSIZE+BLOCKLEN); is_initialized = 1; }
/**************** * Resize the array of A to NLIMBS. The additional space is cleared * (set to 0). */ void _gcry_mpi_resize (gcry_mpi_t a, unsigned nlimbs) { size_t i; if (nlimbs <= a->alloced) { /* We only need to clear the new space (this is a nop if the limb space is already of the correct size. */ for (i=a->nlimbs; i < a->alloced; i++) a->d[i] = 0; return; } /* Actually resize the limb space. */ if (a->d) { a->d = gcry_xrealloc (a->d, nlimbs * sizeof (mpi_limb_t)); for (i=a->alloced; i < nlimbs; i++) a->d[i] = 0; } else { if (a->flags & 1) /* Secure memory is wanted. */ a->d = gcry_xcalloc_secure (nlimbs , sizeof (mpi_limb_t)); else /* Standard memory. */ a->d = gcry_xcalloc (nlimbs , sizeof (mpi_limb_t)); } a->alloced = nlimbs; }
/* Full initialization of this module. */ static void initialize(void) { /* Although the basic initialization should have happened already, we call it here to make sure that all prerequisites are met. */ initialize_basics (); /* Now we can look the pool and complete the initialization if necessary. */ lock_pool (); if (!rndpool) { /* The data buffer is allocated somewhat larger, so that we can use this extra space (which is allocated in secure memory) as a temporary hash buffer */ rndpool = (secure_alloc ? gcry_xcalloc_secure (1, POOLSIZE + BLOCKLEN) : gcry_xcalloc (1, POOLSIZE + BLOCKLEN)); keypool = (secure_alloc ? gcry_xcalloc_secure (1, POOLSIZE + BLOCKLEN) : gcry_xcalloc (1, POOLSIZE + BLOCKLEN)); /* Setup the slow entropy gathering function. The code requires that this function exists. */ slow_gather_fnc = getfnc_gather_random (); if (!slow_gather_fnc) { faked_rng = 1; slow_gather_fnc = gather_faked; } /* Setup the fast entropy gathering function. */ fast_gather_fnc = getfnc_fast_random_poll (); } unlock_pool (); }
/**************** * Resize the array of A to NLIMBS. the additional space is cleared * (set to 0) [done by gcry_realloc()] */ void _gcry_mpi_resize (gcry_mpi_t a, unsigned nlimbs) { if (nlimbs <= a->alloced) return; /* no need to do it */ if (a->d) a->d = gcry_xrealloc (a->d, nlimbs * sizeof (mpi_limb_t)); else { if (a->flags & 1) /* Secure memory is wanted. */ a->d = gcry_xcalloc_secure (nlimbs , sizeof (mpi_limb_t)); else /* Standard memory. */ a->d = gcry_xcalloc (nlimbs , sizeof (mpi_limb_t)); } a->alloced = nlimbs; }