Make the hmac_t interface a generic interface for message authentication codes

This commit is contained in:
Tobias Brunner
2012-06-25 16:35:06 +02:00
parent 228d096e42
commit c4a3c9672a
11 changed files with 131 additions and 132 deletions
+3 -3
View File
@@ -13,17 +13,17 @@ asn1/oid.c asn1/oid.h \
bio/bio_reader.h bio/bio_reader.c bio/bio_writer.h bio/bio_writer.c \ bio/bio_reader.h bio/bio_reader.c bio/bio_writer.h bio/bio_writer.c \
crypto/crypters/crypter.c crypto/crypters/crypter.h \ crypto/crypters/crypter.c crypto/crypters/crypter.h \
crypto/hashers/hasher.h crypto/hashers/hasher.c \ crypto/hashers/hasher.h crypto/hashers/hasher.c \
crypto/hmacs/hmac.h \ crypto/mac.h \
crypto/hmacs/hmac_prf.h crypto/hmacs/hmac_prf.c \
crypto/hmacs/hmac_signer.h crypto/hmacs/hmac_signer.c \
crypto/pkcs7.c crypto/pkcs7.h \ crypto/pkcs7.c crypto/pkcs7.h \
crypto/pkcs9.c crypto/pkcs9.h \ crypto/pkcs9.c crypto/pkcs9.h \
crypto/proposal/proposal_keywords.c crypto/proposal/proposal_keywords.h \ crypto/proposal/proposal_keywords.c crypto/proposal/proposal_keywords.h \
crypto/prfs/prf.c crypto/prfs/prf.h \ crypto/prfs/prf.c crypto/prfs/prf.h \
crypto/prfs/mac_prf.h crypto/prfs/mac_prf.c \
crypto/rngs/rng.c crypto/rngs/rng.h \ crypto/rngs/rng.c crypto/rngs/rng.h \
crypto/nonce_gen.h \ crypto/nonce_gen.h \
crypto/prf_plus.h crypto/prf_plus.c \ crypto/prf_plus.h crypto/prf_plus.c \
crypto/signers/signer.c crypto/signers/signer.h \ crypto/signers/signer.c crypto/signers/signer.h \
crypto/signers/mac_signer.h crypto/signers/mac_signer.c \
crypto/crypto_factory.c crypto/crypto_factory.h \ crypto/crypto_factory.c crypto/crypto_factory.h \
crypto/crypto_tester.c crypto/crypto_tester.h \ crypto/crypto_tester.c crypto/crypto_tester.h \
crypto/diffie_hellman.c crypto/diffie_hellman.h \ crypto/diffie_hellman.c crypto/diffie_hellman.h \
@@ -16,23 +16,23 @@
*/ */
/** /**
* @defgroup hmac hmac * @defgroup mac mac
* @{ @ingroup crypto * @{ @ingroup crypto
*/ */
#ifndef HMAC_H_ #ifndef MAC_H_
#define HMAC_H_ #define MAC_H_
typedef struct hmac_t hmac_t; typedef struct mac_t mac_t;
#include <library.h> #include <library.h>
/** /**
* Generic interface for message authentication using hash functions. * Generic interface for message authentication codes.
* *
* Classes implementing this interface can use the PRF and signer wrappers. * Classes implementing this interface can use the PRF and signer wrappers.
*/ */
struct hmac_t { struct mac_t {
/** /**
* Generate message authentication code. * Generate message authentication code.
@@ -45,29 +45,28 @@ struct hmac_t {
* @param data chunk of data to authenticate * @param data chunk of data to authenticate
* @param out pointer where the generated bytes will be written * @param out pointer where the generated bytes will be written
*/ */
void (*get_mac)(hmac_t *this, chunk_t data, u_int8_t *out); void (*get_mac)(mac_t *this, chunk_t data, u_int8_t *out);
/** /**
* Get the size of the resulting MAC (i.e. the output size of the * Get the size of the resulting MAC.
* underlying hash function).
* *
* @return block size in bytes * @return block size in bytes
*/ */
size_t (*get_mac_size)(hmac_t *this); size_t (*get_mac_size)(mac_t *this);
/** /**
* Set the key to be used for the HMAC. * Set the key to be used for the MAC.
* *
* Any key length must be accepted. * Any key length must be accepted.
* *
* @param key key to set * @param key key to set
*/ */
void (*set_key) (hmac_t *this, chunk_t key); void (*set_key) (mac_t *this, chunk_t key);
/** /**
* Destroys a hmac_t object. * Destroys a mac_t object.
*/ */
void (*destroy) (hmac_t *this); void (*destroy) (mac_t *this);
}; };
#endif /** HMAC_H_ @}*/ #endif /** MAC_H_ @}*/
@@ -15,12 +15,12 @@
* for more details. * for more details.
*/ */
#include "hmac_prf.h" #include "mac_prf.h"
typedef struct private_prf_t private_prf_t; typedef struct private_prf_t private_prf_t;
/** /**
* Private data of a hmac_prf_t object. * Private data of a mac_prf_t object.
*/ */
struct private_prf_t { struct private_prf_t {
@@ -30,15 +30,15 @@ struct private_prf_t {
prf_t public; prf_t public;
/** /**
* HMAC to use * MAC to use
*/ */
hmac_t *hmac; mac_t *mac;
}; };
METHOD(prf_t, get_bytes, void, METHOD(prf_t, get_bytes, void,
private_prf_t *this, chunk_t seed, u_int8_t *buffer) private_prf_t *this, chunk_t seed, u_int8_t *buffer)
{ {
this->hmac->get_mac(this->hmac, seed, buffer); this->mac->get_mac(this->mac, seed, buffer);
} }
METHOD(prf_t, allocate_bytes, void, METHOD(prf_t, allocate_bytes, void,
@@ -46,45 +46,45 @@ METHOD(prf_t, allocate_bytes, void,
{ {
if (!chunk) if (!chunk)
{ {
this->hmac->get_mac(this->hmac, seed, NULL); this->mac->get_mac(this->mac, seed, NULL);
} }
else else
{ {
*chunk = chunk_alloc(this->hmac->get_mac_size(this->hmac)); *chunk = chunk_alloc(this->mac->get_mac_size(this->mac));
this->hmac->get_mac(this->hmac, seed, chunk->ptr); this->mac->get_mac(this->mac, seed, chunk->ptr);
} }
} }
METHOD(prf_t, get_block_size, size_t, METHOD(prf_t, get_block_size, size_t,
private_prf_t *this) private_prf_t *this)
{ {
return this->hmac->get_mac_size(this->hmac); return this->mac->get_mac_size(this->mac);
} }
METHOD(prf_t, get_key_size, size_t, METHOD(prf_t, get_key_size, size_t,
private_prf_t *this) private_prf_t *this)
{ {
/* for HMAC PRFs, IKEv2 uses MAC size as key size */ /* IKEv2 uses MAC size as key size */
return this->hmac->get_mac_size(this->hmac); return this->mac->get_mac_size(this->mac);
} }
METHOD(prf_t, set_key, void, METHOD(prf_t, set_key, void,
private_prf_t *this, chunk_t key) private_prf_t *this, chunk_t key)
{ {
this->hmac->set_key(this->hmac, key); this->mac->set_key(this->mac, key);
} }
METHOD(prf_t, destroy, void, METHOD(prf_t, destroy, void,
private_prf_t *this) private_prf_t *this)
{ {
this->hmac->destroy(this->hmac); this->mac->destroy(this->mac);
free(this); free(this);
} }
/* /*
* Described in header. * Described in header.
*/ */
prf_t *hmac_prf_create(hmac_t *hmac) prf_t *mac_prf_create(mac_t *mac)
{ {
private_prf_t *this; private_prf_t *this;
@@ -97,7 +97,7 @@ prf_t *hmac_prf_create(hmac_t *hmac)
.set_key = _set_key, .set_key = _set_key,
.destroy = _destroy, .destroy = _destroy,
}, },
.hmac = hmac, .mac = mac,
); );
return &this->public; return &this->public;
@@ -14,23 +14,23 @@
*/ */
/** /**
* @defgroup hmac_prf hmac_prf * @defgroup mac_prf mac_prf
* @{ @ingroup hmac * @{ @ingroup crypto
*/ */
#ifndef HMAC_PRF_H_ #ifndef MAC_PRF_H_
#define HMAC_PRF_H_ #define MAC_PRF_H_
#include <crypto/mac.h>
#include <crypto/prfs/prf.h> #include <crypto/prfs/prf.h>
#include <crypto/hmacs/hmac.h>
/** /**
* Creates an implementation of the prf_t interface using the provided hmac_t * Creates an implementation of the prf_t interface using the provided mac_t
* implementation. Basically a simple wrapper to map the interface. * implementation. Basically a simple wrapper to map the interface.
* *
* @param hmac hmac_t implementation * @param mac mac_t implementation
* @return prf_t object * @return prf_t object
*/ */
prf_t *hmac_prf_create(hmac_t *hmac); prf_t *mac_prf_create(mac_t *mac);
#endif /** HMAC_PRF_H_ @}*/ #endif /** MAC_PRF_H_ @}*/
@@ -15,12 +15,12 @@
* for more details. * for more details.
*/ */
#include "hmac_signer.h" #include "mac_signer.h"
typedef struct private_signer_t private_signer_t; typedef struct private_signer_t private_signer_t;
/** /**
* Private data of a hmac_signer_t object. * Private data of a mac_signer_t object.
*/ */
struct private_signer_t { struct private_signer_t {
@@ -30,12 +30,12 @@ struct private_signer_t {
signer_t public; signer_t public;
/** /**
* HMAC to use * MAC to use
*/ */
hmac_t *hmac; mac_t *mac;
/** /**
* Truncation of HMAC output * Truncation of MAC output
*/ */
size_t truncation; size_t truncation;
}; };
@@ -45,13 +45,13 @@ METHOD(signer_t, get_signature, void,
{ {
if (buffer == NULL) if (buffer == NULL)
{ {
this->hmac->get_mac(this->hmac, data, NULL); this->mac->get_mac(this->mac, data, NULL);
} }
else else
{ {
u_int8_t mac[this->hmac->get_mac_size(this->hmac)]; u_int8_t mac[this->mac->get_mac_size(this->mac)];
this->hmac->get_mac(this->hmac, data, mac); this->mac->get_mac(this->mac, data, mac);
memcpy(buffer, mac, this->truncation); memcpy(buffer, mac, this->truncation);
} }
} }
@@ -61,13 +61,13 @@ METHOD(signer_t, allocate_signature, void,
{ {
if (chunk == NULL) if (chunk == NULL)
{ {
this->hmac->get_mac(this->hmac, data, NULL); this->mac->get_mac(this->mac, data, NULL);
} }
else else
{ {
u_int8_t mac[this->hmac->get_mac_size(this->hmac)]; u_int8_t mac[this->mac->get_mac_size(this->mac)];
this->hmac->get_mac(this->hmac, data, mac); this->mac->get_mac(this->mac, data, mac);
*chunk = chunk_alloc(this->truncation); *chunk = chunk_alloc(this->truncation);
memcpy(chunk->ptr, mac, this->truncation); memcpy(chunk->ptr, mac, this->truncation);
@@ -77,20 +77,20 @@ METHOD(signer_t, allocate_signature, void,
METHOD(signer_t, verify_signature, bool, METHOD(signer_t, verify_signature, bool,
private_signer_t *this, chunk_t data, chunk_t signature) private_signer_t *this, chunk_t data, chunk_t signature)
{ {
u_int8_t mac[this->hmac->get_mac_size(this->hmac)]; u_int8_t mac[this->mac->get_mac_size(this->mac)];
if (signature.len != this->truncation) if (signature.len != this->truncation)
{ {
return FALSE; return FALSE;
} }
this->hmac->get_mac(this->hmac, data, mac); this->mac->get_mac(this->mac, data, mac);
return memeq(signature.ptr, mac, this->truncation); return memeq(signature.ptr, mac, this->truncation);
} }
METHOD(signer_t, get_key_size, size_t, METHOD(signer_t, get_key_size, size_t,
private_signer_t *this) private_signer_t *this)
{ {
return this->hmac->get_mac_size(this->hmac); return this->mac->get_mac_size(this->mac);
} }
METHOD(signer_t, get_block_size, size_t, METHOD(signer_t, get_block_size, size_t,
@@ -102,20 +102,20 @@ METHOD(signer_t, get_block_size, size_t,
METHOD(signer_t, set_key, void, METHOD(signer_t, set_key, void,
private_signer_t *this, chunk_t key) private_signer_t *this, chunk_t key)
{ {
this->hmac->set_key(this->hmac, key); this->mac->set_key(this->mac, key);
} }
METHOD(signer_t, destroy, void, METHOD(signer_t, destroy, void,
private_signer_t *this) private_signer_t *this)
{ {
this->hmac->destroy(this->hmac); this->mac->destroy(this->mac);
free(this); free(this);
} }
/* /*
* Described in header * Described in header
*/ */
signer_t *hmac_signer_create(hmac_t *hmac, size_t len) signer_t *mac_signer_create(mac_t *mac, size_t len)
{ {
private_signer_t *this; private_signer_t *this;
@@ -129,8 +129,8 @@ signer_t *hmac_signer_create(hmac_t *hmac, size_t len)
.set_key = _set_key, .set_key = _set_key,
.destroy = _destroy, .destroy = _destroy,
}, },
.truncation = min(len, hmac->get_mac_size(hmac)), .truncation = min(len, mac->get_mac_size(mac)),
.hmac = hmac, .mac = mac,
); );
return &this->public; return &this->public;
@@ -14,28 +14,28 @@
*/ */
/** /**
* @defgroup hmac_signer hmac_signer * @defgroup mac_signer mac_signer
* @{ @ingroup hmac * @{ @ingroup crypto
*/ */
#ifndef HMAC_SIGNER_H_ #ifndef MAC_SIGNER_H_
#define HMAC_SIGNER_H_ #define MAC_SIGNER_H_
typedef struct hmac_signer_t hmac_signer_t; typedef struct mac_signer_t mac_signer_t;
#include <crypto/hmacs/hmac.h> #include <crypto/mac.h>
#include <crypto/signers/signer.h> #include <crypto/signers/signer.h>
/** /**
* Creates an implementation of the signer_t interface using the provided hmac_t * Creates an implementation of the signer_t interface using the provided mac_t
* implementation and truncation length. * implementation and truncation length.
* *
* @note len will be set to hmac_t.get_mac_size() if it is greater than that. * @note len will be set to mac_t.get_mac_size() if it is greater than that.
* *
* @param hmac hmac_t implementation * @param mac mac_t implementation
* @param len length of resulting signature * @param len length of resulting signature
* @return hmac_signer_t * @return mac_signer_t
*/ */
signer_t *hmac_signer_create(hmac_t *hmac, size_t len); signer_t *mac_signer_create(mac_t *mac, size_t len);
#endif /** HMAC_SIGNER_H_ @}*/ #endif /** MAC_SIGNER_H_ @}*/
+1 -1
View File
@@ -10,6 +10,6 @@ plugin_LTLIBRARIES = libstrongswan-hmac.la
endif endif
libstrongswan_hmac_la_SOURCES = \ libstrongswan_hmac_la_SOURCES = \
hmac_plugin.h hmac_plugin.c hmac_hmac.h hmac_hmac.c hmac_plugin.h hmac_plugin.c hmac.h hmac.c
libstrongswan_hmac_la_LDFLAGS = -module -avoid-version libstrongswan_hmac_la_LDFLAGS = -module -avoid-version
@@ -15,25 +15,25 @@
* for more details. * for more details.
*/ */
#include "hmac_hmac.h" #include "hmac.h"
#include <crypto/hmacs/hmac.h> #include <crypto/mac.h>
#include <crypto/hmacs/hmac_prf.h> #include <crypto/prfs/mac_prf.h>
#include <crypto/hmacs/hmac_signer.h> #include <crypto/signers/mac_signer.h>
typedef struct private_hmac_t private_hmac_t; typedef struct private_mac_t private_mac_t;
/** /**
* Private data of a hmac_hmac_t object. * Private data of a mac_t object.
* *
* The variable names are the same as in the RFC. * The variable names are the same as in the RFC.
*/ */
struct private_hmac_t { struct private_mac_t {
/** /**
* Implements hmac_t interface * Implements mac_t interface
*/ */
hmac_t public; mac_t public;
/** /**
* Block size, as in RFC. * Block size, as in RFC.
@@ -56,8 +56,8 @@ struct private_hmac_t {
chunk_t ipaded_key; chunk_t ipaded_key;
}; };
METHOD(hmac_t, get_mac, void, METHOD(mac_t, get_mac, void,
private_hmac_t *this, chunk_t data, u_int8_t *out) private_mac_t *this, chunk_t data, u_int8_t *out)
{ {
/* H(K XOR opad, H(K XOR ipad, text)) /* H(K XOR opad, H(K XOR ipad, text))
* *
@@ -92,14 +92,14 @@ METHOD(hmac_t, get_mac, void,
} }
} }
METHOD(hmac_t, get_mac_size, size_t, METHOD(mac_t, get_mac_size, size_t,
private_hmac_t *this) private_mac_t *this)
{ {
return this->h->get_hash_size(this->h); return this->h->get_hash_size(this->h);
} }
METHOD(hmac_t, set_key, void, METHOD(mac_t, set_key, void,
private_hmac_t *this, chunk_t key) private_mac_t *this, chunk_t key)
{ {
int i; int i;
u_int8_t buffer[this->b]; u_int8_t buffer[this->b];
@@ -129,8 +129,8 @@ METHOD(hmac_t, set_key, void,
this->h->get_hash(this->h, this->ipaded_key, NULL); this->h->get_hash(this->h, this->ipaded_key, NULL);
} }
METHOD(hmac_t, destroy, void, METHOD(mac_t, destroy, void,
private_hmac_t *this) private_mac_t *this)
{ {
this->h->destroy(this->h); this->h->destroy(this->h);
chunk_clear(&this->opaded_key); chunk_clear(&this->opaded_key);
@@ -139,11 +139,11 @@ METHOD(hmac_t, destroy, void,
} }
/* /*
* Creates an hmac_t object * Creates an mac_t object
*/ */
static hmac_t *hmac_create(hash_algorithm_t hash_algorithm) static mac_t *hmac_create(hash_algorithm_t hash_algorithm)
{ {
private_hmac_t *this; private_mac_t *this;
INIT(this, INIT(this,
.public = { .public = {
@@ -191,14 +191,14 @@ static hmac_t *hmac_create(hash_algorithm_t hash_algorithm)
/* /*
* Described in header * Described in header
*/ */
prf_t *hmac_hmac_prf_create(pseudo_random_function_t algo) prf_t *hmac_prf_create(pseudo_random_function_t algo)
{ {
hmac_t *hmac; mac_t *hmac;
hmac = hmac_create(hasher_algorithm_from_prf(algo)); hmac = hmac_create(hasher_algorithm_from_prf(algo));
if (hmac) if (hmac)
{ {
return hmac_prf_create(hmac); return mac_prf_create(hmac);
} }
return NULL; return NULL;
} }
@@ -206,15 +206,15 @@ prf_t *hmac_hmac_prf_create(pseudo_random_function_t algo)
/* /*
* Described in header * Described in header
*/ */
signer_t *hmac_hmac_signer_create(integrity_algorithm_t algo) signer_t *hmac_signer_create(integrity_algorithm_t algo)
{ {
hmac_t *hmac; mac_t *hmac;
size_t trunc; size_t trunc;
hmac = hmac_create(hasher_algorithm_from_integrity(algo, &trunc)); hmac = hmac_create(hasher_algorithm_from_integrity(algo, &trunc));
if (hmac) if (hmac)
{ {
return hmac_signer_create(hmac, trunc); return mac_signer_create(hmac, trunc);
} }
return NULL; return NULL;
} }
@@ -18,12 +18,12 @@
* *
* It uses a hash function, which must be implemented as a hasher_t class. * It uses a hash function, which must be implemented as a hasher_t class.
* *
* @defgroup hmac_hmac hmac * @defgroup hmac_mac mac
* @{ @ingroup hmac_p * @{ @ingroup hmac_p
*/ */
#ifndef HMAC_HMAC_H_ #ifndef HMAC_H_
#define HMAC_HMAC_H_ #define HMAC_H_
#include <crypto/prfs/prf.h> #include <crypto/prfs/prf.h>
#include <crypto/signers/signer.h> #include <crypto/signers/signer.h>
@@ -34,7 +34,7 @@
* @param algo algorithm to implement * @param algo algorithm to implement
* @return prf_t object, NULL if not supported * @return prf_t object, NULL if not supported
*/ */
prf_t *hmac_hmac_prf_create(pseudo_random_function_t algo); prf_t *hmac_prf_create(pseudo_random_function_t algo);
/** /**
* Creates a new signer_t object based on an HMAC. * Creates a new signer_t object based on an HMAC.
@@ -42,6 +42,6 @@ prf_t *hmac_hmac_prf_create(pseudo_random_function_t algo);
* @param algo algorithm to implement * @param algo algorithm to implement
* @return signer_t, NULL if not supported * @return signer_t, NULL if not supported
*/ */
signer_t *hmac_hmac_signer_create(integrity_algorithm_t algo); signer_t *hmac_signer_create(integrity_algorithm_t algo);
#endif /** HMAC_HMAC_H_ @}*/ #endif /** HMAC_H_ @}*/
+3 -3
View File
@@ -16,7 +16,7 @@
#include "hmac_plugin.h" #include "hmac_plugin.h"
#include <library.h> #include <library.h>
#include "hmac_hmac.h" #include "hmac.h"
typedef struct private_hmac_plugin_t private_hmac_plugin_t; typedef struct private_hmac_plugin_t private_hmac_plugin_t;
@@ -41,7 +41,7 @@ METHOD(plugin_t, get_features, int,
private_hmac_plugin_t *this, plugin_feature_t *features[]) private_hmac_plugin_t *this, plugin_feature_t *features[])
{ {
static plugin_feature_t f[] = { static plugin_feature_t f[] = {
PLUGIN_REGISTER(PRF, hmac_hmac_prf_create), PLUGIN_REGISTER(PRF, hmac_prf_create),
PLUGIN_PROVIDE(PRF, PRF_HMAC_SHA1), PLUGIN_PROVIDE(PRF, PRF_HMAC_SHA1),
PLUGIN_DEPENDS(HASHER, HASH_SHA1), PLUGIN_DEPENDS(HASHER, HASH_SHA1),
PLUGIN_PROVIDE(PRF, PRF_HMAC_MD5), PLUGIN_PROVIDE(PRF, PRF_HMAC_MD5),
@@ -52,7 +52,7 @@ METHOD(plugin_t, get_features, int,
PLUGIN_DEPENDS(HASHER, HASH_SHA384), PLUGIN_DEPENDS(HASHER, HASH_SHA384),
PLUGIN_PROVIDE(PRF, PRF_HMAC_SHA2_512), PLUGIN_PROVIDE(PRF, PRF_HMAC_SHA2_512),
PLUGIN_DEPENDS(HASHER, HASH_SHA512), PLUGIN_DEPENDS(HASHER, HASH_SHA512),
PLUGIN_REGISTER(SIGNER, hmac_hmac_signer_create), PLUGIN_REGISTER(SIGNER, hmac_signer_create),
PLUGIN_PROVIDE(SIGNER, AUTH_HMAC_SHA1_96), PLUGIN_PROVIDE(SIGNER, AUTH_HMAC_SHA1_96),
PLUGIN_DEPENDS(HASHER, HASH_SHA1), PLUGIN_DEPENDS(HASHER, HASH_SHA1),
PLUGIN_PROVIDE(SIGNER, AUTH_HMAC_SHA1_128), PLUGIN_PROVIDE(SIGNER, AUTH_HMAC_SHA1_128),
@@ -40,21 +40,21 @@
#include "openssl_hmac.h" #include "openssl_hmac.h"
#include <crypto/hmacs/hmac.h> #include <crypto/mac.h>
#include <crypto/hmacs/hmac_prf.h> #include <crypto/prfs/mac_prf.h>
#include <crypto/hmacs/hmac_signer.h> #include <crypto/signers/mac_signer.h>
typedef struct private_hmac_t private_hmac_t; typedef struct private_mac_t private_mac_t;
/** /**
* Private data of a hmac_t object. * Private data of a mac_t object.
*/ */
struct private_hmac_t { struct private_mac_t {
/** /**
* Public interface * Public interface
*/ */
hmac_t public; mac_t public;
/** /**
* Hasher to use * Hasher to use
@@ -75,13 +75,13 @@ struct private_hmac_t {
/** /**
* Resets HMAC context * Resets HMAC context
*/ */
static void reset(private_hmac_t *this) static void reset(private_mac_t *this)
{ {
HMAC_Init_ex(&this->hmac, this->key.ptr, this->key.len, this->hasher, NULL); HMAC_Init_ex(&this->hmac, this->key.ptr, this->key.len, this->hasher, NULL);
} }
METHOD(hmac_t, get_mac, void, METHOD(mac_t, get_mac, void,
private_hmac_t *this, chunk_t data, u_int8_t *out) private_mac_t *this, chunk_t data, u_int8_t *out)
{ {
if (out == NULL) if (out == NULL)
{ {
@@ -95,22 +95,22 @@ METHOD(hmac_t, get_mac, void,
} }
} }
METHOD(hmac_t, get_mac_size, size_t, METHOD(mac_t, get_mac_size, size_t,
private_hmac_t *this) private_mac_t *this)
{ {
return EVP_MD_size(this->hasher); return EVP_MD_size(this->hasher);
} }
METHOD(hmac_t, set_key, void, METHOD(mac_t, set_key, void,
private_hmac_t *this, chunk_t key) private_mac_t *this, chunk_t key)
{ {
chunk_clear(&this->key); chunk_clear(&this->key);
this->key = chunk_clone(key); this->key = chunk_clone(key);
reset(this); reset(this);
} }
METHOD(hmac_t, destroy, void, METHOD(mac_t, destroy, void,
private_hmac_t *this) private_mac_t *this)
{ {
HMAC_CTX_cleanup(&this->hmac); HMAC_CTX_cleanup(&this->hmac);
chunk_clear(&this->key); chunk_clear(&this->key);
@@ -118,11 +118,11 @@ METHOD(hmac_t, destroy, void,
} }
/* /*
* Create an OpenSSL-backed implementation of the hmac_t interface * Create an OpenSSL-backed implementation of the mac_t interface
*/ */
static hmac_t *hmac_create(hash_algorithm_t algo) static mac_t *hmac_create(hash_algorithm_t algo)
{ {
private_hmac_t *this; private_mac_t *this;
INIT(this, INIT(this,
.public = { .public = {
@@ -170,12 +170,12 @@ static hmac_t *hmac_create(hash_algorithm_t algo)
*/ */
prf_t *openssl_hmac_prf_create(pseudo_random_function_t algo) prf_t *openssl_hmac_prf_create(pseudo_random_function_t algo)
{ {
hmac_t *hmac; mac_t *hmac;
hmac = hmac_create(hasher_algorithm_from_prf(algo)); hmac = hmac_create(hasher_algorithm_from_prf(algo));
if (hmac) if (hmac)
{ {
return hmac_prf_create(hmac); return mac_prf_create(hmac);
} }
return NULL; return NULL;
} }
@@ -185,13 +185,13 @@ prf_t *openssl_hmac_prf_create(pseudo_random_function_t algo)
*/ */
signer_t *openssl_hmac_signer_create(integrity_algorithm_t algo) signer_t *openssl_hmac_signer_create(integrity_algorithm_t algo)
{ {
hmac_t *hmac; mac_t *hmac;
size_t trunc; size_t trunc;
hmac = hmac_create(hasher_algorithm_from_integrity(algo, &trunc)); hmac = hmac_create(hasher_algorithm_from_integrity(algo, &trunc));
if (hmac) if (hmac)
{ {
return hmac_signer_create(hmac, trunc); return mac_signer_create(hmac, trunc);
} }
return NULL; return NULL;
} }