Add features support to af_alg plugin
This commit is contained in:
@@ -61,7 +61,7 @@ static struct {
|
||||
/* size of the keying material (key + nonce for ctr mode) */
|
||||
size_t keymat_size;
|
||||
size_t iv_size;
|
||||
} algs[] = {
|
||||
} algs[AF_ALG_CRYPTER] = {
|
||||
{ENCR_DES, "cbc(des)", 8, 8, 8, 8, },
|
||||
{ENCR_DES_ECB, "ecb(des)", 8, 8, 8, 0, },
|
||||
{ENCR_3DES, "cbc(des3_ede)", 8, 24, 24, 8, },
|
||||
@@ -92,25 +92,20 @@ static struct {
|
||||
/**
|
||||
* See header.
|
||||
*/
|
||||
void af_alg_crypter_probe(char *plugin)
|
||||
void af_alg_crypter_probe(plugin_feature_t *features, int *pos)
|
||||
{
|
||||
encryption_algorithm_t prev = -1;
|
||||
af_alg_ops_t *ops;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < countof(algs); i++)
|
||||
{
|
||||
if (prev != algs[i].id)
|
||||
ops = af_alg_ops_create("skcipher", algs[i].name);
|
||||
if (ops)
|
||||
{
|
||||
ops = af_alg_ops_create("skcipher", algs[i].name);
|
||||
if (ops)
|
||||
{
|
||||
ops->destroy(ops);
|
||||
lib->crypto->add_crypter(lib->crypto, algs[i].id, plugin,
|
||||
(crypter_constructor_t)af_alg_crypter_create);
|
||||
}
|
||||
ops->destroy(ops);
|
||||
features[(*pos)++] = PLUGIN_PROVIDE(CRYPTER,
|
||||
algs[i].id, algs[i].key_size);
|
||||
}
|
||||
prev = algs[i].id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,12 @@
|
||||
|
||||
typedef struct af_alg_crypter_t af_alg_crypter_t;
|
||||
|
||||
#include <plugins/plugin.h>
|
||||
#include <crypto/crypters/crypter.h>
|
||||
|
||||
/** Number of crypters */
|
||||
#define AF_ALG_CRYPTER 25
|
||||
|
||||
/**
|
||||
* Implementation of signers using AF_ALG.
|
||||
*/
|
||||
@@ -47,10 +51,11 @@ af_alg_crypter_t *af_alg_crypter_create(encryption_algorithm_t algo,
|
||||
size_t key_size);
|
||||
|
||||
/**
|
||||
* Probe algorithms and register af_alg_crypter_create().
|
||||
* Probe algorithms and return plugin features.
|
||||
*
|
||||
* @param plugin plugin name to register algorithms for
|
||||
* @param features plugin features to create
|
||||
* @param pos current position in features
|
||||
*/
|
||||
void af_alg_crypter_probe(char *plugin);
|
||||
void af_alg_crypter_probe(plugin_feature_t *features, int *pos);
|
||||
|
||||
#endif /** AF_ALG_CRYPTER_H_ @}*/
|
||||
|
||||
@@ -46,7 +46,7 @@ static struct {
|
||||
hash_algorithm_t id;
|
||||
char *name;
|
||||
size_t size;
|
||||
} algs[] = {
|
||||
} algs[AF_ALG_HASHER] = {
|
||||
{HASH_SHA1, "sha1", HASH_SIZE_SHA1 },
|
||||
{HASH_MD5, "md5", HASH_SIZE_MD5 },
|
||||
{HASH_SHA224, "sha224", HASH_SIZE_SHA224 },
|
||||
@@ -59,7 +59,7 @@ static struct {
|
||||
/**
|
||||
* See header.
|
||||
*/
|
||||
void af_alg_hasher_probe(char *plugin)
|
||||
void af_alg_hasher_probe(plugin_feature_t *features, int *pos)
|
||||
{
|
||||
af_alg_ops_t *ops;
|
||||
int i;
|
||||
@@ -70,8 +70,7 @@ void af_alg_hasher_probe(char *plugin)
|
||||
if (ops)
|
||||
{
|
||||
ops->destroy(ops);
|
||||
lib->crypto->add_hasher(lib->crypto, algs[i].id, plugin,
|
||||
(hasher_constructor_t)af_alg_hasher_create);
|
||||
features[(*pos)++] = PLUGIN_PROVIDE(HASHER, algs[i].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,12 @@
|
||||
|
||||
typedef struct af_alg_hasher_t af_alg_hasher_t;
|
||||
|
||||
#include <plugins/plugin.h>
|
||||
#include <crypto/hashers/hasher.h>
|
||||
|
||||
/** Number of hashers */
|
||||
#define AF_ALG_HASHER 7
|
||||
|
||||
/**
|
||||
* Implementation of hashers using AF_ALG.
|
||||
*/
|
||||
@@ -45,10 +49,11 @@ struct af_alg_hasher_t {
|
||||
af_alg_hasher_t *af_alg_hasher_create(hash_algorithm_t algo);
|
||||
|
||||
/**
|
||||
* Probe algorithms and register af_alg_hasher_create().
|
||||
* Probe algorithms and return plugin features.
|
||||
*
|
||||
* @param plugin plugin name to register algorithms for
|
||||
* @param features plugin features to create
|
||||
* @param pos current position in deps
|
||||
*/
|
||||
void af_alg_hasher_probe(char *plugin);
|
||||
void af_alg_hasher_probe(plugin_feature_t *features, int *pos);
|
||||
|
||||
#endif /** af_alg_HASHER_H_ @}*/
|
||||
|
||||
@@ -41,18 +41,31 @@ METHOD(plugin_t, get_name, char*,
|
||||
return "af-alg";
|
||||
}
|
||||
|
||||
METHOD(plugin_t, get_features, int,
|
||||
private_af_alg_plugin_t *this, plugin_feature_t *features[])
|
||||
{
|
||||
static plugin_feature_t f[AF_ALG_HASHER + AF_ALG_SIGNER +
|
||||
AF_ALG_PRF + AF_ALG_CRYPTER + 4] = {};
|
||||
static int count = 0;
|
||||
|
||||
if (!count)
|
||||
{ /* initialize only once */
|
||||
f[count++] = PLUGIN_REGISTER(HASHER, af_alg_hasher_create);
|
||||
af_alg_hasher_probe(f, &count);
|
||||
f[count++] = PLUGIN_REGISTER(SIGNER, af_alg_signer_create);
|
||||
af_alg_signer_probe(f, &count);
|
||||
f[count++] = PLUGIN_REGISTER(PRF, af_alg_prf_create);
|
||||
af_alg_prf_probe(f, &count);
|
||||
f[count++] = PLUGIN_REGISTER(CRYPTER, af_alg_crypter_create);
|
||||
af_alg_crypter_probe(f, &count);
|
||||
}
|
||||
*features = f;
|
||||
return count;
|
||||
}
|
||||
|
||||
METHOD(plugin_t, destroy, void,
|
||||
private_af_alg_plugin_t *this)
|
||||
{
|
||||
lib->crypto->remove_hasher(lib->crypto,
|
||||
(hasher_constructor_t)af_alg_hasher_create);
|
||||
lib->crypto->remove_signer(lib->crypto,
|
||||
(signer_constructor_t)af_alg_signer_create);
|
||||
lib->crypto->remove_prf(lib->crypto,
|
||||
(prf_constructor_t)af_alg_prf_create);
|
||||
lib->crypto->remove_crypter(lib->crypto,
|
||||
(crypter_constructor_t)af_alg_crypter_create);
|
||||
|
||||
free(this);
|
||||
}
|
||||
|
||||
@@ -67,16 +80,11 @@ plugin_t *af_alg_plugin_create()
|
||||
.public = {
|
||||
.plugin = {
|
||||
.get_name = _get_name,
|
||||
.reload = (void*)return_false,
|
||||
.get_features = _get_features,
|
||||
.destroy = _destroy,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
af_alg_hasher_probe(get_name(this));
|
||||
af_alg_signer_probe(get_name(this));
|
||||
af_alg_prf_probe(get_name(this));
|
||||
af_alg_crypter_probe(get_name(this));
|
||||
|
||||
return &this->public.plugin;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ static struct {
|
||||
char *name;
|
||||
size_t block_size;
|
||||
bool xcbc;
|
||||
} algs[] = {
|
||||
} algs[AF_ALG_PRF] = {
|
||||
{PRF_HMAC_SHA1, "hmac(sha1)", 20, FALSE, },
|
||||
{PRF_HMAC_SHA2_256, "hmac(sha256)", 32, FALSE, },
|
||||
{PRF_HMAC_MD5, "hmac(md5)", 16, FALSE, },
|
||||
@@ -70,7 +70,7 @@ static struct {
|
||||
/**
|
||||
* See header.
|
||||
*/
|
||||
void af_alg_prf_probe(char *plugin)
|
||||
void af_alg_prf_probe(plugin_feature_t *features, int *pos)
|
||||
{
|
||||
af_alg_ops_t *ops;
|
||||
int i;
|
||||
@@ -81,8 +81,7 @@ void af_alg_prf_probe(char *plugin)
|
||||
if (ops)
|
||||
{
|
||||
ops->destroy(ops);
|
||||
lib->crypto->add_prf(lib->crypto, algs[i].id, plugin,
|
||||
(prf_constructor_t)af_alg_prf_create);
|
||||
features[(*pos)++] = PLUGIN_PROVIDE(PRF, algs[i].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,12 @@
|
||||
|
||||
typedef struct af_alg_prf_t af_alg_prf_t;
|
||||
|
||||
#include <plugins/plugin.h>
|
||||
#include <crypto/prfs/prf.h>
|
||||
|
||||
/** Number of PRFs */
|
||||
#define AF_ALG_PRF 7
|
||||
|
||||
/**
|
||||
* Implementation of PRFs using AF_ALG.
|
||||
*/
|
||||
@@ -45,10 +49,11 @@ struct af_alg_prf_t {
|
||||
af_alg_prf_t *af_alg_prf_create(pseudo_random_function_t algo);
|
||||
|
||||
/**
|
||||
* Probe algorithms and register af_alg_prf_create().
|
||||
* Probe algorithms and return plugin features.
|
||||
*
|
||||
* @param plugin plugin name to register algorithms for
|
||||
* @param features plugin features to create
|
||||
* @param pos current position in features
|
||||
*/
|
||||
void af_alg_prf_probe(char *plugin);
|
||||
void af_alg_prf_probe(plugin_feature_t *features, int *pos);
|
||||
|
||||
#endif /** AF_ALG_PRF_H_ @}*/
|
||||
|
||||
@@ -52,7 +52,7 @@ static struct {
|
||||
char *name;
|
||||
size_t block_size;
|
||||
size_t key_size;
|
||||
} algs[] = {
|
||||
} algs[AF_ALG_SIGNER] = {
|
||||
{AUTH_HMAC_SHA1_96, "hmac(sha1)", 12, 20, },
|
||||
{AUTH_HMAC_SHA1_128, "hmac(sha1)", 16, 20, },
|
||||
{AUTH_HMAC_SHA1_160, "hmac(sha1)", 20, 20, },
|
||||
@@ -71,7 +71,7 @@ static struct {
|
||||
/**
|
||||
* See header.
|
||||
*/
|
||||
void af_alg_signer_probe(char *plugin)
|
||||
void af_alg_signer_probe(plugin_feature_t *features, int *pos)
|
||||
{
|
||||
af_alg_ops_t *ops;
|
||||
int i;
|
||||
@@ -82,8 +82,7 @@ void af_alg_signer_probe(char *plugin)
|
||||
if (ops)
|
||||
{
|
||||
ops->destroy(ops);
|
||||
lib->crypto->add_signer(lib->crypto, algs[i].id, plugin,
|
||||
(signer_constructor_t)af_alg_signer_create);
|
||||
features[(*pos)++] = PLUGIN_PROVIDE(SIGNER, algs[i].id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,12 @@
|
||||
|
||||
typedef struct af_alg_signer_t af_alg_signer_t;
|
||||
|
||||
#include <plugins/plugin.h>
|
||||
#include <crypto/signers/signer.h>
|
||||
|
||||
/** Number of signers */
|
||||
#define AF_ALG_SIGNER 13
|
||||
|
||||
/**
|
||||
* Implementation of signers using AF_ALG.
|
||||
*/
|
||||
@@ -45,10 +49,11 @@ struct af_alg_signer_t {
|
||||
af_alg_signer_t *af_alg_signer_create(integrity_algorithm_t algo);
|
||||
|
||||
/**
|
||||
* Probe algorithms and register af_alg_signer_create().
|
||||
* Probe algorithms and return plugin features.
|
||||
*
|
||||
* @param plugin plugin name to register algorithms for
|
||||
* @param features plugin features to create
|
||||
* @param pos current position in features
|
||||
*/
|
||||
void af_alg_signer_probe(char *plugin);
|
||||
void af_alg_signer_probe(plugin_feature_t *features, int *pos);
|
||||
|
||||
#endif /** AF_ALG_SIGNER_H_ @}*/
|
||||
|
||||
Reference in New Issue
Block a user