signers implemented with HMAC now support NULL output parameters

to feed signer with more than one block of data.
This commit is contained in:
Martin Willi
2007-08-29 07:52:49 +00:00
parent ef5f65626f
commit dc5a849bf0
2 changed files with 34 additions and 17 deletions
+25 -14
View File
@@ -52,14 +52,19 @@ struct private_hmac_signer_t {
/** /**
* Implementation of signer_t.get_signature. * Implementation of signer_t.get_signature.
*/ */
static void get_signature (private_hmac_signer_t *this, chunk_t data, u_int8_t *buffer) static void get_signature(private_hmac_signer_t *this, chunk_t data, u_int8_t *buffer)
{ {
u_int8_t full_mac[this->hmac_prf->get_block_size(this->hmac_prf)]; if (buffer == NULL)
{ /* append mode */
this->hmac_prf->get_bytes(this->hmac_prf, data, NULL);
}
else
{
u_int8_t full_mac[this->hmac_prf->get_block_size(this->hmac_prf)];
this->hmac_prf->get_bytes(this->hmac_prf, data, full_mac); this->hmac_prf->get_bytes(this->hmac_prf, data, full_mac);
memcpy(buffer, full_mac, this->block_size);
/* copy MAC depending on truncation */ }
memcpy(buffer, full_mac, this->block_size);
} }
/** /**
@@ -67,18 +72,24 @@ static void get_signature (private_hmac_signer_t *this, chunk_t data, u_int8_t *
*/ */
static void allocate_signature (private_hmac_signer_t *this, chunk_t data, chunk_t *chunk) static void allocate_signature (private_hmac_signer_t *this, chunk_t data, chunk_t *chunk)
{ {
chunk_t signature; if (chunk == NULL)
u_int8_t full_mac[this->hmac_prf->get_block_size(this->hmac_prf)]; { /* append mode */
this->hmac_prf->get_bytes(this->hmac_prf, data, NULL);
}
else
{
chunk_t signature;
u_int8_t full_mac[this->hmac_prf->get_block_size(this->hmac_prf)];
this->hmac_prf->get_bytes(this->hmac_prf,data,full_mac); this->hmac_prf->get_bytes(this->hmac_prf, data, full_mac);
signature.ptr = malloc(this->block_size); signature.ptr = malloc(this->block_size);
signature.len = this->block_size; signature.len = this->block_size;
/* copy signature */ memcpy(signature.ptr, full_mac, this->block_size);
memcpy(signature.ptr, full_mac, this->block_size);
*chunk = signature; *chunk = signature;
}
} }
/** /**
@@ -75,6 +75,9 @@ struct signer_t {
/** /**
* @brief Generate a signature. * @brief Generate a signature.
* *
* If buffer is NULL, data is processed and prepended to a next call until
* buffer is a valid pointer.
*
* @param this calling object * @param this calling object
* @param data a chunk containing the data to sign * @param data a chunk containing the data to sign
* @param[out] buffer pointer where the signature will be written * @param[out] buffer pointer where the signature will be written
@@ -84,6 +87,9 @@ struct signer_t {
/** /**
* @brief Generate a signature and allocate space for it. * @brief Generate a signature and allocate space for it.
* *
* If chunk is NULL, data is processed and prepended to a next call until
* chunk is a valid chunk pointer.
*
* @param this calling object * @param this calling object
* @param data a chunk containing the data to sign * @param data a chunk containing the data to sign
* @param[out] chunk chunk which will hold the allocated signature * @param[out] chunk chunk which will hold the allocated signature