Migrated padlock plugin to INIT/METHOD macros
This commit is contained in:
@@ -78,8 +78,8 @@ static void padlock_crypt(void *key, void *ctrl, void *src, void *dst,
|
|||||||
: "eax", "ecx", "edx", "esi", "edi");
|
: "eax", "ecx", "edx", "esi", "edi");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Implementation of crypter_t.crypt
|
* Do encryption/decryption operation using Padlock control word
|
||||||
*/
|
*/
|
||||||
static void crypt(private_padlock_aes_crypter_t *this, char *iv,
|
static void crypt(private_padlock_aes_crypter_t *this, char *iv,
|
||||||
chunk_t src, chunk_t *dst, bool enc)
|
chunk_t src, chunk_t *dst, bool enc)
|
||||||
@@ -107,53 +107,38 @@ static void crypt(private_padlock_aes_crypter_t *this, char *iv,
|
|||||||
src.len / AES_BLOCK_SIZE, iv_aligned);
|
src.len / AES_BLOCK_SIZE, iv_aligned);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, decrypt, void,
|
||||||
* Implementation of crypter_t.decrypt.
|
private_padlock_aes_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *dst)
|
||||||
*/
|
|
||||||
static void decrypt(private_padlock_aes_crypter_t *this, chunk_t data,
|
|
||||||
chunk_t iv, chunk_t *dst)
|
|
||||||
{
|
{
|
||||||
crypt(this, iv.ptr, data, dst, TRUE);
|
crypt(this, iv.ptr, data, dst, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
METHOD(crypter_t, encrypt, void,
|
||||||
/**
|
private_padlock_aes_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *dst)
|
||||||
* Implementation of crypter_t.encrypt.
|
|
||||||
*/
|
|
||||||
static void encrypt (private_padlock_aes_crypter_t *this, chunk_t data,
|
|
||||||
chunk_t iv, chunk_t *dst)
|
|
||||||
{
|
{
|
||||||
crypt(this, iv.ptr, data, dst, FALSE);
|
crypt(this, iv.ptr, data, dst, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, get_block_size, size_t,
|
||||||
* Implementation of crypter_t.get_block_size.
|
private_padlock_aes_crypter_t *this)
|
||||||
*/
|
|
||||||
static size_t get_block_size(private_padlock_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_padlock_aes_crypter_t *this)
|
||||||
*/
|
|
||||||
static size_t get_key_size(private_padlock_aes_crypter_t *this)
|
|
||||||
{
|
{
|
||||||
return this->key.len;
|
return this->key.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, set_key, void,
|
||||||
* Implementation of crypter_t.set_key.
|
private_padlock_aes_crypter_t *this, chunk_t key)
|
||||||
*/
|
|
||||||
static void set_key(private_padlock_aes_crypter_t *this, chunk_t key)
|
|
||||||
{
|
{
|
||||||
memcpy(this->key.ptr, key.ptr, min(key.len, this->key.len));
|
memcpy(this->key.ptr, key.ptr, min(key.len, this->key.len));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(crypter_t, destroy, void,
|
||||||
* Implementation of crypter_t.destroy and aes_crypter_t.destroy.
|
private_padlock_aes_crypter_t *this)
|
||||||
*/
|
|
||||||
static void destroy (private_padlock_aes_crypter_t *this)
|
|
||||||
{
|
{
|
||||||
free(this->key.ptr);
|
free(this->key.ptr);
|
||||||
free(this);
|
free(this);
|
||||||
@@ -171,9 +156,6 @@ padlock_aes_crypter_t *padlock_aes_crypter_create(encryption_algorithm_t algo,
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
this = malloc_thing(private_padlock_aes_crypter_t);
|
|
||||||
|
|
||||||
switch (key_size)
|
switch (key_size)
|
||||||
{
|
{
|
||||||
case 16: /* AES 128 */
|
case 16: /* AES 128 */
|
||||||
@@ -182,18 +164,19 @@ padlock_aes_crypter_t *padlock_aes_crypter_create(encryption_algorithm_t algo,
|
|||||||
case 32: /* AES-256 */
|
case 32: /* AES-256 */
|
||||||
/* These need an expanded key, currently not supported, FALL */
|
/* These need an expanded key, currently not supported, FALL */
|
||||||
default:
|
default:
|
||||||
free(this);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->key = chunk_alloc(key_size);
|
INIT(this,
|
||||||
|
.public.crypter = {
|
||||||
this->public.crypter_interface.encrypt = (void (*) (crypter_t *, chunk_t,chunk_t, chunk_t *)) encrypt;
|
.encrypt = _encrypt,
|
||||||
this->public.crypter_interface.decrypt = (void (*) (crypter_t *, chunk_t , chunk_t, chunk_t *)) decrypt;
|
.decrypt = _decrypt,
|
||||||
this->public.crypter_interface.get_block_size = (size_t (*) (crypter_t *)) get_block_size;
|
.get_block_size = _get_block_size,
|
||||||
this->public.crypter_interface.get_key_size = (size_t (*) (crypter_t *)) get_key_size;
|
.get_key_size = _get_key_size,
|
||||||
this->public.crypter_interface.set_key = (void (*) (crypter_t *,chunk_t)) set_key;
|
.set_key = _set_key,
|
||||||
this->public.crypter_interface.destroy = (void (*) (crypter_t *)) destroy;
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
|
.key = chunk_alloc(key_size),
|
||||||
|
);
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ typedef struct padlock_aes_crypter_t padlock_aes_crypter_t;
|
|||||||
struct padlock_aes_crypter_t {
|
struct padlock_aes_crypter_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The crypter_t interface.
|
* Implements crypter_t interface.
|
||||||
*/
|
*/
|
||||||
crypter_t crypter_interface;
|
crypter_t crypter;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -101,10 +101,8 @@ static padlock_feature_t get_padlock_features()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(plugin_t, destroy, void,
|
||||||
* Implementation of aes_plugin_t.destroy
|
private_padlock_plugin_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_padlock_plugin_t *this)
|
|
||||||
{
|
{
|
||||||
if (this->features & PADLOCK_RNG_ENABLED)
|
if (this->features & PADLOCK_RNG_ENABLED)
|
||||||
{
|
{
|
||||||
@@ -133,11 +131,13 @@ static void destroy(private_padlock_plugin_t *this)
|
|||||||
*/
|
*/
|
||||||
plugin_t *padlock_plugin_create()
|
plugin_t *padlock_plugin_create()
|
||||||
{
|
{
|
||||||
private_padlock_plugin_t *this = malloc_thing(private_padlock_plugin_t);
|
private_padlock_plugin_t *this;
|
||||||
|
|
||||||
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
|
INIT(this,
|
||||||
|
.public.plugin.destroy = _destroy,
|
||||||
|
.features = get_padlock_features(),
|
||||||
|
);
|
||||||
|
|
||||||
this->features = get_padlock_features();
|
|
||||||
if (!this->features)
|
if (!this->features)
|
||||||
{
|
{
|
||||||
free(this);
|
free(this);
|
||||||
|
|||||||
@@ -69,11 +69,8 @@ static void rng(char *buf, int len, int quality)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(rng_t, allocate_bytes, void,
|
||||||
* Implementation of padlock_rng_t.allocate_bytes.
|
private_padlock_rng_t *this, size_t bytes, chunk_t *chunk)
|
||||||
*/
|
|
||||||
static void allocate_bytes(private_padlock_rng_t *this, size_t bytes,
|
|
||||||
chunk_t *chunk)
|
|
||||||
{
|
{
|
||||||
chunk->len = bytes;
|
chunk->len = bytes;
|
||||||
/* padlock requires some additional bytes */
|
/* padlock requires some additional bytes */
|
||||||
@@ -82,11 +79,8 @@ static void allocate_bytes(private_padlock_rng_t *this, size_t bytes,
|
|||||||
rng(chunk->ptr, chunk->len, this->quality);
|
rng(chunk->ptr, chunk->len, this->quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(rng_t, get_bytes, void,
|
||||||
* Implementation of padlock_rng_t.get_bytes.
|
private_padlock_rng_t *this, size_t bytes, u_int8_t *buffer)
|
||||||
*/
|
|
||||||
static void get_bytes(private_padlock_rng_t *this, size_t bytes,
|
|
||||||
u_int8_t *buffer)
|
|
||||||
{
|
{
|
||||||
chunk_t chunk;
|
chunk_t chunk;
|
||||||
|
|
||||||
@@ -96,10 +90,8 @@ static void get_bytes(private_padlock_rng_t *this, size_t bytes,
|
|||||||
chunk_clear(&chunk);
|
chunk_clear(&chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(rng_t, destroy, void,
|
||||||
* Implementation of padlock_rng_t.destroy.
|
private_padlock_rng_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_padlock_rng_t *this)
|
|
||||||
{
|
{
|
||||||
free(this);
|
free(this);
|
||||||
}
|
}
|
||||||
@@ -109,11 +101,15 @@ static void destroy(private_padlock_rng_t *this)
|
|||||||
*/
|
*/
|
||||||
padlock_rng_t *padlock_rng_create(rng_quality_t quality)
|
padlock_rng_t *padlock_rng_create(rng_quality_t quality)
|
||||||
{
|
{
|
||||||
private_padlock_rng_t *this = malloc_thing(private_padlock_rng_t);
|
private_padlock_rng_t *this;
|
||||||
|
|
||||||
this->public.rng.get_bytes = (void (*) (rng_t *, size_t, u_int8_t*)) get_bytes;
|
INIT(this,
|
||||||
this->public.rng.allocate_bytes = (void (*) (rng_t *, size_t, chunk_t*)) allocate_bytes;
|
.public.rng = {
|
||||||
this->public.rng.destroy = (void (*) (rng_t *))destroy;
|
.get_bytes = _get_bytes,
|
||||||
|
.allocate_bytes = _allocate_bytes,
|
||||||
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
/* map RNG quality to Padlock quality factor */
|
/* map RNG quality to Padlock quality factor */
|
||||||
switch (quality)
|
switch (quality)
|
||||||
@@ -127,8 +123,10 @@ padlock_rng_t *padlock_rng_create(rng_quality_t quality)
|
|||||||
case RNG_TRUE:
|
case RNG_TRUE:
|
||||||
this->quality = PADLOCK_QF3;
|
this->quality = PADLOCK_QF3;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
free(this);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,19 +83,14 @@ static void append_data(private_padlock_sha1_hasher_t *this, chunk_t data)
|
|||||||
this->data.len += data.len;
|
this->data.len += data.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(hasher_t, reset, void,
|
||||||
* Implementation of hasher_t.reset.
|
private_padlock_sha1_hasher_t *this)
|
||||||
*/
|
|
||||||
static void reset(private_padlock_sha1_hasher_t *this)
|
|
||||||
{
|
{
|
||||||
chunk_free(&this->data);
|
chunk_free(&this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(hasher_t, get_hash, void,
|
||||||
* Implementation of hasher_t.get_hash.
|
private_padlock_sha1_hasher_t *this, chunk_t chunk, u_int8_t *hash)
|
||||||
*/
|
|
||||||
static void get_hash(private_padlock_sha1_hasher_t *this, chunk_t chunk,
|
|
||||||
u_int8_t *hash)
|
|
||||||
{
|
{
|
||||||
if (hash)
|
if (hash)
|
||||||
{
|
{
|
||||||
@@ -116,11 +111,8 @@ static void get_hash(private_padlock_sha1_hasher_t *this, chunk_t chunk,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(hasher_t, allocate_hash, void,
|
||||||
* Implementation of hasher_t.allocate_hash.
|
private_padlock_sha1_hasher_t *this, chunk_t chunk, chunk_t *hash)
|
||||||
*/
|
|
||||||
static void allocate_hash(private_padlock_sha1_hasher_t *this, chunk_t chunk,
|
|
||||||
chunk_t *hash)
|
|
||||||
{
|
{
|
||||||
if (hash)
|
if (hash)
|
||||||
{
|
{
|
||||||
@@ -133,18 +125,14 @@ static void allocate_hash(private_padlock_sha1_hasher_t *this, chunk_t chunk,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(hasher_t, get_hash_size, size_t,
|
||||||
* Implementation of hasher_t.get_hash_size.
|
private_padlock_sha1_hasher_t *this)
|
||||||
*/
|
|
||||||
static size_t get_hash_size(private_padlock_sha1_hasher_t *this)
|
|
||||||
{
|
{
|
||||||
return HASH_SIZE_SHA1;
|
return HASH_SIZE_SHA1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(hasher_t, destroy, void,
|
||||||
* Implementation of hasher_t.destroy.
|
private_padlock_sha1_hasher_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_padlock_sha1_hasher_t *this)
|
|
||||||
{
|
{
|
||||||
free(this->data.ptr);
|
free(this->data.ptr);
|
||||||
free(this);
|
free(this);
|
||||||
@@ -161,15 +149,14 @@ padlock_sha1_hasher_t *padlock_sha1_hasher_create(hash_algorithm_t algo)
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
INIT(this,
|
||||||
this = malloc_thing(private_padlock_sha1_hasher_t);
|
.public.hasher = {
|
||||||
this->public.hasher_interface.get_hash = (void (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
|
.get_hash = _get_hash,
|
||||||
this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
|
.allocate_hash = _allocate_hash,
|
||||||
this->public.hasher_interface.get_hash_size = (size_t (*) (hasher_t*))get_hash_size;
|
.get_hash_size = _get_hash_size,
|
||||||
this->public.hasher_interface.reset = (void (*) (hasher_t*))reset;
|
.reset = _reset,
|
||||||
this->public.hasher_interface.destroy = (void (*) (hasher_t*))destroy;
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
this->data = chunk_empty;
|
);
|
||||||
|
return &this->public;
|
||||||
return &(this->public);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ struct padlock_sha1_hasher_t {
|
|||||||
/**
|
/**
|
||||||
* Implements hasher_t interface.
|
* Implements hasher_t interface.
|
||||||
*/
|
*/
|
||||||
hasher_t hasher_interface;
|
hasher_t hasher;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user