Add a return value to signer_t.allocate_signature()

This commit is contained in:
Martin Willi
2012-07-16 14:53:32 +02:00
parent ad08730a4b
commit cbfbba7d86
6 changed files with 25 additions and 7 deletions
+4 -1
View File
@@ -52,7 +52,10 @@ METHOD(aead_t, encrypt, bool,
if (encrypted)
{
this->crypter->encrypt(this->crypter, plain, iv, &encr);
this->signer->allocate_signature(this->signer, encr, &sig);
if (!this->signer->allocate_signature(this->signer, encr, &sig))
{
return FALSE;
}
*encrypted = chunk_cat("cmm", iv, encr, sig);
}
else
+9 -2
View File
@@ -547,7 +547,10 @@ METHOD(crypto_tester_t, test_signer, bool,
/* allocated signature */
data = chunk_create(vector->data, vector->len);
signer->allocate_signature(signer, data, &mac);
if (!signer->allocate_signature(signer, data, &mac))
{
failed = TRUE;
}
if (mac.len != signer->get_block_size(signer))
{
failed = TRUE;
@@ -577,7 +580,11 @@ METHOD(crypto_tester_t, test_signer, bool,
/* signature to existing buffer, using append mode */
if (data.len > 2)
{
signer->allocate_signature(signer, chunk_create(data.ptr, 1), NULL);
if (!signer->allocate_signature(signer,
chunk_create(data.ptr, 1), NULL))
{
failed = TRUE;
}
signer->get_signature(signer, chunk_create(data.ptr + 1, 1), NULL);
if (!signer->verify_signature(signer, chunk_skip(data, 2),
chunk_create(vector->mac, mac.len)))
@@ -56,7 +56,7 @@ METHOD(signer_t, get_signature, void,
}
}
METHOD(signer_t, allocate_signature, void,
METHOD(signer_t, allocate_signature, bool,
private_signer_t *this, chunk_t data, chunk_t *chunk)
{
if (chunk == NULL)
@@ -72,6 +72,7 @@ METHOD(signer_t, allocate_signature, void,
*chunk = chunk_alloc(this->truncation);
memcpy(chunk->ptr, mac, this->truncation);
}
return TRUE;
}
METHOD(signer_t, verify_signature, bool,
+3 -1
View File
@@ -102,8 +102,10 @@ struct signer_t {
*
* @param data a chunk containing the data to sign
* @param chunk chunk which will hold the allocated signature
* @return TRUE if signature allocated successfully
*/
void (*allocate_signature) (signer_t *this, chunk_t data, chunk_t *chunk);
__attribute__((warn_unused_result))
bool (*allocate_signature) (signer_t *this, chunk_t data, chunk_t *chunk);
/**
* Verify a signature.
@@ -113,7 +113,7 @@ METHOD(signer_t, get_signature, void,
this->ops->hash(this->ops, data, buffer, this->block_size);
}
METHOD(signer_t, allocate_signature, void,
METHOD(signer_t, allocate_signature, bool,
private_af_alg_signer_t *this, chunk_t data, chunk_t *chunk)
{
if (chunk)
@@ -125,6 +125,7 @@ METHOD(signer_t, allocate_signature, void,
{
get_signature(this, data, NULL);
}
return TRUE;
}
METHOD(signer_t, verify_signature, bool,
+5 -1
View File
@@ -220,7 +220,11 @@ METHOD(tls_protection_t, build, status_t,
sigheader(this->signer_out, this->seq_out, *type,
this->version, data->len);
this->signer_out->allocate_signature(this->signer_out, *data, &mac);
if (!this->signer_out->allocate_signature(this->signer_out,
*data, &mac))
{
return FAILED;
}
if (this->crypter_out)
{
chunk_t padding, iv;