return NULL;
}
-static void crypt(private_openssl_crypter_t *this, chunk_t data,
- chunk_t iv, chunk_t *dst, int enc)
+/**
+ * Do the actual en/decryption in an EVP context
+ */
+static void crypt(private_openssl_crypter_t *this, chunk_t data, chunk_t iv,
+ chunk_t *dst, int enc)
{
int len;
u_char *out;
EVP_CIPHER_CTX_cleanup(&ctx);
}
-/**
- * Implementation of crypter_t.decrypt.
- */
-static void decrypt(private_openssl_crypter_t *this, chunk_t data,
- chunk_t iv, chunk_t *dst)
+METHOD(crypter_t, decrypt, void,
+ private_openssl_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *dst)
{
crypt(this, data, iv, dst, 0);
}
-
-/**
- * Implementation of crypter_t.encrypt.
- */
-static void encrypt (private_openssl_crypter_t *this, chunk_t data,
- chunk_t iv, chunk_t *dst)
+METHOD(crypter_t, encrypt, void,
+ private_openssl_crypter_t *this, chunk_t data, chunk_t iv, chunk_t *dst)
{
crypt(this, data, iv, dst, 1);
}
-/**
- * Implementation of crypter_t.get_block_size.
- */
-static size_t get_block_size(private_openssl_crypter_t *this)
+METHOD(crypter_t, get_block_size, size_t,
+ private_openssl_crypter_t *this)
{
return this->cipher->block_size;
}
-/**
- * Implementation of crypter_t.get_key_size.
- */
-static size_t get_key_size(private_openssl_crypter_t *this)
+METHOD(crypter_t, get_key_size, size_t,
+ private_openssl_crypter_t *this)
{
return this->key.len;
}
-/**
- * Implementation of crypter_t.set_key.
- */
-static void set_key(private_openssl_crypter_t *this, chunk_t key)
+METHOD(crypter_t, set_key, void,
+ private_openssl_crypter_t *this, chunk_t key)
{
memcpy(this->key.ptr, key.ptr, min(key.len, this->key.len));
}
-/**
- * Implementation of crypter_t.destroy.
- */
-static void destroy (private_openssl_crypter_t *this)
+METHOD(crypter_t, destroy, void,
+ private_openssl_crypter_t *this)
{
free(this->key.ptr);
free(this);
{
private_openssl_crypter_t *this;
- this = malloc_thing(private_openssl_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,
+ },
+ );
switch (algo)
{
this->key = chunk_alloc(key_size);
- 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;
}
struct openssl_crypter_t {
/**
- * The crypter_t interface.
+ * Implements crypter_t interface.
*/
- crypter_t crypter_interface;
+ crypter_t crypter;
};
/**
bool computed;
};
-/**
- * Implementation of openssl_diffie_hellman_t.get_my_public_value.
- */
-static void get_my_public_value(private_openssl_diffie_hellman_t *this,
- chunk_t *value)
+METHOD(diffie_hellman_t, get_my_public_value, void,
+ private_openssl_diffie_hellman_t *this, chunk_t *value)
{
*value = chunk_alloc(DH_size(this->dh));
memset(value->ptr, 0, value->len);
value->ptr + value->len - BN_num_bytes(this->dh->pub_key));
}
-/**
- * Implementation of openssl_diffie_hellman_t.get_shared_secret.
- */
-static status_t get_shared_secret(private_openssl_diffie_hellman_t *this,
- chunk_t *secret)
+METHOD(diffie_hellman_t, get_shared_secret, status_t,
+ private_openssl_diffie_hellman_t *this, chunk_t *secret)
{
if (!this->computed)
{
}
-/**
- * Implementation of openssl_diffie_hellman_t.set_other_public_value.
- */
-static void set_other_public_value(private_openssl_diffie_hellman_t *this,
- chunk_t value)
+METHOD(diffie_hellman_t, set_other_public_value, void,
+ private_openssl_diffie_hellman_t *this, chunk_t value)
{
int len;
this->computed = TRUE;
}
-/**
- * Implementation of openssl_diffie_hellman_t.get_dh_group.
- */
-static diffie_hellman_group_t get_dh_group(private_openssl_diffie_hellman_t *this)
+METHOD(diffie_hellman_t, get_dh_group, diffie_hellman_group_t,
+ private_openssl_diffie_hellman_t *this)
{
return this->group;
}
return SUCCESS;
}
-/**
- * Implementation of openssl_diffie_hellman_t.destroy.
- */
-static void destroy(private_openssl_diffie_hellman_t *this)
+METHOD(diffie_hellman_t, destroy, void,
+ private_openssl_diffie_hellman_t *this)
{
BN_clear_free(this->pub_key);
DH_free(this->dh);
*/
openssl_diffie_hellman_t *openssl_diffie_hellman_create(diffie_hellman_group_t group)
{
- private_openssl_diffie_hellman_t *this = malloc_thing(private_openssl_diffie_hellman_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;
+ private_openssl_diffie_hellman_t *this;
+
+ 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,
+ },
+ );
this->dh = DH_new();
if (!this->dh)
* of the Diffie-Hellman shared secret value is the same as that of the
* Diffie-Hellman public value."
*/
-static bool compute_shared_key(private_openssl_ec_diffie_hellman_t *this, chunk_t *shared_secret)
+static bool compute_shared_key(private_openssl_ec_diffie_hellman_t *this,
+ chunk_t *shared_secret)
{
const BIGNUM *priv_key;
EC_POINT *secret = NULL;
return ret;
}
-/**
- * Implementation of openssl_ec_diffie_hellman_t.set_other_public_value.
- */
-static void set_other_public_value(private_openssl_ec_diffie_hellman_t *this, chunk_t value)
+METHOD(diffie_hellman_t, set_other_public_value, void,
+ private_openssl_ec_diffie_hellman_t *this, chunk_t value)
{
if (!chunk2ecp(this->ec_group, value, this->pub_key))
{
this->computed = TRUE;
}
-/**
- * Implementation of openssl_ec_diffie_hellman_t.get_my_public_value.
- */
-static void get_my_public_value(private_openssl_ec_diffie_hellman_t *this,chunk_t *value)
+METHOD(diffie_hellman_t, get_my_public_value, void,
+ private_openssl_ec_diffie_hellman_t *this,chunk_t *value)
{
ecp2chunk(this->ec_group, EC_KEY_get0_public_key(this->key), value, FALSE);
}
-/**
- * Implementation of openssl_ec_diffie_hellman_t.get_shared_secret.
- */
-static status_t get_shared_secret(private_openssl_ec_diffie_hellman_t *this, chunk_t *secret)
+METHOD(diffie_hellman_t, get_shared_secret, status_t,
+ private_openssl_ec_diffie_hellman_t *this, chunk_t *secret)
{
if (!this->computed)
{
return SUCCESS;
}
-/**
- * Implementation of openssl_ec_diffie_hellman_t.get_dh_group.
- */
-static diffie_hellman_group_t get_dh_group(private_openssl_ec_diffie_hellman_t *this)
+METHOD(diffie_hellman_t, get_dh_group, diffie_hellman_group_t,
+ private_openssl_ec_diffie_hellman_t *this)
{
return this->group;
}
-/**
- * Implementation of openssl_ec_diffie_hellman_t.destroy.
- */
-static void destroy(private_openssl_ec_diffie_hellman_t *this)
+METHOD(diffie_hellman_t, destroy, void,
+ private_openssl_ec_diffie_hellman_t *this)
{
EC_POINT_clear_free(this->pub_key);
EC_KEY_free(this->key);
*/
openssl_ec_diffie_hellman_t *openssl_ec_diffie_hellman_create(diffie_hellman_group_t group)
{
- private_openssl_ec_diffie_hellman_t *this = malloc_thing(private_openssl_ec_diffie_hellman_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;
+ private_openssl_ec_diffie_hellman_t *this;
+
+ 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,
+ );
switch (group)
{
return NULL;
}
- this->group = group;
- this->computed = FALSE;
-
- this->shared_secret = chunk_empty;
-
return &this->public;
}
#endif /* OPENSSL_NO_EC */
return built;
}
-/**
- * Implementation of private_key_t.sign.
- */
-static bool sign(private_openssl_ec_private_key_t *this,
- signature_scheme_t scheme, chunk_t data, chunk_t *signature)
+METHOD(private_key_t, sign, bool,
+ private_openssl_ec_private_key_t *this, signature_scheme_t scheme,
+ chunk_t data, chunk_t *signature)
{
switch (scheme)
{
}
}
-/**
- * Implementation of private_key_t.destroy.
- */
-static bool decrypt(private_openssl_ec_private_key_t *this,
- chunk_t crypto, chunk_t *plain)
+METHOD(private_key_t, decrypt, bool,
+ private_openssl_ec_private_key_t *this, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EC private key decryption not implemented");
return FALSE;
}
-/**
- * Implementation of private_key_t.get_keysize.
- */
-static size_t get_keysize(private_openssl_ec_private_key_t *this)
+METHOD(private_key_t, get_keysize, size_t,
+ private_openssl_ec_private_key_t *this)
{
return EC_FIELD_ELEMENT_LEN(EC_KEY_get0_group(this->ec));
}
-/**
- * Implementation of private_key_t.get_type.
- */
-static key_type_t get_type(private_openssl_ec_private_key_t *this)
+METHOD(private_key_t, get_type, key_type_t,
+ private_openssl_ec_private_key_t *this)
{
return KEY_ECDSA;
}
-/**
- * Implementation of private_key_t.get_public_key.
- */
-static public_key_t* get_public_key(private_openssl_ec_private_key_t *this)
+METHOD(private_key_t, get_public_key, public_key_t*,
+ private_openssl_ec_private_key_t *this)
{
public_key_t *public;
chunk_t key;
return public;
}
-/**
- * Implementation of private_key_t.get_fingerprint.
- */
-static bool get_fingerprint(private_openssl_ec_private_key_t *this,
- cred_encoding_type_t type, chunk_t *fingerprint)
+METHOD(private_key_t, get_fingerprint, bool,
+ private_openssl_ec_private_key_t *this, cred_encoding_type_t type,
+ chunk_t *fingerprint)
{
return openssl_ec_fingerprint(this->ec, type, fingerprint);
}
-/**
- * Implementation of private_key_t.get_encoding.
- */
-static bool get_encoding(private_openssl_ec_private_key_t *this,
- cred_encoding_type_t type, chunk_t *encoding)
+METHOD(private_key_t, get_encoding, bool,
+ private_openssl_ec_private_key_t *this, cred_encoding_type_t type,
+ chunk_t *encoding)
{
u_char *p;
}
}
-/**
- * Implementation of private_key_t.get_ref.
- */
-static private_key_t* get_ref(private_openssl_ec_private_key_t *this)
+METHOD(private_key_t, get_ref, private_key_t*,
+ private_openssl_ec_private_key_t *this)
{
ref_get(&this->ref);
- return &this->public.interface;
+ return &this->public.key;
}
-/**
- * Implementation of private_key_t.destroy.
- */
-static void destroy(private_openssl_ec_private_key_t *this)
+METHOD(private_key_t, destroy, void,
+ private_openssl_ec_private_key_t *this)
{
if (ref_put(&this->ref))
{
*/
static private_openssl_ec_private_key_t *create_empty(void)
{
- private_openssl_ec_private_key_t *this = malloc_thing(private_openssl_ec_private_key_t);
-
- 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->ec = NULL;
- this->ref = 1;
+ private_openssl_ec_private_key_t *this;
+
+ 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;
}
/**
* Implements private_key_t interface
*/
- private_key_t interface;
+ private_key_t key;
};
/**
return valid;
}
-/**
- * Implementation of public_key_t.get_type.
- */
-static key_type_t get_type(private_openssl_ec_public_key_t *this)
+METHOD(public_key_t, get_type, key_type_t,
+ private_openssl_ec_public_key_t *this)
{
return KEY_ECDSA;
}
-/**
- * Implementation of public_key_t.verify.
- */
-static bool verify(private_openssl_ec_public_key_t *this,
- signature_scheme_t scheme, chunk_t data, chunk_t signature)
+METHOD(public_key_t, verify, bool,
+ private_openssl_ec_public_key_t *this, signature_scheme_t scheme,
+ chunk_t data, chunk_t signature)
{
switch (scheme)
{
}
}
-/**
- * Implementation of public_key_t.get_keysize.
- */
-static bool encrypt_(private_openssl_ec_public_key_t *this,
- chunk_t crypto, chunk_t *plain)
+METHOD(public_key_t, encrypt, bool,
+ private_openssl_ec_public_key_t *this, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EC public key encryption not implemented");
return FALSE;
}
-/**
- * Implementation of public_key_t.get_keysize.
- */
-static size_t get_keysize(private_openssl_ec_public_key_t *this)
+METHOD(public_key_t, get_keysize, size_t,
+ private_openssl_ec_public_key_t *this)
{
return EC_FIELD_ELEMENT_LEN(EC_KEY_get0_group(this->ec));
}
return TRUE;
}
-/**
- * Implementation of private_key_t.get_fingerprint.
- */
-static bool get_fingerprint(private_openssl_ec_public_key_t *this,
- cred_encoding_type_t type, chunk_t *fingerprint)
+METHOD(public_key_t, get_fingerprint, bool,
+ private_openssl_ec_public_key_t *this, cred_encoding_type_t type,
+ chunk_t *fingerprint)
{
return openssl_ec_fingerprint(this->ec, type, fingerprint);
}
-/**
- * Implementation of private_key_t.get_encoding.
- */
-static bool get_encoding(private_openssl_ec_public_key_t *this,
- cred_encoding_type_t type, chunk_t *encoding)
+METHOD(public_key_t, get_encoding, bool,
+ private_openssl_ec_public_key_t *this, cred_encoding_type_t type,
+ chunk_t *encoding)
{
u_char *p;
}
}
-/**
- * Implementation of public_key_t.get_ref.
- */
-static public_key_t* get_ref(private_openssl_ec_public_key_t *this)
+METHOD(public_key_t, get_ref, public_key_t*,
+ private_openssl_ec_public_key_t *this)
{
ref_get(&this->ref);
- return &this->public.interface;
+ return &this->public.key;
}
-/**
- * Implementation of openssl_ec_public_key.destroy.
- */
-static void destroy(private_openssl_ec_public_key_t *this)
+METHOD(public_key_t, destroy, void,
+ private_openssl_ec_public_key_t *this)
{
if (ref_put(&this->ref))
{
*/
static private_openssl_ec_public_key_t *create_empty()
{
- private_openssl_ec_public_key_t *this = malloc_thing(private_openssl_ec_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.get_keysize = (size_t (*) (public_key_t *this))get_keysize;
- this->public.interface.equals = public_key_equals;
- 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->ec = NULL;
- this->ref = 1;
+ private_openssl_ec_public_key_t *this;
+
+ INIT(this,
+ .public.key = {
+ .get_type = _get_type,
+ .verify = _verify,
+ .encrypt = _encrypt,
+ .get_keysize = _get_keysize,
+ .equals = public_key_equals,
+ .get_fingerprint = _get_fingerprint,
+ .has_fingerprint = public_key_has_fingerprint,
+ .get_encoding = _get_encoding,
+ .get_ref = _get_ref,
+ .destroy = _destroy,
+ },
+ .ref = 1,
+ );
return this;
}
/**
* Implements the public_key_t interface
*/
- public_key_t interface;
+ public_key_t key;
};
/**
return NULL;
}
-/**
- * Implementation of hasher_t.get_hash_size.
- */
-static size_t get_hash_size(private_openssl_hasher_t *this)
+METHOD(hasher_t, get_hash_size, size_t,
+ private_openssl_hasher_t *this)
{
return this->hasher->md_size;
}
-/**
- * Implementation of hasher_t.reset.
- */
-static void reset(private_openssl_hasher_t *this)
+METHOD(hasher_t, reset, void,
+ private_openssl_hasher_t *this)
{
EVP_DigestInit_ex(this->ctx, this->hasher, NULL);
}
-/**
- * Implementation of hasher_t.get_hash.
- */
-static void get_hash(private_openssl_hasher_t *this, chunk_t chunk,
- u_int8_t *hash)
+METHOD(hasher_t, get_hash, void,
+ private_openssl_hasher_t *this, chunk_t chunk, u_int8_t *hash)
{
EVP_DigestUpdate(this->ctx, chunk.ptr, chunk.len);
if (hash)
}
}
-/**
- * Implementation of hasher_t.allocate_hash.
- */
-static void allocate_hash(private_openssl_hasher_t *this, chunk_t chunk,
- chunk_t *hash)
+METHOD(hasher_t, allocate_hash, void,
+ private_openssl_hasher_t *this, chunk_t chunk, chunk_t *hash)
{
if (hash)
{
}
}
-/**
- * Implementation of hasher_t.destroy.
- */
-static void destroy (private_openssl_hasher_t *this)
+METHOD(hasher_t, destroy, void,
+ private_openssl_hasher_t *this)
{
EVP_MD_CTX_destroy(this->ctx);
free(this);
return NULL;
}
- this = malloc_thing(private_openssl_hasher_t);
+ INIT(this,
+ .public.hasher = {
+ .get_hash = _get_hash,
+ .allocate_hash = _allocate_hash,
+ .get_hash_size = _get_hash_size,
+ .reset = _reset,
+ .destroy = _destroy,
+ },
+ );
this->hasher = EVP_get_digestbyname(name);
if (!this->hasher)
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;
-
this->ctx = EVP_MD_CTX_create();
/* initialization */
struct openssl_hasher_t {
/**
- * The hasher_t interface.
+ * Implements hasher_t interface.
*/
- hasher_t hasher_interface;
+ hasher_t hasher;
};
/**
mutex = NULL;
}
-/**
- * Implementation of openssl_plugin_t.destroy
- */
-static void destroy(private_openssl_plugin_t *this)
+METHOD(plugin_t, destroy, void,
+ private_openssl_plugin_t *this)
{
lib->crypto->remove_crypter(lib->crypto,
(crypter_constructor_t)openssl_crypter_create);
*/
plugin_t *openssl_plugin_create()
{
- private_openssl_plugin_t *this = malloc_thing(private_openssl_plugin_t);
+ private_openssl_plugin_t *this;
- this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+ INIT(this,
+ .public.plugin.destroy = _destroy,
+ );
threading_init();
return success;
}
-/**
- * Implementation of openssl_rsa_private_key.get_type.
- */
-static key_type_t get_type(private_openssl_rsa_private_key_t *this)
+
+METHOD(private_key_t, get_type, key_type_t,
+ private_openssl_rsa_private_key_t *this)
{
return KEY_RSA;
}
-/**
- * Implementation of openssl_rsa_private_key.sign.
- */
-static bool sign(private_openssl_rsa_private_key_t *this, signature_scheme_t scheme,
- chunk_t data, chunk_t *signature)
+METHOD(private_key_t, sign, bool,
+ private_openssl_rsa_private_key_t *this, signature_scheme_t scheme,
+ chunk_t data, chunk_t *signature)
{
switch (scheme)
{
}
}
-/**
- * Implementation of openssl_rsa_private_key.decrypt.
- */
-static bool decrypt(private_openssl_rsa_private_key_t *this,
- chunk_t crypto, chunk_t *plain)
+METHOD(private_key_t, decrypt, bool,
+ private_openssl_rsa_private_key_t *this, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "RSA private key decryption not implemented");
return FALSE;
}
-/**
- * Implementation of openssl_rsa_private_key.get_keysize.
- */
-static size_t get_keysize(private_openssl_rsa_private_key_t *this)
+METHOD(private_key_t, get_keysize, size_t,
+ private_openssl_rsa_private_key_t *this)
{
return RSA_size(this->rsa);
}
-/**
- * Implementation of openssl_rsa_private_key.get_public_key.
- */
-static public_key_t* get_public_key(private_openssl_rsa_private_key_t *this)
+METHOD(private_key_t, get_public_key, public_key_t*,
+ private_openssl_rsa_private_key_t *this)
{
chunk_t enc;
public_key_t *key;
return key;
}
-/**
- * Implementation of public_key_t.get_fingerprint.
- */
-static bool get_fingerprint(private_openssl_rsa_private_key_t *this,
- cred_encoding_type_t type, chunk_t *fingerprint)
+METHOD(private_key_t, get_fingerprint, bool,
+ private_openssl_rsa_private_key_t *this, cred_encoding_type_t type,
+ chunk_t *fingerprint)
{
return openssl_rsa_fingerprint(this->rsa, type, fingerprint);
}
-/*
- * Implementation of public_key_t.get_encoding.
- */
-static bool get_encoding(private_openssl_rsa_private_key_t *this,
- cred_encoding_type_t type, chunk_t *encoding)
+METHOD(private_key_t, get_encoding, bool,
+ private_openssl_rsa_private_key_t *this, cred_encoding_type_t type,
+ chunk_t *encoding)
{
u_char *p;
}
}
-/**
- * Implementation of openssl_rsa_private_key.get_ref.
- */
-static private_openssl_rsa_private_key_t* get_ref(private_openssl_rsa_private_key_t *this)
+METHOD(private_key_t, get_ref, private_key_t*,
+ private_openssl_rsa_private_key_t *this)
{
ref_get(&this->ref);
- return this;
+ return &this->public.key;
}
-/**
- * Implementation of openssl_rsa_private_key.destroy.
- */
-static void destroy(private_openssl_rsa_private_key_t *this)
+METHOD(private_key_t, destroy, void,
+ private_openssl_rsa_private_key_t *this)
{
if (ref_put(&this->ref))
{
/**
* Internal generic constructor
*/
-static private_openssl_rsa_private_key_t *create_empty(void)
+static private_openssl_rsa_private_key_t *create_empty()
{
- private_openssl_rsa_private_key_t *this = malloc_thing(private_openssl_rsa_private_key_t);
-
- this->public.interface.get_type = (key_type_t (*) (private_key_t*))get_type;
- this->public.interface.sign = (bool (*) (private_key_t*, signature_scheme_t, chunk_t, chunk_t*))sign;
- this->public.interface.decrypt = (bool (*) (private_key_t*, chunk_t, chunk_t*))decrypt;
- this->public.interface.get_keysize = (size_t (*) (private_key_t*))get_keysize;
- this->public.interface.get_public_key = (public_key_t* (*) (private_key_t*))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*))get_ref;
- this->public.interface.destroy = (void (*) (private_key_t*))destroy;
-
- this->engine = FALSE;
- this->ref = 1;
+ private_openssl_rsa_private_key_t *this;
+
+ 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;
}
/**
* Implements private_key_t interface
*/
- private_key_t interface;
+ private_key_t key;
};
/**
return valid;
}
-/**
- * Implementation of public_key_t.get_type.
- */
-static key_type_t get_type(private_openssl_rsa_public_key_t *this)
+METHOD(public_key_t, get_type, key_type_t,
+ private_openssl_rsa_public_key_t *this)
{
return KEY_RSA;
}
-/**
- * Implementation of public_key_t.verify.
- */
-static bool verify(private_openssl_rsa_public_key_t *this, signature_scheme_t scheme,
- chunk_t data, chunk_t signature)
+METHOD(public_key_t, verify, bool,
+ private_openssl_rsa_public_key_t *this, signature_scheme_t scheme,
+ chunk_t data, chunk_t signature)
{
switch (scheme)
{
}
}
-/**
- * Implementation of public_key_t.get_keysize.
- */
-static bool encrypt_(private_openssl_rsa_public_key_t *this,
- chunk_t crypto, chunk_t *plain)
+METHOD(public_key_t, encrypt, bool,
+ private_openssl_rsa_public_key_t *this, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "RSA public key encryption not implemented");
return FALSE;
}
-/**
- * Implementation of public_key_t.get_keysize.
- */
-static size_t get_keysize(private_openssl_rsa_public_key_t *this)
+METHOD(public_key_t, get_keysize, size_t,
+ private_openssl_rsa_public_key_t *this)
{
return RSA_size(this->rsa);
}
return TRUE;
}
-/**
- * Implementation of public_key_t.get_fingerprint.
- */
-static bool get_fingerprint(private_openssl_rsa_public_key_t *this,
- cred_encoding_type_t type, chunk_t *fingerprint)
+METHOD(public_key_t, get_fingerprint, bool,
+ private_openssl_rsa_public_key_t *this, cred_encoding_type_t type,
+ chunk_t *fingerprint)
{
return openssl_rsa_fingerprint(this->rsa, type, fingerprint);
}
-/*
- * Implementation of public_key_t.get_encoding.
- */
-static bool get_encoding(private_openssl_rsa_public_key_t *this,
- cred_encoding_type_t type, chunk_t *encoding)
+METHOD(public_key_t, get_encoding, bool,
+ private_openssl_rsa_public_key_t *this, cred_encoding_type_t type,
+ chunk_t *encoding)
{
u_char *p;
}
}
-/**
- * Implementation of public_key_t.get_ref.
- */
-static public_key_t* get_ref(private_openssl_rsa_public_key_t *this)
+METHOD(public_key_t, get_ref, public_key_t*,
+ private_openssl_rsa_public_key_t *this)
{
ref_get(&this->ref);
- return &this->public.interface;
+ return &this->public.key;
}
-/**
- * Implementation of openssl_rsa_public_key.destroy.
- */
-static void destroy(private_openssl_rsa_public_key_t *this)
+METHOD(public_key_t, destroy, void,
+ private_openssl_rsa_public_key_t *this)
{
if (ref_put(&this->ref))
{
*/
static private_openssl_rsa_public_key_t *create_empty()
{
- private_openssl_rsa_public_key_t *this = malloc_thing(private_openssl_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->rsa = NULL;
- this->ref = 1;
+ private_openssl_rsa_public_key_t *this;
+
+ 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,
+ );
return this;
}
/**
* Implements the public_key_t interface
*/
- public_key_t interface;
+ public_key_t key;
};
/**