destroy(this);
return NULL;
}
-
- rng->allocate_bytes(rng, exp_len, &random);
+ if (!rng->allocate_bytes(rng, exp_len, &random))
+ {
+ DBG1(DBG_LIB, "failed to allocate DH secret");
+ rng->destroy(rng);
+ destroy(this);
+ return NULL;
+ }
rng->destroy(rng);
if (exp_len == this->p_len)
mpz_init(*prime);
do
{
- rng->allocate_bytes(rng, prime_size, &random_bytes);
+ if (!rng->allocate_bytes(rng, prime_size, &random_bytes))
+ {
+ DBG1(DBG_LIB, "failed to allocate random prime");
+ rng->destroy(rng);
+ return FAILED;
+ }
/* make sure the two most significant bits are set */
random_bytes.ptr[0] = random_bytes.ptr[0] | 0xC0;
{
chunk_t em;
u_char *pos;
- int padding, i;
+ int padding;
rng_t *rng;
if (scheme != ENCRYPT_RSA_PKCS1)
*pos++ = 0x02;
/* fill with pseudo random octets */
- rng->get_bytes(rng, padding, pos);
-
- /* replace zero-valued random octets */
- for (i = 0; i < padding; i++)
+ if (!rng_get_bytes_not_zero(rng, padding, pos, TRUE))
{
- while (*pos == 0)
- {
- rng->get_bytes(rng, 1, pos);
- }
- pos++;
+ DBG1(DBG_LIB, "failed to allocate padding");
+ chunk_clear(&em);
+ rng->destroy(rng);
+ return FALSE;
}
rng->destroy(rng);