Add a return value to signer_t.get_signature()

This commit is contained in:
Martin Willi
2012-07-16 14:53:33 +02:00
parent 5fb719e0de
commit 2e96de60a8
8 changed files with 63 additions and 32 deletions
+15 -5
View File
@@ -46,8 +46,11 @@ METHOD(aead_t, encrypt, bool,
{
chunk_t encr, sig;
this->signer->get_signature(this->signer, assoc, NULL);
this->signer->get_signature(this->signer, iv, NULL);
if (!this->signer->get_signature(this->signer, assoc, NULL) ||
!this->signer->get_signature(this->signer, iv, NULL))
{
return FALSE;
}
if (encrypted)
{
@@ -61,7 +64,11 @@ METHOD(aead_t, encrypt, bool,
else
{
this->crypter->encrypt(this->crypter, plain, iv, NULL);
this->signer->get_signature(this->signer, plain, plain.ptr + plain.len);
if (!this->signer->get_signature(this->signer,
plain, plain.ptr + plain.len))
{
return FALSE;
}
}
return TRUE;
}
@@ -84,8 +91,11 @@ METHOD(aead_t, decrypt, bool,
chunk_split(encrypted, "mm", encrypted.len - sig.len,
&encrypted, sig.len, &sig);
this->signer->get_signature(this->signer, assoc, NULL);
this->signer->get_signature(this->signer, iv, NULL);
if (!this->signer->get_signature(this->signer, assoc, NULL) ||
!this->signer->get_signature(this->signer, iv, NULL))
{
return FALSE;
}
if (!this->signer->verify_signature(this->signer, encrypted, sig))
{
DBG1(DBG_LIB, "MAC verification failed");
+17 -6
View File
@@ -497,10 +497,14 @@ static u_int bench_signer(private_crypto_tester_t *this,
start_timing(&start);
while (end_timing(&start) < this->bench_time)
{
signer->get_signature(signer, buf, mac);
runs++;
signer->verify_signature(signer, buf, chunk_from_thing(mac));
runs++;
if (signer->get_signature(signer, buf, mac))
{
runs++;
}
if (signer->verify_signature(signer, buf, chunk_from_thing(mac)))
{
runs++;
}
}
free(buf.ptr);
signer->destroy(signer);
@@ -561,7 +565,10 @@ METHOD(crypto_tester_t, test_signer, bool,
}
/* signature to existing buffer */
memset(mac.ptr, 0, mac.len);
signer->get_signature(signer, data, mac.ptr);
if (!signer->get_signature(signer, data, mac.ptr))
{
failed = TRUE;
}
if (!memeq(vector->mac, mac.ptr, mac.len))
{
failed = TRUE;
@@ -585,7 +592,11 @@ METHOD(crypto_tester_t, test_signer, bool,
{
failed = TRUE;
}
signer->get_signature(signer, chunk_create(data.ptr + 1, 1), NULL);
if (!signer->get_signature(signer,
chunk_create(data.ptr + 1, 1), NULL))
{
failed = TRUE;
}
if (!signer->verify_signature(signer, chunk_skip(data, 2),
chunk_create(vector->mac, mac.len)))
{
@@ -40,7 +40,7 @@ struct private_signer_t {
size_t truncation;
};
METHOD(signer_t, get_signature, void,
METHOD(signer_t, get_signature, bool,
private_signer_t *this, chunk_t data, u_int8_t *buffer)
{
if (buffer == NULL)
@@ -54,6 +54,7 @@ METHOD(signer_t, get_signature, void,
this->mac->get_mac(this->mac, data, mac);
memcpy(buffer, mac, this->truncation);
}
return TRUE;
}
METHOD(signer_t, allocate_signature, bool,
+3 -1
View File
@@ -91,8 +91,10 @@ struct signer_t {
*
* @param data a chunk containing the data to sign
* @param buffer pointer where the signature will be written
* @return TRUE if signature created successfully
*/
void (*get_signature) (signer_t *this, chunk_t data, u_int8_t *buffer);
__attribute__((warn_unused_result))
bool (*get_signature) (signer_t *this, chunk_t data, u_int8_t *buffer);
/**
* Generate a signature and allocate space for it.
@@ -107,10 +107,11 @@ static size_t lookup_alg(integrity_algorithm_t algo, char **name,
return 0;
}
METHOD(signer_t, get_signature, void,
METHOD(signer_t, get_signature, bool,
private_af_alg_signer_t *this, chunk_t data, u_int8_t *buffer)
{
this->ops->hash(this->ops, data, buffer, this->block_size);
return TRUE;
}
METHOD(signer_t, allocate_signature, bool,
@@ -119,13 +120,9 @@ METHOD(signer_t, allocate_signature, bool,
if (chunk)
{
*chunk = chunk_alloc(this->block_size);
get_signature(this, data, chunk->ptr);
return get_signature(this, data, chunk->ptr);
}
else
{
get_signature(this, data, NULL);
}
return TRUE;
return get_signature(this, data, NULL);
}
METHOD(signer_t, verify_signature, bool,
@@ -137,7 +134,10 @@ METHOD(signer_t, verify_signature, bool,
{
return FALSE;
}
get_signature(this, data, sig);
if (!get_signature(this, data, sig))
{
return FALSE;
}
return memeq(signature.ptr, sig, signature.len);
}