Add a return value to prf_t.allocate_bytes()

This commit is contained in:
Martin Willi
2012-07-16 14:53:34 +02:00
parent a7e6539135
commit ecc080b393
9 changed files with 92 additions and 43 deletions
+6 -3
View File
@@ -847,7 +847,10 @@ METHOD(crypto_tester_t, test_prf, bool,
/* allocated bytes */
seed = chunk_create(vector->seed, vector->len);
prf->allocate_bytes(prf, seed, &out);
if (!prf->allocate_bytes(prf, seed, &out))
{
failed = TRUE;
}
if (out.len != prf->get_block_size(prf))
{
failed = TRUE;
@@ -878,8 +881,8 @@ METHOD(crypto_tester_t, test_prf, bool,
{
prf->set_key(prf, key);
}
prf->allocate_bytes(prf, chunk_create(seed.ptr, 1), NULL);
if (!prf->get_bytes(prf, chunk_create(seed.ptr + 1, 1), NULL) ||
if (!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))
{
failed = TRUE;
+2 -1
View File
@@ -42,7 +42,7 @@ METHOD(prf_t, get_bytes, bool,
return TRUE;
}
METHOD(prf_t, allocate_bytes, void,
METHOD(prf_t, allocate_bytes, bool,
private_prf_t *this, chunk_t seed, chunk_t *chunk)
{
if (!chunk)
@@ -54,6 +54,7 @@ METHOD(prf_t, allocate_bytes, void,
*chunk = chunk_alloc(this->mac->get_mac_size(this->mac));
this->mac->get_mac(this->mac, seed, chunk->ptr);
}
return TRUE;
}
METHOD(prf_t, get_block_size, size_t,
+3 -1
View File
@@ -87,8 +87,10 @@ struct prf_t {
*
* @param seed a chunk containing the seed for the next bytes
* @param chunk chunk which will hold generated bytes
* @return TRUE if bytes allocated and generated successfully
*/
void (*allocate_bytes) (prf_t *this, chunk_t seed, chunk_t *chunk);
__attribute__((warn_unused_result))
bool (*allocate_bytes) (prf_t *this, chunk_t seed, chunk_t *chunk);
/**
* Get the block size of this prf_t object.
@@ -112,18 +112,15 @@ METHOD(prf_t, get_bytes, bool,
return TRUE;
}
METHOD(prf_t, allocate_bytes, void,
METHOD(prf_t, allocate_bytes, bool,
private_af_alg_prf_t *this, chunk_t seed, chunk_t *chunk)
{
if (chunk)
{
*chunk = chunk_alloc(this->block_size);
get_bytes(this, seed, chunk->ptr);
}
else
{
get_bytes(this, seed, NULL);
return get_bytes(this, seed, chunk->ptr);
}
return get_bytes(this, seed, NULL);
}
METHOD(prf_t, get_block_size, size_t,
@@ -147,11 +147,11 @@ METHOD(prf_t, get_block_size, size_t,
{
return 2 * this->b;
}
METHOD(prf_t, allocate_bytes, void,
METHOD(prf_t, allocate_bytes, bool,
private_fips_prf_t *this, chunk_t seed, chunk_t *chunk)
{
*chunk = chunk_alloc(get_block_size(this));
get_bytes(this, seed, chunk->ptr);
return get_bytes(this, seed, chunk->ptr);
}
METHOD(prf_t, get_key_size, size_t,
@@ -60,18 +60,15 @@ METHOD(prf_t, get_block_size, size_t,
return HASH_SIZE_SHA1;
}
METHOD(prf_t, allocate_bytes, void,
METHOD(prf_t, allocate_bytes, bool,
private_openssl_sha1_prf_t *this, chunk_t seed, chunk_t *chunk)
{
if (chunk)
{
*chunk = chunk_alloc(HASH_SIZE_SHA1);
get_bytes(this, seed, chunk->ptr);
}
else
{
get_bytes(this, seed, NULL);
return get_bytes(this, seed, chunk->ptr);
}
return get_bytes(this, seed, NULL);
}
METHOD(prf_t, get_key_size, size_t,
+2 -2
View File
@@ -81,11 +81,11 @@ METHOD(prf_t, get_block_size, size_t,
return HASH_SIZE_SHA1;
}
METHOD(prf_t, allocate_bytes, void,
METHOD(prf_t, allocate_bytes, bool,
private_sha1_prf_t *this, chunk_t seed, chunk_t *chunk)
{
*chunk = chunk_alloc(HASH_SIZE_SHA1);
get_bytes(this, seed, chunk->ptr);
return get_bytes(this, seed, chunk->ptr);
}
METHOD(prf_t, get_key_size, size_t,