Migrated the aes plugin to INIT/METHOD macros
This commit is contained in:
@@ -1331,11 +1331,8 @@ static void decrypt_block(const private_aes_crypter_t *this, const unsigned char
|
|||||||
state_out(out_blk, b0);
|
state_out(out_blk, b0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, decrypt, void,
|
||||||
* Implementation of crypter_t.decrypt.
|
private_aes_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *decrypted)
|
||||||
*/
|
|
||||||
static void decrypt(private_aes_crypter_t *this, chunk_t data, chunk_t iv,
|
|
||||||
chunk_t *decrypted)
|
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
const u_int32_t *iv_i;
|
const u_int32_t *iv_i;
|
||||||
@@ -1376,12 +1373,8 @@ static void decrypt(private_aes_crypter_t *this, chunk_t data, chunk_t iv,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
METHOD(crypter_t, encrypt, void,
|
||||||
/**
|
private_aes_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *encrypted)
|
||||||
* Implementation of crypter_t.decrypt.
|
|
||||||
*/
|
|
||||||
static void encrypt (private_aes_crypter_t *this, chunk_t data, chunk_t iv,
|
|
||||||
chunk_t *encrypted)
|
|
||||||
{
|
{
|
||||||
int pos;
|
int pos;
|
||||||
const u_int32_t *iv_i;
|
const u_int32_t *iv_i;
|
||||||
@@ -1417,26 +1410,20 @@ static void encrypt (private_aes_crypter_t *this, chunk_t data, chunk_t iv,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, get_block_size, size_t,
|
||||||
* Implementation of crypter_t.get_block_size.
|
private_aes_crypter_t *this)
|
||||||
*/
|
|
||||||
static size_t get_block_size (private_aes_crypter_t *this)
|
|
||||||
{
|
{
|
||||||
return AES_BLOCK_SIZE;
|
return AES_BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, get_key_size, size_t,
|
||||||
* Implementation of crypter_t.get_key_size.
|
private_aes_crypter_t *this)
|
||||||
*/
|
|
||||||
static size_t get_key_size (private_aes_crypter_t *this)
|
|
||||||
{
|
{
|
||||||
return this->key_size;
|
return this->key_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, set_key, void,
|
||||||
* Implementation of crypter_t.set_key.
|
private_aes_crypter_t *this, chunk_t key)
|
||||||
*/
|
|
||||||
static void set_key (private_aes_crypter_t *this, chunk_t key)
|
|
||||||
{
|
{
|
||||||
u_int32_t *kf, *kt, rci, f = 0;
|
u_int32_t *kf, *kt, rci, f = 0;
|
||||||
u_int8_t *in_key = key.ptr;
|
u_int8_t *in_key = key.ptr;
|
||||||
@@ -1498,8 +1485,8 @@ static void set_key (private_aes_crypter_t *this, chunk_t key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!f)
|
if(!f)
|
||||||
{
|
{
|
||||||
u_int32_t i;
|
u_int32_t i;
|
||||||
|
|
||||||
kt = this->aes_d_key + nc * this->aes_Nrnd;
|
kt = this->aes_d_key + nc * this->aes_Nrnd;
|
||||||
kf = this->aes_e_key;
|
kf = this->aes_e_key;
|
||||||
@@ -1517,15 +1504,13 @@ static void set_key (private_aes_crypter_t *this, chunk_t key)
|
|||||||
cpy(kt, kf);
|
cpy(kt, kf);
|
||||||
#endif
|
#endif
|
||||||
kt -= 2 * nc;
|
kt -= 2 * nc;
|
||||||
}
|
}
|
||||||
cpy(kt, kf);
|
cpy(kt, kf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, destroy, void,
|
||||||
* Implementation of crypter_t.destroy and aes_crypter_t.destroy.
|
private_aes_crypter_t *this)
|
||||||
*/
|
|
||||||
static void destroy (private_aes_crypter_t *this)
|
|
||||||
{
|
{
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
@@ -1541,36 +1526,32 @@ aes_crypter_t *aes_crypter_create(encryption_algorithm_t algo, size_t key_size)
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
switch (key_size)
|
||||||
this = malloc_thing(private_aes_crypter_t);
|
{
|
||||||
|
case 32:
|
||||||
|
case 24:
|
||||||
|
case 16:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(FIXED_TABLES)
|
#if !defined(FIXED_TABLES)
|
||||||
if(!tab_gen) { gen_tabs(); tab_gen = 1; }
|
if(!tab_gen) { gen_tabs(); tab_gen = 1; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
this->key_size = key_size;
|
INIT(this,
|
||||||
switch(key_size)
|
.public.crypter = {
|
||||||
{
|
.encrypt = _encrypt,
|
||||||
case 32: /* bytes */
|
.decrypt = _decrypt,
|
||||||
this->aes_Nkey = 8;
|
.get_block_size = _get_block_size,
|
||||||
break;
|
.get_key_size = _get_key_size,
|
||||||
case 24: /* bytes */
|
.set_key = _set_key,
|
||||||
this->aes_Nkey = 6;
|
.destroy = _destroy,
|
||||||
break;
|
},
|
||||||
case 16: /* bytes */
|
.key_size = key_size,
|
||||||
this->aes_Nkey = 4;
|
.aes_Nkey = key_size / 4,
|
||||||
break;
|
);
|
||||||
default:
|
|
||||||
free(this);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
return &(this->public);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ typedef struct aes_crypter_t aes_crypter_t;
|
|||||||
struct aes_crypter_t {
|
struct aes_crypter_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The crypter_t interface.
|
* Implements crypter_t interface.
|
||||||
*/
|
*/
|
||||||
crypter_t crypter_interface;
|
crypter_t crypter;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,10 +31,8 @@ struct private_aes_plugin_t {
|
|||||||
aes_plugin_t public;
|
aes_plugin_t public;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
METHOD(plugin_t, destroy, void,
|
||||||
* Implementation of aes_plugin_t.destroy
|
private_aes_plugin_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_aes_plugin_t *this)
|
|
||||||
{
|
{
|
||||||
lib->crypto->remove_crypter(lib->crypto,
|
lib->crypto->remove_crypter(lib->crypto,
|
||||||
(crypter_constructor_t)aes_crypter_create);
|
(crypter_constructor_t)aes_crypter_create);
|
||||||
@@ -46,9 +44,11 @@ static void destroy(private_aes_plugin_t *this)
|
|||||||
*/
|
*/
|
||||||
plugin_t *aes_plugin_create()
|
plugin_t *aes_plugin_create()
|
||||||
{
|
{
|
||||||
private_aes_plugin_t *this = malloc_thing(private_aes_plugin_t);
|
private_aes_plugin_t *this;
|
||||||
|
|
||||||
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
|
INIT(this,
|
||||||
|
.public.plugin.destroy = _destroy,
|
||||||
|
);
|
||||||
|
|
||||||
lib->crypto->add_crypter(lib->crypto, ENCR_AES_CBC,
|
lib->crypto->add_crypter(lib->crypto, ENCR_AES_CBC,
|
||||||
(crypter_constructor_t)aes_crypter_create);
|
(crypter_constructor_t)aes_crypter_create);
|
||||||
|
|||||||
Reference in New Issue
Block a user