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/hashers/hasher.h crypto/hashers/hasher.c \
-crypto/hmacs/hmac.h \
-crypto/hmacs/hmac_prf.h crypto/hmacs/hmac_prf.c \
-crypto/hmacs/hmac_signer.h crypto/hmacs/hmac_signer.c \
+crypto/mac.h \
crypto/pkcs7.c crypto/pkcs7.h \
crypto/pkcs9.c crypto/pkcs9.h \
crypto/proposal/proposal_keywords.c crypto/proposal/proposal_keywords.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/nonce_gen.h \
crypto/prf_plus.h crypto/prf_plus.c \
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_tester.c crypto/crypto_tester.h \
crypto/diffie_hellman.c crypto/diffie_hellman.h \
*/
/**
- * @defgroup hmac hmac
+ * @defgroup mac mac
* @{ @ingroup crypto
*/
-#ifndef HMAC_H_
-#define HMAC_H_
+#ifndef MAC_H_
+#define MAC_H_
-typedef struct hmac_t hmac_t;
+typedef struct mac_t mac_t;
#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.
*/
-struct hmac_t {
+struct mac_t {
/**
* Generate message authentication code.
* @param data chunk of data to authenticate
* @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
- * underlying hash function).
+ * Get the size of the resulting MAC.
*
* @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.
*
* @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_ @}*/
* for more details.
*/
-#include "hmac_prf.h"
+#include "mac_prf.h"
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 {
prf_t public;
/**
- * HMAC to use
+ * MAC to use
*/
- hmac_t *hmac;
+ mac_t *mac;
};
METHOD(prf_t, get_bytes, void,
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,
{
if (!chunk)
{
- this->hmac->get_mac(this->hmac, seed, NULL);
+ this->mac->get_mac(this->mac, seed, NULL);
}
else
{
- *chunk = chunk_alloc(this->hmac->get_mac_size(this->hmac));
- this->hmac->get_mac(this->hmac, seed, chunk->ptr);
+ *chunk = chunk_alloc(this->mac->get_mac_size(this->mac));
+ this->mac->get_mac(this->mac, seed, chunk->ptr);
}
}
METHOD(prf_t, get_block_size, size_t,
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,
private_prf_t *this)
{
- /* for HMAC PRFs, IKEv2 uses MAC size as key size */
- return this->hmac->get_mac_size(this->hmac);
+ /* IKEv2 uses MAC size as key size */
+ return this->mac->get_mac_size(this->mac);
}
METHOD(prf_t, set_key, void,
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,
private_prf_t *this)
{
- this->hmac->destroy(this->hmac);
+ this->mac->destroy(this->mac);
free(this);
}
/*
* Described in header.
*/
-prf_t *hmac_prf_create(hmac_t *hmac)
+prf_t *mac_prf_create(mac_t *mac)
{
private_prf_t *this;
.set_key = _set_key,
.destroy = _destroy,
},
- .hmac = hmac,
+ .mac = mac,
);
return &this->public;
*/
/**
- * @defgroup hmac_prf hmac_prf
- * @{ @ingroup hmac
+ * @defgroup mac_prf mac_prf
+ * @{ @ingroup crypto
*/
-#ifndef HMAC_PRF_H_
-#define HMAC_PRF_H_
+#ifndef MAC_PRF_H_
+#define MAC_PRF_H_
+#include <crypto/mac.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.
*
- * @param hmac hmac_t implementation
+ * @param mac mac_t implementation
* @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_ @}*/
* for more details.
*/
-#include "hmac_signer.h"
+#include "mac_signer.h"
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 {
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;
};
{
if (buffer == NULL)
{
- this->hmac->get_mac(this->hmac, data, NULL);
+ this->mac->get_mac(this->mac, data, NULL);
}
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);
}
}
{
if (chunk == NULL)
{
- this->hmac->get_mac(this->hmac, data, NULL);
+ this->mac->get_mac(this->mac, data, NULL);
}
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);
memcpy(chunk->ptr, mac, this->truncation);
METHOD(signer_t, verify_signature, bool,
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)
{
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);
}
METHOD(signer_t, get_key_size, size_t,
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, set_key, void,
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,
private_signer_t *this)
{
- this->hmac->destroy(this->hmac);
+ this->mac->destroy(this->mac);
free(this);
}
/*
* 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;
.set_key = _set_key,
.destroy = _destroy,
},
- .truncation = min(len, hmac->get_mac_size(hmac)),
- .hmac = hmac,
+ .truncation = min(len, mac->get_mac_size(mac)),
+ .mac = mac,
);
return &this->public;
*/
/**
- * @defgroup hmac_signer hmac_signer
- * @{ @ingroup hmac
+ * @defgroup mac_signer mac_signer
+ * @{ @ingroup crypto
*/
-#ifndef HMAC_SIGNER_H_
-#define HMAC_SIGNER_H_
+#ifndef MAC_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>
/**
- * 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.
*
- * @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
- * @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_ @}*/
endif
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
* for more details.
*/
-#include "hmac_hmac.h"
+#include "hmac.h"
-#include <crypto/hmacs/hmac.h>
-#include <crypto/hmacs/hmac_prf.h>
-#include <crypto/hmacs/hmac_signer.h>
+#include <crypto/mac.h>
+#include <crypto/prfs/mac_prf.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.
*/
-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.
chunk_t ipaded_key;
};
-METHOD(hmac_t, get_mac, void,
- private_hmac_t *this, chunk_t data, u_int8_t *out)
+METHOD(mac_t, get_mac, void,
+ private_mac_t *this, chunk_t data, u_int8_t *out)
{
/* H(K XOR opad, H(K XOR ipad, text))
*
}
}
-METHOD(hmac_t, get_mac_size, size_t,
- private_hmac_t *this)
+METHOD(mac_t, get_mac_size, size_t,
+ private_mac_t *this)
{
return this->h->get_hash_size(this->h);
}
-METHOD(hmac_t, set_key, void,
- private_hmac_t *this, chunk_t key)
+METHOD(mac_t, set_key, void,
+ private_mac_t *this, chunk_t key)
{
int i;
u_int8_t buffer[this->b];
this->h->get_hash(this->h, this->ipaded_key, NULL);
}
-METHOD(hmac_t, destroy, void,
- private_hmac_t *this)
+METHOD(mac_t, destroy, void,
+ private_mac_t *this)
{
this->h->destroy(this->h);
chunk_clear(&this->opaded_key);
}
/*
- * 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,
.public = {
/*
* 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));
if (hmac)
{
- return hmac_prf_create(hmac);
+ return mac_prf_create(hmac);
}
return NULL;
}
/*
* 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;
hmac = hmac_create(hasher_algorithm_from_integrity(algo, &trunc));
if (hmac)
{
- return hmac_signer_create(hmac, trunc);
+ return mac_signer_create(hmac, trunc);
}
return NULL;
}
*
* 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
*/
-#ifndef HMAC_HMAC_H_
-#define HMAC_HMAC_H_
+#ifndef HMAC_H_
+#define HMAC_H_
#include <crypto/prfs/prf.h>
#include <crypto/signers/signer.h>
* @param algo algorithm to implement
* @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.
* @param algo algorithm to implement
* @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_ @}*/
#include "hmac_plugin.h"
#include <library.h>
-#include "hmac_hmac.h"
+#include "hmac.h"
typedef struct private_hmac_plugin_t private_hmac_plugin_t;
private_hmac_plugin_t *this, plugin_feature_t *features[])
{
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_DEPENDS(HASHER, HASH_SHA1),
PLUGIN_PROVIDE(PRF, PRF_HMAC_MD5),
PLUGIN_DEPENDS(HASHER, HASH_SHA384),
PLUGIN_PROVIDE(PRF, PRF_HMAC_SHA2_512),
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_DEPENDS(HASHER, HASH_SHA1),
PLUGIN_PROVIDE(SIGNER, AUTH_HMAC_SHA1_128),
#include "openssl_hmac.h"
-#include <crypto/hmacs/hmac.h>
-#include <crypto/hmacs/hmac_prf.h>
-#include <crypto/hmacs/hmac_signer.h>
+#include <crypto/mac.h>
+#include <crypto/prfs/mac_prf.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
*/
- hmac_t public;
+ mac_t public;
/**
* Hasher to use
/**
* 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);
}
-METHOD(hmac_t, get_mac, void,
- private_hmac_t *this, chunk_t data, u_int8_t *out)
+METHOD(mac_t, get_mac, void,
+ private_mac_t *this, chunk_t data, u_int8_t *out)
{
if (out == NULL)
{
}
}
-METHOD(hmac_t, get_mac_size, size_t,
- private_hmac_t *this)
+METHOD(mac_t, get_mac_size, size_t,
+ private_mac_t *this)
{
return EVP_MD_size(this->hasher);
}
-METHOD(hmac_t, set_key, void,
- private_hmac_t *this, chunk_t key)
+METHOD(mac_t, set_key, void,
+ private_mac_t *this, chunk_t key)
{
chunk_clear(&this->key);
this->key = chunk_clone(key);
reset(this);
}
-METHOD(hmac_t, destroy, void,
- private_hmac_t *this)
+METHOD(mac_t, destroy, void,
+ private_mac_t *this)
{
HMAC_CTX_cleanup(&this->hmac);
chunk_clear(&this->key);
}
/*
- * 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,
.public = {
*/
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));
if (hmac)
{
- return hmac_prf_create(hmac);
+ return mac_prf_create(hmac);
}
return NULL;
}
*/
signer_t *openssl_hmac_signer_create(integrity_algorithm_t algo)
{
- hmac_t *hmac;
+ mac_t *hmac;
size_t trunc;
hmac = hmac_create(hasher_algorithm_from_integrity(algo, &trunc));
if (hmac)
{
- return hmac_signer_create(hmac, trunc);
+ return mac_signer_create(hmac, trunc);
}
return NULL;
}