Add a return value to prf_t.set_key()
This commit is contained in:
@@ -843,7 +843,10 @@ METHOD(crypto_tester_t, test_prf, bool,
|
||||
failed = FALSE;
|
||||
|
||||
key = chunk_create(vector->key, vector->key_size);
|
||||
prf->set_key(prf, key);
|
||||
if (!prf->set_key(prf, key))
|
||||
{
|
||||
failed = TRUE;
|
||||
}
|
||||
|
||||
/* allocated bytes */
|
||||
seed = chunk_create(vector->seed, vector->len);
|
||||
@@ -863,7 +866,10 @@ METHOD(crypto_tester_t, test_prf, bool,
|
||||
memset(out.ptr, 0, out.len);
|
||||
if (vector->stateful)
|
||||
{
|
||||
prf->set_key(prf, key);
|
||||
if (!prf->set_key(prf, key))
|
||||
{
|
||||
failed = TRUE;
|
||||
}
|
||||
}
|
||||
if (!prf->get_bytes(prf, seed, out.ptr))
|
||||
{
|
||||
@@ -879,7 +885,10 @@ METHOD(crypto_tester_t, test_prf, bool,
|
||||
memset(out.ptr, 0, out.len);
|
||||
if (vector->stateful)
|
||||
{
|
||||
prf->set_key(prf, key);
|
||||
if (!prf->set_key(prf, key))
|
||||
{
|
||||
failed = TRUE;
|
||||
}
|
||||
}
|
||||
if (!prf->allocate_bytes(prf, chunk_create(seed.ptr, 1), NULL) ||
|
||||
!prf->get_bytes(prf, chunk_create(seed.ptr + 1, 1), NULL) ||
|
||||
|
||||
@@ -70,10 +70,11 @@ METHOD(prf_t, get_key_size, size_t,
|
||||
return this->mac->get_mac_size(this->mac);
|
||||
}
|
||||
|
||||
METHOD(prf_t, set_key, void,
|
||||
METHOD(prf_t, set_key, bool,
|
||||
private_prf_t *this, chunk_t key)
|
||||
{
|
||||
this->mac->set_key(this->mac, key);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(prf_t, destroy, void,
|
||||
|
||||
@@ -113,8 +113,10 @@ struct prf_t {
|
||||
* Set the key for this prf_t object.
|
||||
*
|
||||
* @param key key to set
|
||||
* @return TRUE if key set successfully
|
||||
*/
|
||||
void (*set_key) (prf_t *this, chunk_t key);
|
||||
__attribute__((warn_unused_result))
|
||||
bool (*set_key) (prf_t *this, chunk_t key);
|
||||
|
||||
/**
|
||||
* Destroys a prf object.
|
||||
|
||||
@@ -135,7 +135,7 @@ METHOD(prf_t, get_key_size, size_t,
|
||||
return this->block_size;
|
||||
}
|
||||
|
||||
METHOD(prf_t, set_key, void,
|
||||
METHOD(prf_t, set_key, bool,
|
||||
private_af_alg_prf_t *this, chunk_t key)
|
||||
{
|
||||
char buf[this->block_size];
|
||||
@@ -159,6 +159,7 @@ METHOD(prf_t, set_key, void,
|
||||
}
|
||||
}
|
||||
this->ops->set_key(this->ops, key);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(prf_t, destroy, void,
|
||||
|
||||
@@ -160,11 +160,12 @@ METHOD(prf_t, get_key_size, size_t,
|
||||
return this->b;
|
||||
}
|
||||
|
||||
METHOD(prf_t, set_key, void,
|
||||
METHOD(prf_t, set_key, bool,
|
||||
private_fips_prf_t *this, chunk_t key)
|
||||
{
|
||||
/* save key as "key mod 2^b" */
|
||||
chunk_mod(this->b, key, this->key);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,8 +190,8 @@ static bool g_sha1(private_fips_prf_t *this, chunk_t c, u_int8_t res[])
|
||||
}
|
||||
|
||||
/* use the keyed hasher, but use an empty key to use SHA1 IV */
|
||||
this->keyed_prf->set_key(this->keyed_prf, chunk_empty);
|
||||
if (!this->keyed_prf->get_bytes(this->keyed_prf, c, res))
|
||||
if (!this->keyed_prf->set_key(this->keyed_prf, chunk_empty) ||
|
||||
!this->keyed_prf->get_bytes(this->keyed_prf, c, res))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -77,11 +77,15 @@ METHOD(prf_t, get_key_size, size_t,
|
||||
return HASH_SIZE_SHA1;
|
||||
}
|
||||
|
||||
METHOD(prf_t, set_key, void,
|
||||
METHOD(prf_t, set_key, bool,
|
||||
private_openssl_sha1_prf_t *this, chunk_t key)
|
||||
{
|
||||
SHA1_Init(&this->ctx);
|
||||
|
||||
if (key.len % 4)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (key.len >= 4)
|
||||
{
|
||||
this->ctx.h0 ^= untoh32(key.ptr);
|
||||
@@ -102,6 +106,7 @@ METHOD(prf_t, set_key, void,
|
||||
{
|
||||
this->ctx.h4 ^= untoh32(key.ptr + 16);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(prf_t, destroy, void,
|
||||
|
||||
@@ -225,7 +225,10 @@ static bool pbkdf2(prf_t *prf, chunk_t password, chunk_t salt,
|
||||
size_t blocks;
|
||||
u_int32_t i = 0, *ni;
|
||||
|
||||
prf->set_key(prf, password);
|
||||
if (!prf->set_key(prf, password))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
block.len = prf->get_block_size(prf);
|
||||
blocks = (key.len - 1) / block.len + 1;
|
||||
|
||||
@@ -94,7 +94,7 @@ METHOD(prf_t, get_key_size, size_t,
|
||||
return sizeof(this->hasher->state);
|
||||
}
|
||||
|
||||
METHOD(prf_t, set_key, void,
|
||||
METHOD(prf_t, set_key, bool,
|
||||
private_sha1_prf_t *this, chunk_t key)
|
||||
{
|
||||
int i, rounds;
|
||||
@@ -106,6 +106,7 @@ METHOD(prf_t, set_key, void,
|
||||
{
|
||||
this->hasher->state[i] ^= htonl(iv[i]);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
METHOD(prf_t, destroy, void,
|
||||
|
||||
Reference in New Issue
Block a user