Migrated blowfish plugin to INIT/METHOD macros
This commit is contained in:
@@ -68,8 +68,6 @@ typedef struct private_blowfish_crypter_t private_blowfish_crypter_t;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class implementing the Blowfish symmetric encryption algorithm.
|
* Class implementing the Blowfish symmetric encryption algorithm.
|
||||||
*
|
|
||||||
* @ingroup crypters
|
|
||||||
*/
|
*/
|
||||||
struct private_blowfish_crypter_t {
|
struct private_blowfish_crypter_t {
|
||||||
|
|
||||||
@@ -89,11 +87,9 @@ struct private_blowfish_crypter_t {
|
|||||||
u_int32_t key_size;
|
u_int32_t key_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, decrypt, void,
|
||||||
* Implementation of crypter_t.decrypt.
|
private_blowfish_crypter_t *this, chunk_t data, chunk_t iv,
|
||||||
*/
|
chunk_t *decrypted)
|
||||||
static void decrypt(private_blowfish_crypter_t *this, chunk_t data, chunk_t iv,
|
|
||||||
chunk_t *decrypted)
|
|
||||||
{
|
{
|
||||||
u_int8_t *in, *out;
|
u_int8_t *in, *out;
|
||||||
|
|
||||||
@@ -114,11 +110,9 @@ static void decrypt(private_blowfish_crypter_t *this, chunk_t data, chunk_t iv,
|
|||||||
free(iv.ptr);
|
free(iv.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, encrypt, void,
|
||||||
* Implementation of crypter_t.decrypt.
|
private_blowfish_crypter_t *this, chunk_t data, chunk_t iv,
|
||||||
*/
|
chunk_t *encrypted)
|
||||||
static void encrypt (private_blowfish_crypter_t *this, chunk_t data, chunk_t iv,
|
|
||||||
chunk_t *encrypted)
|
|
||||||
{
|
{
|
||||||
u_int8_t *in, *out;
|
u_int8_t *in, *out;
|
||||||
|
|
||||||
@@ -139,34 +133,26 @@ static void encrypt (private_blowfish_crypter_t *this, chunk_t data, chunk_t iv,
|
|||||||
free(iv.ptr);
|
free(iv.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, get_block_size, size_t,
|
||||||
* Implementation of crypter_t.get_block_size.
|
private_blowfish_crypter_t *this)
|
||||||
*/
|
|
||||||
static size_t get_block_size (private_blowfish_crypter_t *this)
|
|
||||||
{
|
{
|
||||||
return BLOWFISH_BLOCK_SIZE;
|
return BLOWFISH_BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, get_key_size, size_t,
|
||||||
* Implementation of crypter_t.get_key_size.
|
private_blowfish_crypter_t *this)
|
||||||
*/
|
|
||||||
static size_t get_key_size (private_blowfish_crypter_t *this)
|
|
||||||
{
|
{
|
||||||
return this->key_size;
|
return this->key_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, set_key, void,
|
||||||
* Implementation of crypter_t.set_key.
|
private_blowfish_crypter_t *this, chunk_t key)
|
||||||
*/
|
|
||||||
static void set_key (private_blowfish_crypter_t *this, chunk_t key)
|
|
||||||
{
|
{
|
||||||
BF_set_key(&this->schedule, key.len , key.ptr);
|
BF_set_key(&this->schedule, key.len , key.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, destroy, void,
|
||||||
* Implementation of crypter_t.destroy and blowfish_crypter_t.destroy.
|
private_blowfish_crypter_t *this)
|
||||||
*/
|
|
||||||
static void destroy (private_blowfish_crypter_t *this)
|
|
||||||
{
|
{
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
@@ -183,15 +169,17 @@ blowfish_crypter_t *blowfish_crypter_create(encryption_algorithm_t algo, size_t
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
this = malloc_thing(private_blowfish_crypter_t);
|
INIT(this,
|
||||||
|
.public.crypter = {
|
||||||
|
.encrypt = _encrypt,
|
||||||
|
.decrypt = _decrypt,
|
||||||
|
.get_block_size = _get_block_size,
|
||||||
|
.get_key_size = _get_key_size,
|
||||||
|
.set_key = _set_key,
|
||||||
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
|
.key_size = key_size,
|
||||||
|
);
|
||||||
|
|
||||||
this->key_size = key_size;
|
return &this->public;
|
||||||
this->public.crypter_interface.encrypt = (void (*) (crypter_t *, chunk_t,chunk_t, chunk_t *)) encrypt;
|
|
||||||
this->public.crypter_interface.decrypt = (void (*) (crypter_t *, chunk_t , chunk_t, chunk_t *)) decrypt;
|
|
||||||
this->public.crypter_interface.get_block_size = (size_t (*) (crypter_t *)) get_block_size;
|
|
||||||
this->public.crypter_interface.get_key_size = (size_t (*) (crypter_t *)) get_key_size;
|
|
||||||
this->public.crypter_interface.set_key = (void (*) (crypter_t *,chunk_t)) set_key;
|
|
||||||
this->public.crypter_interface.destroy = (void (*) (crypter_t *)) destroy;
|
|
||||||
|
|
||||||
return &(this->public);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ typedef struct blowfish_crypter_t blowfish_crypter_t;
|
|||||||
struct blowfish_crypter_t {
|
struct blowfish_crypter_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The crypter_t interface.
|
* Implements crypter_t interface.
|
||||||
*/
|
*/
|
||||||
crypter_t crypter_interface;
|
crypter_t crypter;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,10 +32,8 @@ struct private_blowfish_plugin_t {
|
|||||||
blowfish_plugin_t public;
|
blowfish_plugin_t public;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
METHOD(plugin_t, destroy, void,
|
||||||
* Implementation of blowfish_plugin_t.destroy
|
private_blowfish_plugin_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_blowfish_plugin_t *this)
|
|
||||||
{
|
{
|
||||||
lib->crypto->remove_crypter(lib->crypto,
|
lib->crypto->remove_crypter(lib->crypto,
|
||||||
(crypter_constructor_t)blowfish_crypter_create);
|
(crypter_constructor_t)blowfish_crypter_create);
|
||||||
@@ -47,9 +45,11 @@ static void destroy(private_blowfish_plugin_t *this)
|
|||||||
*/
|
*/
|
||||||
plugin_t *blowfish_plugin_create()
|
plugin_t *blowfish_plugin_create()
|
||||||
{
|
{
|
||||||
private_blowfish_plugin_t *this = malloc_thing(private_blowfish_plugin_t);
|
private_blowfish_plugin_t *this;
|
||||||
|
|
||||||
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
|
INIT(this,
|
||||||
|
.public.plugin.destroy = _destroy,
|
||||||
|
);
|
||||||
|
|
||||||
lib->crypto->add_crypter(lib->crypto, ENCR_BLOWFISH,
|
lib->crypto->add_crypter(lib->crypto, ENCR_BLOWFISH,
|
||||||
(crypter_constructor_t)blowfish_crypter_create);
|
(crypter_constructor_t)blowfish_crypter_create);
|
||||||
|
|||||||
Reference in New Issue
Block a user