Add a return value to prf_t.get_bytes()
This commit is contained in:
@@ -797,8 +797,10 @@ static u_int bench_prf(private_crypto_tester_t *this,
|
||||
start_timing(&start);
|
||||
while (end_timing(&start) < this->bench_time)
|
||||
{
|
||||
prf->get_bytes(prf, buf, bytes);
|
||||
runs++;
|
||||
if (prf->get_bytes(prf, buf, bytes))
|
||||
{
|
||||
runs++;
|
||||
}
|
||||
}
|
||||
free(buf.ptr);
|
||||
prf->destroy(prf);
|
||||
@@ -860,7 +862,10 @@ METHOD(crypto_tester_t, test_prf, bool,
|
||||
{
|
||||
prf->set_key(prf, key);
|
||||
}
|
||||
prf->get_bytes(prf, seed, out.ptr);
|
||||
if (!prf->get_bytes(prf, seed, out.ptr))
|
||||
{
|
||||
failed = TRUE;
|
||||
}
|
||||
if (!memeq(vector->out, out.ptr, out.len))
|
||||
{
|
||||
failed = TRUE;
|
||||
@@ -874,8 +879,11 @@ METHOD(crypto_tester_t, test_prf, bool,
|
||||
prf->set_key(prf, key);
|
||||
}
|
||||
prf->allocate_bytes(prf, chunk_create(seed.ptr, 1), NULL);
|
||||
prf->get_bytes(prf, chunk_create(seed.ptr + 1, 1), NULL);
|
||||
prf->get_bytes(prf, chunk_skip(seed, 2), out.ptr);
|
||||
if (!prf->get_bytes(prf, chunk_create(seed.ptr + 1, 1), NULL) ||
|
||||
!prf->get_bytes(prf, chunk_skip(seed, 2), out.ptr))
|
||||
{
|
||||
failed = TRUE;
|
||||
}
|
||||
if (!memeq(vector->out, out.ptr, out.len))
|
||||
{
|
||||
failed = TRUE;
|
||||
|
||||
@@ -66,17 +66,27 @@ METHOD(prf_plus_t, get_bytes, bool,
|
||||
{
|
||||
if (this->buffer.len == this->used)
|
||||
{ /* buffer used, get next round */
|
||||
this->prf->get_bytes(this->prf, this->buffer, NULL);
|
||||
if (!this->prf->get_bytes(this->prf, this->buffer, NULL))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (this->counter)
|
||||
{
|
||||
this->prf->get_bytes(this->prf, this->seed, NULL);
|
||||
this->prf->get_bytes(this->prf, chunk_from_thing(this->counter),
|
||||
this->buffer.ptr);
|
||||
if (!this->prf->get_bytes(this->prf, this->seed, NULL) ||
|
||||
!this->prf->get_bytes(this->prf,
|
||||
chunk_from_thing(this->counter), this->buffer.ptr))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
this->counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->prf->get_bytes(this->prf, this->seed, this->buffer.ptr);
|
||||
if (!this->prf->get_bytes(this->prf, this->seed,
|
||||
this->buffer.ptr))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
this->used = 0;
|
||||
}
|
||||
@@ -131,14 +141,22 @@ prf_plus_t *prf_plus_create(prf_t *prf, bool counter, chunk_t seed)
|
||||
if (counter)
|
||||
{
|
||||
this->counter = 0x01;
|
||||
this->prf->get_bytes(this->prf, this->seed, NULL);
|
||||
this->prf->get_bytes(this->prf, chunk_from_thing(this->counter),
|
||||
this->buffer.ptr);
|
||||
if (!this->prf->get_bytes(this->prf, this->seed, NULL) ||
|
||||
!this->prf->get_bytes(this->prf, chunk_from_thing(this->counter),
|
||||
this->buffer.ptr))
|
||||
{
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
this->counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->prf->get_bytes(this->prf, this->seed, this->buffer.ptr);
|
||||
if (!this->prf->get_bytes(this->prf, this->seed, this->buffer.ptr))
|
||||
{
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return &this->public;
|
||||
|
||||
@@ -35,10 +35,11 @@ struct private_prf_t {
|
||||
mac_t *mac;
|
||||
};
|
||||
|
||||
METHOD(prf_t, get_bytes, void,
|
||||
METHOD(prf_t, get_bytes, bool,
|
||||
private_prf_t *this, chunk_t seed, u_int8_t *buffer)
|
||||
{
|
||||
this->mac->get_mac(this->mac, seed, buffer);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(prf_t, allocate_bytes, void,
|
||||
|
||||
@@ -71,13 +71,16 @@ extern enum_name_t *pseudo_random_function_names;
|
||||
* Generic interface for pseudo-random-functions.
|
||||
*/
|
||||
struct prf_t {
|
||||
|
||||
/**
|
||||
* Generates pseudo random bytes and writes them in the buffer.
|
||||
*
|
||||
* @param seed a chunk containing the seed for the next bytes
|
||||
* @param buffer pointer where the generated bytes will be written
|
||||
* @return TRUE if bytes generated successfully
|
||||
*/
|
||||
void (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer);
|
||||
__attribute__((warn_unused_result))
|
||||
bool (*get_bytes) (prf_t *this, chunk_t seed, u_int8_t *buffer);
|
||||
|
||||
/**
|
||||
* Generates pseudo random bytes and allocate space for them.
|
||||
|
||||
Reference in New Issue
Block a user