aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/gcrypt/gcrypt_crypter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/plugins/gcrypt/gcrypt_crypter.c')
-rw-r--r--src/libstrongswan/plugins/gcrypt/gcrypt_crypter.c59
1 files changed, 23 insertions, 36 deletions
diff --git a/src/libstrongswan/plugins/gcrypt/gcrypt_crypter.c b/src/libstrongswan/plugins/gcrypt/gcrypt_crypter.c
index 5dbdde32c..3db5e5750 100644
--- a/src/libstrongswan/plugins/gcrypt/gcrypt_crypter.c
+++ b/src/libstrongswan/plugins/gcrypt/gcrypt_crypter.c
@@ -42,11 +42,8 @@ struct private_gcrypt_crypter_t {
int alg;
};
-/**
- * Implementation of crypter_t.decrypt.
- */
-static void decrypt(private_gcrypt_crypter_t *this, chunk_t data,
- chunk_t iv, chunk_t *dst)
+METHOD(crypter_t, decrypt, void,
+ private_gcrypt_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *dst)
{
gcry_cipher_setiv(this->h, iv.ptr, iv.len);
@@ -61,11 +58,8 @@ static void decrypt(private_gcrypt_crypter_t *this, chunk_t data,
}
}
-/**
- * Implementation of crypter_t.encrypt.
- */
-static void encrypt(private_gcrypt_crypter_t *this, chunk_t data,
- chunk_t iv, chunk_t *dst)
+METHOD(crypter_t, encrypt, void,
+ private_gcrypt_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *dst)
{
gcry_cipher_setiv(this->h, iv.ptr, iv.len);
@@ -80,10 +74,8 @@ static void encrypt(private_gcrypt_crypter_t *this, chunk_t data,
}
}
-/**
- * Implementation of crypter_t.get_block_size.
- */
-static size_t get_block_size(private_gcrypt_crypter_t *this)
+METHOD(crypter_t, get_block_size, size_t,
+ private_gcrypt_crypter_t *this)
{
size_t len = 0;
@@ -91,10 +83,8 @@ static size_t get_block_size(private_gcrypt_crypter_t *this)
return len;
}
-/**
- * Implementation of crypter_t.get_key_size.
- */
-static size_t get_key_size(private_gcrypt_crypter_t *this)
+METHOD(crypter_t, get_key_size, size_t,
+ private_gcrypt_crypter_t *this)
{
size_t len = 0;
@@ -102,18 +92,14 @@ static size_t get_key_size(private_gcrypt_crypter_t *this)
return len;
}
-/**
- * Implementation of crypter_t.set_key.
- */
-static void set_key(private_gcrypt_crypter_t *this, chunk_t key)
+METHOD(crypter_t, set_key, void,
+ private_gcrypt_crypter_t *this, chunk_t key)
{
gcry_cipher_setkey(this->h, key.ptr, key.len);
}
-/**
- * Implementation of crypter_t.destroy.
- */
-static void destroy (private_gcrypt_crypter_t *this)
+METHOD(crypter_t, destroy, void,
+ private_gcrypt_crypter_t *this)
{
gcry_cipher_close(this->h);
free(this);
@@ -228,9 +214,18 @@ gcrypt_crypter_t *gcrypt_crypter_create(encryption_algorithm_t algo,
return NULL;
}
- this = malloc_thing(private_gcrypt_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,
+ },
+ .alg = gcrypt_alg,
+ );
- this->alg = gcrypt_alg;
err = gcry_cipher_open(&this->h, gcrypt_alg, mode, 0);
if (err)
{
@@ -239,14 +234,6 @@ gcrypt_crypter_t *gcrypt_crypter_create(encryption_algorithm_t algo,
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;
}