Migraded gcrypt plugin to INIT/METHOD macros

This commit is contained in:
Martin Willi
2010-08-10 18:46:30 +02:00
parent 876b61e132
commit 646babd354
11 changed files with 164 additions and 241 deletions
@@ -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;
}
@@ -33,7 +33,7 @@ struct gcrypt_crypter_t {
/**
* The crypter_t interface.
*/
crypter_t crypter_interface;
crypter_t crypter;
};
/**
+21 -32
View File
@@ -73,10 +73,8 @@ struct private_gcrypt_dh_t {
size_t p_len;
};
/**
* Implementation of gcrypt_dh_t.set_other_public_value.
*/
static void set_other_public_value(private_gcrypt_dh_t *this, chunk_t value)
METHOD(diffie_hellman_t, set_other_public_value, void,
private_gcrypt_dh_t *this, chunk_t value)
{
gcry_mpi_t p_min_1;
gcry_error_t err;
@@ -134,18 +132,14 @@ static chunk_t export_mpi(gcry_mpi_t value, size_t len)
return chunk;
}
/**
* Implementation of gcrypt_dh_t.get_my_public_value.
*/
static void get_my_public_value(private_gcrypt_dh_t *this, chunk_t *value)
METHOD(diffie_hellman_t, get_my_public_value, void,
private_gcrypt_dh_t *this, chunk_t *value)
{
*value = export_mpi(this->ya, this->p_len);
}
/**
* Implementation of gcrypt_dh_t.get_shared_secret.
*/
static status_t get_shared_secret(private_gcrypt_dh_t *this, chunk_t *secret)
METHOD(diffie_hellman_t, get_shared_secret, status_t,
private_gcrypt_dh_t *this, chunk_t *secret)
{
if (!this->zz)
{
@@ -155,18 +149,14 @@ static status_t get_shared_secret(private_gcrypt_dh_t *this, chunk_t *secret)
return SUCCESS;
}
/**
* Implementation of gcrypt_dh_t.get_dh_group.
*/
static diffie_hellman_group_t get_dh_group(private_gcrypt_dh_t *this)
METHOD(diffie_hellman_t, get_dh_group, diffie_hellman_group_t,
private_gcrypt_dh_t *this)
{
return this->group;
}
/**
* Implementation of gcrypt_dh_t.destroy.
*/
static void destroy(private_gcrypt_dh_t *this)
METHOD(diffie_hellman_t, destroy, void,
private_gcrypt_dh_t *this)
{
gcry_mpi_release(this->p);
gcry_mpi_release(this->xa);
@@ -194,16 +184,17 @@ gcrypt_dh_t *gcrypt_dh_create(diffie_hellman_group_t group)
return NULL;
}
this = malloc_thing(private_gcrypt_dh_t);
this->public.dh.get_shared_secret = (status_t (*)(diffie_hellman_t *, chunk_t *)) get_shared_secret;
this->public.dh.set_other_public_value = (void (*)(diffie_hellman_t *, chunk_t )) set_other_public_value;
this->public.dh.get_my_public_value = (void (*)(diffie_hellman_t *, chunk_t *)) get_my_public_value;
this->public.dh.get_dh_group = (diffie_hellman_group_t (*)(diffie_hellman_t *)) get_dh_group;
this->public.dh.destroy = (void (*)(diffie_hellman_t *)) destroy;
this->group = group;
this->p_len = params->prime.len;
INIT(this,
.public.dh = {
.get_shared_secret = _get_shared_secret,
.set_other_public_value = _set_other_public_value,
.get_my_public_value = _get_my_public_value,
.get_dh_group = _get_dh_group,
.destroy = _destroy,
},
.group = group,
.p_len = params->prime.len,
);
err = gcry_mpi_scan(&this->p, GCRYMPI_FMT_USG,
params->prime.ptr, params->prime.len, NULL);
if (err)
@@ -251,8 +242,6 @@ gcrypt_dh_t *gcrypt_dh_create(diffie_hellman_group_t group)
}
this->ya = gcry_mpi_new(this->p_len * 8);
this->yb = NULL;
this->zz = NULL;
gcry_mpi_powm(this->ya, this->g, this->xa, this->p);
@@ -37,27 +37,20 @@ struct private_gcrypt_hasher_t {
gcry_md_hd_t hd;
};
/**
* Implementation of hasher_t.get_hash_size.
*/
static size_t get_hash_size(private_gcrypt_hasher_t *this)
METHOD(hasher_t, get_hash_size, size_t,
private_gcrypt_hasher_t *this)
{
return gcry_md_get_algo_dlen(gcry_md_get_algo(this->hd));
}
/**
* Implementation of hasher_t.reset.
*/
static void reset(private_gcrypt_hasher_t *this)
METHOD(hasher_t, reset, void,
private_gcrypt_hasher_t *this)
{
gcry_md_reset(this->hd);
}
/**
* Implementation of hasher_t.get_hash.
*/
static void get_hash(private_gcrypt_hasher_t *this, chunk_t chunk,
u_int8_t *hash)
METHOD(hasher_t, get_hash, void,
private_gcrypt_hasher_t *this, chunk_t chunk, u_int8_t *hash)
{
gcry_md_write(this->hd, chunk.ptr, chunk.len);
if (hash)
@@ -67,11 +60,8 @@ static void get_hash(private_gcrypt_hasher_t *this, chunk_t chunk,
}
}
/**
* Implementation of hasher_t.allocate_hash.
*/
static void allocate_hash(private_gcrypt_hasher_t *this, chunk_t chunk,
chunk_t *hash)
METHOD(hasher_t, allocate_hash, void,
private_gcrypt_hasher_t *this, chunk_t chunk, chunk_t *hash)
{
if (hash)
{
@@ -84,10 +74,8 @@ static void allocate_hash(private_gcrypt_hasher_t *this, chunk_t chunk,
}
}
/**
* Implementation of hasher_t.destroy.
*/
static void destroy (private_gcrypt_hasher_t *this)
METHOD(hasher_t, destroy, void,
private_gcrypt_hasher_t *this)
{
gcry_md_close(this->hd);
free(this);
@@ -132,7 +120,15 @@ gcrypt_hasher_t *gcrypt_hasher_create(hash_algorithm_t algo)
return NULL;
}
this = malloc_thing(private_gcrypt_hasher_t);
INIT(this,
.public.hasher = {
.get_hash = _get_hash,
.allocate_hash = _allocate_hash,
.get_hash_size = _get_hash_size,
.reset = _reset,
.destroy = _destroy,
},
);
err = gcry_md_open(&this->hd, gcrypt_alg, 0);
if (err)
@@ -143,12 +139,6 @@ gcrypt_hasher_t *gcrypt_hasher_create(hash_algorithm_t algo)
return NULL;
}
this->public.hasher_interface.get_hash = (void (*) (hasher_t*, chunk_t, u_int8_t*))get_hash;
this->public.hasher_interface.allocate_hash = (void (*) (hasher_t*, chunk_t, chunk_t*))allocate_hash;
this->public.hasher_interface.get_hash_size = (size_t (*) (hasher_t*))get_hash_size;
this->public.hasher_interface.reset = (void (*) (hasher_t*))reset;
this->public.hasher_interface.destroy = (void (*) (hasher_t*))destroy;
return &this->public;
}
@@ -33,7 +33,7 @@ struct gcrypt_hasher_t {
/**
* The hasher_t interface.
*/
hasher_t hasher_interface;
hasher_t hasher;
};
/**
@@ -93,10 +93,8 @@ static struct gcry_thread_cbs thread_functions = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
/**
* Implementation of gcrypt_plugin_t.destroy
*/
static void destroy(private_gcrypt_plugin_t *this)
METHOD(plugin_t, destroy, void,
private_gcrypt_plugin_t *this)
{
lib->crypto->remove_hasher(lib->crypto,
(hasher_constructor_t)gcrypt_hasher_create);
@@ -139,9 +137,9 @@ plugin_t *gcrypt_plugin_create()
}
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
this = malloc_thing(private_gcrypt_plugin_t);
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
INIT(this,
.public.plugin.destroy = _destroy,
);
/* hashers */
lib->crypto->add_hasher(lib->crypto, HASH_SHA1,
+14 -21
View File
@@ -35,11 +35,8 @@ struct private_gcrypt_rng_t {
rng_quality_t quality;
};
/**
* Implementation of gcrypt_rng_t.get_bytes.
*/
static void get_bytes(private_gcrypt_rng_t *this, size_t bytes,
u_int8_t *buffer)
METHOD(rng_t, get_bytes, void,
private_gcrypt_rng_t *this, size_t bytes, u_int8_t *buffer)
{
switch (this->quality)
{
@@ -55,20 +52,15 @@ static void get_bytes(private_gcrypt_rng_t *this, size_t bytes,
}
}
/**
* Implementation of gcrypt_rng_t.allocate_bytes.
*/
static void allocate_bytes(private_gcrypt_rng_t *this, size_t bytes,
chunk_t *chunk)
METHOD(rng_t, allocate_bytes, void,
private_gcrypt_rng_t *this, size_t bytes, chunk_t *chunk)
{
*chunk = chunk_alloc(bytes);
get_bytes(this, chunk->len, chunk->ptr);
}
/**
* Implementation of gcrypt_rng_t.destroy.
*/
static void destroy(private_gcrypt_rng_t *this)
METHOD(rng_t, destroy, void,
private_gcrypt_rng_t *this)
{
free(this);
}
@@ -90,13 +82,14 @@ gcrypt_rng_t *gcrypt_rng_create(rng_quality_t quality)
return NULL;
}
this = malloc_thing(private_gcrypt_rng_t);
this->public.rng.get_bytes = (void (*) (rng_t *, size_t, u_int8_t*)) get_bytes;
this->public.rng.allocate_bytes = (void (*) (rng_t *, size_t, chunk_t*)) allocate_bytes;
this->public.rng.destroy = (void (*) (rng_t *))destroy;
this->quality = quality;
INIT(this,
.public.rng = {
.get_bytes = _get_bytes,
.allocate_bytes = _allocate_bytes,
.destroy = _destroy,
},
.quality = quality,
);
return &this->public;
}
@@ -192,19 +192,15 @@ static bool sign_pkcs1(private_gcrypt_rsa_private_key_t *this,
return !!signature->len;
}
/**
* Implementation of gcrypt_rsa_private_key.destroy.
*/
static key_type_t get_type(private_gcrypt_rsa_private_key_t *this)
METHOD(private_key_t, get_type, key_type_t,
private_gcrypt_rsa_private_key_t *this)
{
return KEY_RSA;
}
/**
* Implementation of gcrypt_rsa_private_key.destroy.
*/
static bool sign(private_gcrypt_rsa_private_key_t *this, signature_scheme_t scheme,
chunk_t data, chunk_t *sig)
METHOD(private_key_t, sign, bool,
private_gcrypt_rsa_private_key_t *this, signature_scheme_t scheme,
chunk_t data, chunk_t *sig)
{
switch (scheme)
{
@@ -229,11 +225,8 @@ static bool sign(private_gcrypt_rsa_private_key_t *this, signature_scheme_t sche
}
}
/**
* Implementation of gcrypt_rsa_private_key.destroy.
*/
static bool decrypt(private_gcrypt_rsa_private_key_t *this,
chunk_t encrypted, chunk_t *plain)
METHOD(private_key_t, decrypt, bool,
private_gcrypt_rsa_private_key_t *this, chunk_t encrypted, chunk_t *plain)
{
gcry_error_t err;
gcry_sexp_t in, out;
@@ -277,18 +270,14 @@ static bool decrypt(private_gcrypt_rsa_private_key_t *this,
return TRUE;
}
/**
* Implementation of gcrypt_rsa_private_key.get_keysize.
*/
static size_t get_keysize(private_gcrypt_rsa_private_key_t *this)
METHOD(private_key_t, get_keysize, size_t,
private_gcrypt_rsa_private_key_t *this)
{
return gcry_pk_get_nbits(this->key) / 8;
}
/**
* Implementation of gcrypt_rsa_private_key.get_public_key.
*/
static public_key_t* get_public_key(private_gcrypt_rsa_private_key_t *this)
METHOD(private_key_t, get_public_key, public_key_t*,
private_gcrypt_rsa_private_key_t *this)
{
chunk_t n, e;
public_key_t *public;
@@ -304,11 +293,9 @@ static public_key_t* get_public_key(private_gcrypt_rsa_private_key_t *this)
return public;
}
/**
* Implementation of private_key_t.get_encoding
*/
static bool get_encoding(private_gcrypt_rsa_private_key_t *this,
cred_encoding_type_t type, chunk_t *encoding)
METHOD(private_key_t, get_encoding, bool,
private_gcrypt_rsa_private_key_t *this, cred_encoding_type_t type,
chunk_t *encoding)
{
chunk_t cn, ce, cp, cq, cd, cu, cexp1 = chunk_empty, cexp2 = chunk_empty;
gcry_mpi_t p = NULL, q = NULL, d = NULL, exp1, exp2;
@@ -385,11 +372,9 @@ static bool get_encoding(private_gcrypt_rsa_private_key_t *this,
return success;
}
/**
* Implementation of private_key_t.get_fingerprint
*/
static bool get_fingerprint(private_gcrypt_rsa_private_key_t *this,
cred_encoding_type_t type, chunk_t *fp)
METHOD(private_key_t, get_fingerprint, bool,
private_gcrypt_rsa_private_key_t *this, cred_encoding_type_t type,
chunk_t *fp)
{
chunk_t n, e;
bool success;
@@ -409,19 +394,15 @@ static bool get_fingerprint(private_gcrypt_rsa_private_key_t *this,
return success;
}
/**
* Implementation of gcrypt_rsa_private_key.get_ref.
*/
static private_key_t* get_ref(private_gcrypt_rsa_private_key_t *this)
METHOD(private_key_t, get_ref, private_key_t*,
private_gcrypt_rsa_private_key_t *this)
{
ref_get(&this->ref);
return &this->public.interface;
return &this->public.key;
}
/**
* Implementation of gcrypt_rsa_private_key.destroy.
*/
static void destroy(private_gcrypt_rsa_private_key_t *this)
METHOD(private_key_t, destroy, void,
private_gcrypt_rsa_private_key_t *this)
{
if (ref_put(&this->ref))
{
@@ -434,25 +415,27 @@ static void destroy(private_gcrypt_rsa_private_key_t *this)
/**
* Internal generic constructor
*/
static private_gcrypt_rsa_private_key_t *gcrypt_rsa_private_key_create_empty()
static private_gcrypt_rsa_private_key_t *create_empty()
{
private_gcrypt_rsa_private_key_t *this = malloc_thing(private_gcrypt_rsa_private_key_t);
private_gcrypt_rsa_private_key_t *this;
this->public.interface.get_type = (key_type_t (*)(private_key_t *this))get_type;
this->public.interface.sign = (bool (*)(private_key_t *this, signature_scheme_t scheme, chunk_t data, chunk_t *signature))sign;
this->public.interface.decrypt = (bool (*)(private_key_t *this, chunk_t crypto, chunk_t *plain))decrypt;
this->public.interface.get_keysize = (size_t (*) (private_key_t *this))get_keysize;
this->public.interface.get_public_key = (public_key_t* (*)(private_key_t *this))get_public_key;
this->public.interface.equals = private_key_equals;
this->public.interface.belongs_to = private_key_belongs_to;
this->public.interface.get_fingerprint = (bool(*)(private_key_t*, cred_encoding_type_t type, chunk_t *fp))get_fingerprint;
this->public.interface.has_fingerprint = (bool(*)(private_key_t*, chunk_t fp))private_key_has_fingerprint;
this->public.interface.get_encoding = (bool(*)(private_key_t*, cred_encoding_type_t type, chunk_t *encoding))get_encoding;
this->public.interface.get_ref = (private_key_t* (*)(private_key_t *this))get_ref;
this->public.interface.destroy = (void (*)(private_key_t *this))destroy;
this->key = NULL;
this->ref = 1;
INIT(this,
.public.key = {
.get_type = _get_type,
.sign = _sign,
.decrypt = _decrypt,
.get_keysize = _get_keysize,
.get_public_key = _get_public_key,
.equals = private_key_equals,
.belongs_to = private_key_belongs_to,
.get_fingerprint = _get_fingerprint,
.has_fingerprint = private_key_has_fingerprint,
.get_encoding = _get_encoding,
.get_ref = _get_ref,
.destroy = _destroy,
},
.ref = 1,
);
return this;
}
@@ -493,7 +476,7 @@ gcrypt_rsa_private_key_t *gcrypt_rsa_private_key_gen(key_type_t type,
DBG1(DBG_LIB, "building S-expression failed: %s", gpg_strerror(err));
return NULL;
}
this = gcrypt_rsa_private_key_create_empty();
this = create_empty();
err = gcry_pk_genkey(&this->key, param);
gcry_sexp_release(param);
if (err)
@@ -552,7 +535,7 @@ gcrypt_rsa_private_key_t *gcrypt_rsa_private_key_load(key_type_t type,
break;
}
this = gcrypt_rsa_private_key_create_empty();
this = create_empty();
err = gcry_sexp_build(&this->key, NULL,
"(private-key(rsa(n %b)(e %b)(d %b)(p %b)(q %b)(u %b)))",
n.len, n.ptr, e.len, e.ptr, d.len, d.ptr,
@@ -34,7 +34,7 @@ struct gcrypt_rsa_private_key_t {
/**
* Implements private_key_t interface
*/
private_key_t interface;
private_key_t key;
};
/**
@@ -159,19 +159,15 @@ static bool verify_pkcs1(private_gcrypt_rsa_public_key_t *this,
return TRUE;
}
/**
* Implementation of public_key_t.get_type.
*/
static key_type_t get_type(private_gcrypt_rsa_public_key_t *this)
METHOD(public_key_t, get_type, key_type_t,
private_gcrypt_rsa_public_key_t *this)
{
return KEY_RSA;
}
/**
* Implementation of public_key_t.verify.
*/
static bool verify(private_gcrypt_rsa_public_key_t *this,
signature_scheme_t scheme, chunk_t data, chunk_t signature)
METHOD(public_key_t, verify, bool,
private_gcrypt_rsa_public_key_t *this, signature_scheme_t scheme,
chunk_t data, chunk_t signature)
{
switch (scheme)
{
@@ -196,11 +192,8 @@ static bool verify(private_gcrypt_rsa_public_key_t *this,
}
}
/**
* Implementation of public_key_t.encrypt.
*/
static bool encrypt_(private_gcrypt_rsa_public_key_t *this, chunk_t plain,
chunk_t *encrypted)
METHOD(public_key_t, encrypt_, bool,
private_gcrypt_rsa_public_key_t *this, chunk_t plain, chunk_t *encrypted)
{
gcry_sexp_t in, out;
gcry_error_t err;
@@ -228,19 +221,15 @@ static bool encrypt_(private_gcrypt_rsa_public_key_t *this, chunk_t plain,
return !!encrypted->len;
}
/**
* Implementation of public_key_t.get_keysize.
*/
static size_t get_keysize(private_gcrypt_rsa_public_key_t *this)
METHOD(public_key_t, get_keysize, size_t,
private_gcrypt_rsa_public_key_t *this)
{
return gcry_pk_get_nbits(this->key) / 8;
}
/**
* Implementation of private_key_t.get_encoding
*/
static bool get_encoding(private_gcrypt_rsa_public_key_t *this,
cred_encoding_type_t type, chunk_t *encoding)
METHOD(public_key_t, get_encoding, bool,
private_gcrypt_rsa_public_key_t *this, cred_encoding_type_t type,
chunk_t *encoding)
{
chunk_t n, e;
bool success;
@@ -256,11 +245,9 @@ static bool get_encoding(private_gcrypt_rsa_public_key_t *this,
return success;
}
/**
* Implementation of private_key_t.get_fingerprint
*/
static bool get_fingerprint(private_gcrypt_rsa_public_key_t *this,
cred_encoding_type_t type, chunk_t *fp)
METHOD(public_key_t, get_fingerprint, bool,
private_gcrypt_rsa_public_key_t *this, cred_encoding_type_t type,
chunk_t *fp)
{
chunk_t n, e;
bool success;
@@ -280,19 +267,15 @@ static bool get_fingerprint(private_gcrypt_rsa_public_key_t *this,
return success;
}
/**
* Implementation of public_key_t.get_ref.
*/
static public_key_t* get_ref(private_gcrypt_rsa_public_key_t *this)
METHOD(public_key_t, get_ref, public_key_t*,
private_gcrypt_rsa_public_key_t *this)
{
ref_get(&this->ref);
return &this->public.interface;
return &this->public.key;
}
/**
* Implementation of gcrypt_rsa_public_key.destroy.
*/
static void destroy(private_gcrypt_rsa_public_key_t *this)
METHOD(public_key_t, destroy, void,
private_gcrypt_rsa_public_key_t *this)
{
if (ref_put(&this->ref))
{
@@ -331,21 +314,21 @@ gcrypt_rsa_public_key_t *gcrypt_rsa_public_key_load(key_type_t type,
break;
}
this = malloc_thing(private_gcrypt_rsa_public_key_t);
this->public.interface.get_type = (key_type_t (*)(public_key_t *this))get_type;
this->public.interface.verify = (bool (*)(public_key_t *this, signature_scheme_t scheme, chunk_t data, chunk_t signature))verify;
this->public.interface.encrypt = (bool (*)(public_key_t *this, chunk_t crypto, chunk_t *plain))encrypt_;
this->public.interface.equals = public_key_equals;
this->public.interface.get_keysize = (size_t (*) (public_key_t *this))get_keysize;
this->public.interface.get_fingerprint = (bool(*)(public_key_t*, cred_encoding_type_t type, chunk_t *fp))get_fingerprint;
this->public.interface.has_fingerprint = (bool(*)(public_key_t*, chunk_t fp))public_key_has_fingerprint;
this->public.interface.get_encoding = (bool(*)(public_key_t*, cred_encoding_type_t type, chunk_t *encoding))get_encoding;
this->public.interface.get_ref = (public_key_t* (*)(public_key_t *this))get_ref;
this->public.interface.destroy = (void (*)(public_key_t *this))destroy;
this->key = NULL;
this->ref = 1;
INIT(this,
.public.key = {
.get_type = _get_type,
.verify = _verify,
.encrypt = _encrypt_,
.equals = public_key_equals,
.get_keysize = _get_keysize,
.get_fingerprint = _get_fingerprint,
.has_fingerprint = public_key_has_fingerprint,
.get_encoding = _get_encoding,
.get_ref = _get_ref,
.destroy = _destroy,
},
.ref = 1,
);
err = gcry_sexp_build(&this->key, NULL, "(public-key(rsa(n %b)(e %b)))",
n.len, n.ptr, e.len, e.ptr);
@@ -34,7 +34,7 @@ struct gcrypt_rsa_public_key_t {
/**
* Implements the public_key_t interface
*/
public_key_t interface;
public_key_t key;
};
/**