removed trailing spaces ([[:space:]]+$)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Tobias Brunner
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
@@ -23,17 +23,17 @@ typedef struct private_openssl_crypter_t private_openssl_crypter_t;
|
||||
* Private data of openssl_crypter_t
|
||||
*/
|
||||
struct private_openssl_crypter_t {
|
||||
|
||||
|
||||
/**
|
||||
* Public part of this class.
|
||||
*/
|
||||
openssl_crypter_t public;
|
||||
|
||||
|
||||
/*
|
||||
* the key
|
||||
*/
|
||||
chunk_t key;
|
||||
|
||||
|
||||
/*
|
||||
* the cipher to use
|
||||
*/
|
||||
@@ -49,17 +49,17 @@ typedef struct {
|
||||
* Identifier specified in IKEv2
|
||||
*/
|
||||
int ikev2_id;
|
||||
|
||||
|
||||
/**
|
||||
* Name of the algorithm, as used in OpenSSL
|
||||
*/
|
||||
char *name;
|
||||
|
||||
|
||||
/**
|
||||
* Minimum valid key length in bytes
|
||||
*/
|
||||
size_t key_size_min;
|
||||
|
||||
|
||||
/**
|
||||
* Maximum valid key length in bytes
|
||||
*/
|
||||
@@ -91,7 +91,7 @@ static openssl_algorithm_t encryption_algs[] = {
|
||||
/**
|
||||
* Look up an OpenSSL algorithm name and validate its key size
|
||||
*/
|
||||
static char* lookup_algorithm(openssl_algorithm_t *openssl_algo,
|
||||
static char* lookup_algorithm(openssl_algorithm_t *openssl_algo,
|
||||
u_int16_t ikev2_algo, size_t *key_size)
|
||||
{
|
||||
while (openssl_algo->ikev2_id != END_OF_LIST)
|
||||
@@ -104,7 +104,7 @@ static char* lookup_algorithm(openssl_algorithm_t *openssl_algo,
|
||||
{
|
||||
*key_size = openssl_algo->key_size_min;
|
||||
}
|
||||
|
||||
|
||||
/* validate key size */
|
||||
if (*key_size < openssl_algo->key_size_min ||
|
||||
*key_size > openssl_algo->key_size_max)
|
||||
@@ -123,7 +123,7 @@ static void crypt(private_openssl_crypter_t *this, chunk_t data,
|
||||
{
|
||||
int len;
|
||||
u_char *out;
|
||||
|
||||
|
||||
out = data.ptr;
|
||||
if (dst)
|
||||
{
|
||||
@@ -144,7 +144,7 @@ static void crypt(private_openssl_crypter_t *this, chunk_t data,
|
||||
/**
|
||||
* Implementation of crypter_t.decrypt.
|
||||
*/
|
||||
static void decrypt(private_openssl_crypter_t *this, chunk_t data,
|
||||
static void decrypt(private_openssl_crypter_t *this, chunk_t data,
|
||||
chunk_t iv, chunk_t *dst)
|
||||
{
|
||||
crypt(this, data, iv, dst, 0);
|
||||
@@ -154,7 +154,7 @@ static void decrypt(private_openssl_crypter_t *this, chunk_t data,
|
||||
/**
|
||||
* Implementation of crypter_t.encrypt.
|
||||
*/
|
||||
static void encrypt (private_openssl_crypter_t *this, chunk_t data,
|
||||
static void encrypt (private_openssl_crypter_t *this, chunk_t data,
|
||||
chunk_t iv, chunk_t *dst)
|
||||
{
|
||||
crypt(this, data, iv, dst, 1);
|
||||
@@ -196,13 +196,13 @@ static void destroy (private_openssl_crypter_t *this)
|
||||
/*
|
||||
* Described in header
|
||||
*/
|
||||
openssl_crypter_t *openssl_crypter_create(encryption_algorithm_t algo,
|
||||
openssl_crypter_t *openssl_crypter_create(encryption_algorithm_t algo,
|
||||
size_t key_size)
|
||||
{
|
||||
private_openssl_crypter_t *this;
|
||||
|
||||
|
||||
this = malloc_thing(private_openssl_crypter_t);
|
||||
|
||||
|
||||
switch (algo)
|
||||
{
|
||||
case ENCR_NULL:
|
||||
@@ -218,7 +218,7 @@ openssl_crypter_t *openssl_crypter_create(encryption_algorithm_t algo,
|
||||
this->cipher = EVP_get_cipherbyname("aes192");
|
||||
break;
|
||||
case 32: /* AES-256 */
|
||||
this->cipher = EVP_get_cipherbyname("aes256");
|
||||
this->cipher = EVP_get_cipherbyname("aes256");
|
||||
break;
|
||||
default:
|
||||
free(this);
|
||||
@@ -235,7 +235,7 @@ openssl_crypter_t *openssl_crypter_create(encryption_algorithm_t algo,
|
||||
this->cipher = EVP_get_cipherbyname("camellia192");
|
||||
break;
|
||||
case 32: /* CAMELLIA 256 */
|
||||
this->cipher = EVP_get_cipherbyname("camellia256");
|
||||
this->cipher = EVP_get_cipherbyname("camellia256");
|
||||
break;
|
||||
default:
|
||||
free(this);
|
||||
@@ -258,22 +258,22 @@ openssl_crypter_t *openssl_crypter_create(encryption_algorithm_t algo,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!this->cipher)
|
||||
{
|
||||
/* OpenSSL does not support the requested algo */
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ typedef struct openssl_crypter_t openssl_crypter_t;
|
||||
* Implementation of crypters using OpenSSL.
|
||||
*/
|
||||
struct openssl_crypter_t {
|
||||
|
||||
|
||||
/**
|
||||
* The crypter_t interface.
|
||||
*/
|
||||
@@ -38,7 +38,7 @@ struct openssl_crypter_t {
|
||||
|
||||
/**
|
||||
* Constructor to create openssl_crypter_t.
|
||||
*
|
||||
*
|
||||
* @param algo algorithm to implement
|
||||
* @param key_size key size in bytes
|
||||
* @return openssl_crypter_t, NULL if not supported
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
typedef struct modulus_entry_t modulus_entry_t;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Entry of the modulus list.
|
||||
*/
|
||||
struct modulus_entry_t {
|
||||
@@ -30,20 +30,20 @@ struct modulus_entry_t {
|
||||
* Group number as it is defined in file transform_substructure.h.
|
||||
*/
|
||||
diffie_hellman_group_t group;
|
||||
|
||||
|
||||
/**
|
||||
* Pointer to the function to get the modulus.
|
||||
*/
|
||||
BIGNUM *(*get_prime)(BIGNUM *bn);
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* Optimum length of exponent in bits.
|
||||
*/
|
||||
*/
|
||||
long opt_exponent_len;
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* Generator value.
|
||||
*/
|
||||
*/
|
||||
u_int16_t generator;
|
||||
};
|
||||
|
||||
@@ -71,27 +71,27 @@ struct private_openssl_diffie_hellman_t {
|
||||
* Public openssl_diffie_hellman_t interface.
|
||||
*/
|
||||
openssl_diffie_hellman_t public;
|
||||
|
||||
|
||||
/**
|
||||
* Diffie Hellman group number.
|
||||
*/
|
||||
u_int16_t group;
|
||||
|
||||
|
||||
/**
|
||||
* Diffie Hellman object
|
||||
*/
|
||||
DH *dh;
|
||||
|
||||
|
||||
/**
|
||||
* Other public value
|
||||
*/
|
||||
BIGNUM *pub_key;
|
||||
|
||||
|
||||
/**
|
||||
* Shared secret
|
||||
*/
|
||||
chunk_t shared_secret;
|
||||
|
||||
|
||||
/**
|
||||
* True if shared secret is computed
|
||||
*/
|
||||
@@ -123,7 +123,7 @@ static status_t get_shared_secret(private_openssl_diffie_hellman_t *this,
|
||||
/* shared secret should requires a len according the DH group */
|
||||
*secret = chunk_alloc(DH_size(this->dh));
|
||||
memset(secret->ptr, 0, secret->len);
|
||||
memcpy(secret->ptr + secret->len - this->shared_secret.len,
|
||||
memcpy(secret->ptr + secret->len - this->shared_secret.len,
|
||||
this->shared_secret.ptr, this->shared_secret.len);
|
||||
|
||||
return SUCCESS;
|
||||
@@ -137,7 +137,7 @@ static void set_other_public_value(private_openssl_diffie_hellman_t *this,
|
||||
chunk_t value)
|
||||
{
|
||||
int len;
|
||||
|
||||
|
||||
BN_bin2bn(value.ptr, value.len, this->pub_key);
|
||||
chunk_clear(&this->shared_secret);
|
||||
this->shared_secret.ptr = malloc(DH_size(this->dh));
|
||||
@@ -167,10 +167,10 @@ static status_t set_modulus(private_openssl_diffie_hellman_t *this)
|
||||
{
|
||||
int i;
|
||||
bool ansi_x9_42;
|
||||
|
||||
|
||||
ansi_x9_42 = lib->settings->get_bool(lib->settings,
|
||||
"libstrongswan.dh_exponent_ansi_x9_42", TRUE);
|
||||
|
||||
|
||||
for (i = 0; i < (sizeof(modulus_entries) / sizeof(modulus_entry_t)); i++)
|
||||
{
|
||||
if (modulus_entries[i].group == this->group)
|
||||
@@ -205,32 +205,32 @@ static void destroy(private_openssl_diffie_hellman_t *this)
|
||||
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;
|
||||
|
||||
|
||||
this->dh = DH_new();
|
||||
if (!this->dh)
|
||||
{
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
this->group = group;
|
||||
this->computed = FALSE;
|
||||
this->pub_key = BN_new();
|
||||
this->shared_secret = chunk_empty;
|
||||
|
||||
|
||||
/* find a modulus according to group */
|
||||
if (set_modulus(this) != SUCCESS)
|
||||
{
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* generate my public and private values */
|
||||
if (!DH_generate_key(this->dh))
|
||||
{
|
||||
@@ -238,6 +238,6 @@ openssl_diffie_hellman_t *openssl_diffie_hellman_create(diffie_hellman_group_t g
|
||||
return NULL;
|
||||
}
|
||||
DBG2("size of DH secret exponent: %d bits", BN_num_bits(this->dh->priv_key));
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ typedef struct openssl_diffie_hellman_t openssl_diffie_hellman_t;
|
||||
* Implementation of the Diffie-Hellman algorithm using OpenSSL.
|
||||
*/
|
||||
struct openssl_diffie_hellman_t {
|
||||
|
||||
|
||||
/**
|
||||
* Implements diffie_hellman_t interface.
|
||||
*/
|
||||
@@ -38,7 +38,7 @@ struct openssl_diffie_hellman_t {
|
||||
|
||||
/**
|
||||
* Creates a new openssl_diffie_hellman_t object.
|
||||
*
|
||||
*
|
||||
* @param group Diffie Hellman group number to use
|
||||
* @return openssl_diffie_hellman_t object, NULL if not supported
|
||||
*/
|
||||
|
||||
@@ -31,27 +31,27 @@ struct private_openssl_ec_diffie_hellman_t {
|
||||
* Public openssl_ec_diffie_hellman_t interface.
|
||||
*/
|
||||
openssl_ec_diffie_hellman_t public;
|
||||
|
||||
|
||||
/**
|
||||
* Diffie Hellman group number.
|
||||
*/
|
||||
u_int16_t group;
|
||||
|
||||
|
||||
/**
|
||||
* EC private (public) key
|
||||
*/
|
||||
EC_KEY *key;
|
||||
|
||||
|
||||
/**
|
||||
* EC group
|
||||
*/
|
||||
const EC_GROUP *ec_group;
|
||||
|
||||
|
||||
/**
|
||||
* Other public key
|
||||
*/
|
||||
EC_POINT *pub_key;
|
||||
|
||||
|
||||
/**
|
||||
* Shared secret
|
||||
*/
|
||||
@@ -72,13 +72,13 @@ static bool chunk2ecp(const EC_GROUP *group, chunk_t chunk, EC_POINT *point)
|
||||
BN_CTX *ctx;
|
||||
BIGNUM *x, *y;
|
||||
bool ret = FALSE;
|
||||
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (!ctx)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
x = BN_CTX_get(ctx);
|
||||
y = BN_CTX_get(ctx);
|
||||
@@ -86,17 +86,17 @@ static bool chunk2ecp(const EC_GROUP *group, chunk_t chunk, EC_POINT *point)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
if (!openssl_bn_split(chunk, x, y))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
ret = TRUE;
|
||||
error:
|
||||
BN_CTX_end(ctx);
|
||||
@@ -114,13 +114,13 @@ static bool ecp2chunk(const EC_GROUP *group, const EC_POINT *point,
|
||||
BN_CTX *ctx;
|
||||
BIGNUM *x, *y;
|
||||
bool ret = FALSE;
|
||||
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (!ctx)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
x = BN_CTX_get(ctx);
|
||||
y = BN_CTX_get(ctx);
|
||||
@@ -128,12 +128,12 @@ static bool ecp2chunk(const EC_GROUP *group, const EC_POINT *point,
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
if (!EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
if (x_coordinate_only)
|
||||
{
|
||||
y = NULL;
|
||||
@@ -142,7 +142,7 @@ static bool ecp2chunk(const EC_GROUP *group, const EC_POINT *point,
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
ret = TRUE;
|
||||
error:
|
||||
BN_CTX_end(ctx);
|
||||
@@ -152,7 +152,7 @@ error:
|
||||
|
||||
/**
|
||||
* Compute the shared secret.
|
||||
*
|
||||
*
|
||||
* We cannot use the function ECDH_compute_key() because that returns only the
|
||||
* x coordinate of the shared secret point (which is defined, for instance, in
|
||||
* 'NIST SP 800-56A').
|
||||
@@ -166,13 +166,13 @@ static bool compute_shared_key(private_openssl_ec_diffie_hellman_t *this, chunk_
|
||||
const BIGNUM *priv_key;
|
||||
EC_POINT *secret = NULL;
|
||||
bool x_coordinate_only, ret = FALSE;
|
||||
|
||||
|
||||
priv_key = EC_KEY_get0_private_key(this->key);
|
||||
if (!priv_key)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
secret = EC_POINT_new(this->ec_group);
|
||||
if (!secret)
|
||||
{
|
||||
@@ -183,7 +183,7 @@ static bool compute_shared_key(private_openssl_ec_diffie_hellman_t *this, chunk_
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The default setting ecp_x_coordinate_only = TRUE
|
||||
* applies the following errata for RFC 4753:
|
||||
@@ -195,7 +195,7 @@ static bool compute_shared_key(private_openssl_ec_diffie_hellman_t *this, chunk_
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
ret = TRUE;
|
||||
error:
|
||||
if (secret)
|
||||
@@ -215,14 +215,14 @@ static void set_other_public_value(private_openssl_ec_diffie_hellman_t *this, ch
|
||||
DBG1("ECDH public value is malformed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
chunk_free(&this->shared_secret);
|
||||
|
||||
|
||||
if (!compute_shared_key(this, &this->shared_secret)) {
|
||||
DBG1("ECDH shared secret computation failed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this->computed = TRUE;
|
||||
}
|
||||
|
||||
@@ -272,13 +272,13 @@ static void destroy(private_openssl_ec_diffie_hellman_t *this)
|
||||
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;
|
||||
|
||||
|
||||
switch (group)
|
||||
{
|
||||
case ECP_192_BIT:
|
||||
@@ -300,34 +300,34 @@ openssl_ec_diffie_hellman_t *openssl_ec_diffie_hellman_create(diffie_hellman_gro
|
||||
this->key = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!this->key)
|
||||
{
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* caching the EC group */
|
||||
this->ec_group = EC_KEY_get0_group(this->key);
|
||||
|
||||
|
||||
this->pub_key = EC_POINT_new(this->ec_group);
|
||||
if (!this->pub_key)
|
||||
{
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* generate an EC private (public) key */
|
||||
if (!EC_KEY_generate_key(this->key))
|
||||
{
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
this->group = group;
|
||||
this->computed = FALSE;
|
||||
|
||||
|
||||
this->shared_secret = chunk_empty;
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ typedef struct openssl_ec_diffie_hellman_t openssl_ec_diffie_hellman_t;
|
||||
* Implementation of the EC Diffie-Hellman algorithm using OpenSSL.
|
||||
*/
|
||||
struct openssl_ec_diffie_hellman_t {
|
||||
|
||||
|
||||
/**
|
||||
* Implements diffie_hellman_t interface.
|
||||
*/
|
||||
@@ -38,7 +38,7 @@ struct openssl_ec_diffie_hellman_t {
|
||||
|
||||
/**
|
||||
* Creates a new openssl_ec_diffie_hellman_t object.
|
||||
*
|
||||
*
|
||||
* @param group EC Diffie Hellman group number to use
|
||||
* @return openssl_ec_diffie_hellman_t object, NULL if not supported
|
||||
*/
|
||||
|
||||
@@ -34,12 +34,12 @@ struct private_openssl_ec_private_key_t {
|
||||
* Public interface for this signer.
|
||||
*/
|
||||
openssl_ec_private_key_t public;
|
||||
|
||||
|
||||
/**
|
||||
* EC key object
|
||||
*/
|
||||
EC_KEY *ec;
|
||||
|
||||
|
||||
/**
|
||||
* reference count
|
||||
*/
|
||||
@@ -57,7 +57,7 @@ static bool build_signature(private_openssl_ec_private_key_t *this,
|
||||
{
|
||||
bool built = FALSE;
|
||||
ECDSA_SIG *sig;
|
||||
|
||||
|
||||
sig = ECDSA_do_sign(hash.ptr, hash.len, this->ec);
|
||||
if (sig)
|
||||
{
|
||||
@@ -80,7 +80,7 @@ static bool build_curve_signature(private_openssl_ec_private_key_t *this,
|
||||
EC_GROUP *req_group;
|
||||
chunk_t hash;
|
||||
bool built;
|
||||
|
||||
|
||||
req_group = EC_GROUP_new_by_curve_name(nid_curve);
|
||||
if (!req_group)
|
||||
{
|
||||
@@ -114,7 +114,7 @@ static bool build_der_signature(private_openssl_ec_private_key_t *this,
|
||||
chunk_t hash, sig;
|
||||
int siglen = 0;
|
||||
bool built;
|
||||
|
||||
|
||||
if (!openssl_hash_chunk(hash_nid, data, &hash))
|
||||
{
|
||||
return FALSE;
|
||||
@@ -153,7 +153,7 @@ static bool sign(private_openssl_ec_private_key_t *this,
|
||||
case SIGN_ECDSA_WITH_SHA512_DER:
|
||||
return build_der_signature(this, NID_sha512, data, signature);
|
||||
case SIGN_ECDSA_256:
|
||||
return build_curve_signature(this, scheme, NID_sha256,
|
||||
return build_curve_signature(this, scheme, NID_sha256,
|
||||
NID_X9_62_prime256v1, data, signature);
|
||||
case SIGN_ECDSA_384:
|
||||
return build_curve_signature(this, scheme, NID_sha384,
|
||||
@@ -202,11 +202,11 @@ static public_key_t* get_public_key(private_openssl_ec_private_key_t *this)
|
||||
public_key_t *public;
|
||||
chunk_t key;
|
||||
u_char *p;
|
||||
|
||||
|
||||
key = chunk_alloc(i2d_EC_PUBKEY(this->ec, NULL));
|
||||
p = key.ptr;
|
||||
i2d_EC_PUBKEY(this->ec, &p);
|
||||
|
||||
|
||||
public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ECDSA,
|
||||
BUILD_BLOB_ASN1_DER, key, BUILD_END);
|
||||
free(key.ptr);
|
||||
@@ -229,7 +229,7 @@ static bool get_encoding(private_openssl_ec_private_key_t *this,
|
||||
key_encoding_type_t type, chunk_t *encoding)
|
||||
{
|
||||
u_char *p;
|
||||
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case KEY_PRIV_ASN1_DER:
|
||||
@@ -275,7 +275,7 @@ static void destroy(private_openssl_ec_private_key_t *this)
|
||||
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;
|
||||
@@ -287,10 +287,10 @@ static private_openssl_ec_private_key_t *create_empty(void)
|
||||
this->public.interface.get_encoding = (bool(*)(private_key_t*, key_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;
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ static private_openssl_ec_private_key_t *create_empty(void)
|
||||
static openssl_ec_private_key_t *generate(size_t key_size)
|
||||
{
|
||||
private_openssl_ec_private_key_t *this = create_empty();
|
||||
|
||||
|
||||
switch (key_size)
|
||||
{
|
||||
case 256:
|
||||
@@ -335,9 +335,9 @@ static openssl_ec_private_key_t *generate(size_t key_size)
|
||||
static openssl_ec_private_key_t *load(chunk_t blob)
|
||||
{
|
||||
private_openssl_ec_private_key_t *this = create_empty();
|
||||
|
||||
|
||||
this->ec = d2i_ECPrivateKey(NULL, (const u_char**)&blob.ptr, blob.len);
|
||||
|
||||
|
||||
if (!this->ec)
|
||||
{
|
||||
destroy(this);
|
||||
@@ -369,7 +369,7 @@ struct private_builder_t {
|
||||
static openssl_ec_private_key_t *build(private_builder_t *this)
|
||||
{
|
||||
openssl_ec_private_key_t *key = this->key;
|
||||
|
||||
|
||||
free(this);
|
||||
return key;
|
||||
}
|
||||
@@ -382,7 +382,7 @@ static void add(private_builder_t *this, builder_part_t part, ...)
|
||||
if (!this->key)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
|
||||
switch (part)
|
||||
{
|
||||
case BUILD_KEY_SIZE:
|
||||
@@ -416,18 +416,18 @@ static void add(private_builder_t *this, builder_part_t part, ...)
|
||||
builder_t *openssl_ec_private_key_builder(key_type_t type)
|
||||
{
|
||||
private_builder_t *this;
|
||||
|
||||
|
||||
if (type != KEY_ECDSA)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
this = malloc_thing(private_builder_t);
|
||||
|
||||
|
||||
this->key = NULL;
|
||||
this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add;
|
||||
this->public.build = (void*(*)(builder_t *this))build;
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,12 +33,12 @@ struct private_openssl_ec_public_key_t {
|
||||
* Public interface for this signer.
|
||||
*/
|
||||
openssl_ec_public_key_t public;
|
||||
|
||||
|
||||
/**
|
||||
* EC key object
|
||||
*/
|
||||
EC_KEY *ec;
|
||||
|
||||
|
||||
/**
|
||||
* reference counter
|
||||
*/
|
||||
@@ -53,7 +53,7 @@ static bool verify_signature(private_openssl_ec_public_key_t *this,
|
||||
{
|
||||
bool valid = FALSE;
|
||||
ECDSA_SIG *sig;
|
||||
|
||||
|
||||
sig = ECDSA_SIG_new();
|
||||
if (sig)
|
||||
{
|
||||
@@ -78,7 +78,7 @@ static bool verify_curve_signature(private_openssl_ec_public_key_t *this,
|
||||
EC_GROUP *req_group;
|
||||
chunk_t hash;
|
||||
bool valid;
|
||||
|
||||
|
||||
req_group = EC_GROUP_new_by_curve_name(nid_curve);
|
||||
if (!req_group)
|
||||
{
|
||||
@@ -111,7 +111,7 @@ static bool verify_der_signature(private_openssl_ec_public_key_t *this,
|
||||
{
|
||||
chunk_t hash;
|
||||
bool valid = FALSE;
|
||||
|
||||
|
||||
/* remove any preceding 0-bytes from signature */
|
||||
while (signature.len && signature.ptr[0] == 0x00)
|
||||
{
|
||||
@@ -194,7 +194,7 @@ bool openssl_ec_fingerprint(EC_KEY *ec, key_encoding_type_t type, chunk_t *fp)
|
||||
hasher_t *hasher;
|
||||
chunk_t key;
|
||||
u_char *p;
|
||||
|
||||
|
||||
if (lib->encoding->get_cache(lib->encoding, type, ec, fp))
|
||||
{
|
||||
return TRUE;
|
||||
@@ -244,7 +244,7 @@ static bool get_encoding(private_openssl_ec_public_key_t *this,
|
||||
key_encoding_type_t type, chunk_t *encoding)
|
||||
{
|
||||
u_char *p;
|
||||
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case KEY_PUB_SPKI_ASN1_DER:
|
||||
@@ -290,7 +290,7 @@ static void destroy(private_openssl_ec_public_key_t *this)
|
||||
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_;
|
||||
@@ -300,10 +300,10 @@ static private_openssl_ec_public_key_t *create_empty()
|
||||
this->public.interface.get_encoding = (bool(*)(public_key_t*, key_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;
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -314,9 +314,9 @@ static openssl_ec_public_key_t *load(chunk_t blob)
|
||||
{
|
||||
private_openssl_ec_public_key_t *this = create_empty();
|
||||
u_char *p = blob.ptr;
|
||||
|
||||
|
||||
this->ec = d2i_EC_PUBKEY(NULL, (const u_char**)&p, blob.len);
|
||||
|
||||
|
||||
if (!this->ec)
|
||||
{
|
||||
destroy(this);
|
||||
@@ -343,7 +343,7 @@ struct private_builder_t {
|
||||
static openssl_ec_public_key_t *build(private_builder_t *this)
|
||||
{
|
||||
openssl_ec_public_key_t *key = this->key;
|
||||
|
||||
|
||||
free(this);
|
||||
return key;
|
||||
}
|
||||
@@ -356,7 +356,7 @@ static void add(private_builder_t *this, builder_part_t part, ...)
|
||||
if (!this->key)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
|
||||
switch (part)
|
||||
{
|
||||
case BUILD_BLOB_ASN1_DER:
|
||||
@@ -383,18 +383,18 @@ static void add(private_builder_t *this, builder_part_t part, ...)
|
||||
builder_t *openssl_ec_public_key_builder(key_type_t type)
|
||||
{
|
||||
private_builder_t *this;
|
||||
|
||||
|
||||
if (type != KEY_ECDSA)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
this = malloc_thing(private_builder_t);
|
||||
|
||||
|
||||
this->key = NULL;
|
||||
this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add;
|
||||
this->public.build = (void*(*)(builder_t *this))build;
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Tobias Brunner
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
@@ -23,19 +23,19 @@ typedef struct private_openssl_hasher_t private_openssl_hasher_t;
|
||||
* Private data of openssl_hasher_t
|
||||
*/
|
||||
struct private_openssl_hasher_t {
|
||||
|
||||
|
||||
/**
|
||||
* Public part of this class.
|
||||
*/
|
||||
openssl_hasher_t public;
|
||||
|
||||
|
||||
/**
|
||||
* the hasher to use
|
||||
*/
|
||||
const EVP_MD *hasher;
|
||||
|
||||
|
||||
/**
|
||||
* the current digest context
|
||||
* the current digest context
|
||||
*/
|
||||
EVP_MD_CTX *ctx;
|
||||
};
|
||||
@@ -49,7 +49,7 @@ typedef struct {
|
||||
* Identifier specified in IKEv2
|
||||
*/
|
||||
int ikev2_id;
|
||||
|
||||
|
||||
/**
|
||||
* Name of the algorithm, as used in OpenSSL
|
||||
*/
|
||||
@@ -76,7 +76,7 @@ static openssl_algorithm_t integrity_algs[] = {
|
||||
/**
|
||||
* Look up an OpenSSL algorithm name
|
||||
*/
|
||||
static char* lookup_algorithm(openssl_algorithm_t *openssl_algo,
|
||||
static char* lookup_algorithm(openssl_algorithm_t *openssl_algo,
|
||||
u_int16_t ikev2_algo)
|
||||
{
|
||||
while (openssl_algo->ikev2_id != END_OF_LIST)
|
||||
@@ -133,7 +133,7 @@ static void allocate_hash(private_openssl_hasher_t *this, chunk_t chunk,
|
||||
}
|
||||
else
|
||||
{
|
||||
get_hash(this, chunk, NULL);
|
||||
get_hash(this, chunk, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ static void destroy (private_openssl_hasher_t *this)
|
||||
openssl_hasher_t *openssl_hasher_create(hash_algorithm_t algo)
|
||||
{
|
||||
private_openssl_hasher_t *this;
|
||||
|
||||
|
||||
char* name = lookup_algorithm(integrity_algs, algo);
|
||||
if (!name)
|
||||
{
|
||||
@@ -161,7 +161,7 @@ openssl_hasher_t *openssl_hasher_create(hash_algorithm_t algo)
|
||||
}
|
||||
|
||||
this = malloc_thing(private_openssl_hasher_t);
|
||||
|
||||
|
||||
this->hasher = EVP_get_digestbyname(name);
|
||||
if (!this->hasher)
|
||||
{
|
||||
@@ -169,17 +169,17 @@ openssl_hasher_t *openssl_hasher_create(hash_algorithm_t algo)
|
||||
free(this);
|
||||
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 */
|
||||
reset(this);
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ typedef struct openssl_hasher_t openssl_hasher_t;
|
||||
* Implementation of hashers using OpenSSL.
|
||||
*/
|
||||
struct openssl_hasher_t {
|
||||
|
||||
|
||||
/**
|
||||
* The hasher_t interface.
|
||||
*/
|
||||
@@ -38,7 +38,7 @@ struct openssl_hasher_t {
|
||||
|
||||
/**
|
||||
* Constructor to create openssl_hasher_t.
|
||||
*
|
||||
*
|
||||
* @param algo algorithm
|
||||
* @return openssl_hasher_t, NULL if not supported
|
||||
*/
|
||||
|
||||
@@ -83,7 +83,7 @@ struct CRYPTO_dynlock_value {
|
||||
static struct CRYPTO_dynlock_value *create_function(const char *file, int line)
|
||||
{
|
||||
struct CRYPTO_dynlock_value *lock;
|
||||
|
||||
|
||||
lock = malloc_thing(struct CRYPTO_dynlock_value);
|
||||
lock->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
|
||||
return lock;
|
||||
@@ -132,11 +132,11 @@ static void threading_init()
|
||||
|
||||
CRYPTO_set_id_callback(id_function);
|
||||
CRYPTO_set_locking_callback(locking_function);
|
||||
|
||||
|
||||
CRYPTO_set_dynlock_create_callback(create_function);
|
||||
CRYPTO_set_dynlock_lock_callback(lock_function);
|
||||
CRYPTO_set_dynlock_destroy_callback(destroy_function);
|
||||
|
||||
|
||||
num_locks = CRYPTO_num_locks();
|
||||
mutex = malloc(sizeof(mutex_t*) * num_locks);
|
||||
for (i = 0; i < num_locks; i++)
|
||||
@@ -151,7 +151,7 @@ static void threading_init()
|
||||
static void threading_cleanup()
|
||||
{
|
||||
int i, num_locks;
|
||||
|
||||
|
||||
num_locks = CRYPTO_num_locks();
|
||||
for (i = 0; i < num_locks; i++)
|
||||
{
|
||||
@@ -170,9 +170,9 @@ static void destroy(private_openssl_plugin_t *this)
|
||||
(crypter_constructor_t)openssl_crypter_create);
|
||||
lib->crypto->remove_hasher(lib->crypto,
|
||||
(hasher_constructor_t)openssl_hasher_create);
|
||||
lib->crypto->remove_dh(lib->crypto,
|
||||
lib->crypto->remove_dh(lib->crypto,
|
||||
(dh_constructor_t)openssl_diffie_hellman_create);
|
||||
lib->crypto->remove_dh(lib->crypto,
|
||||
lib->crypto->remove_dh(lib->crypto,
|
||||
(dh_constructor_t)openssl_ec_diffie_hellman_create);
|
||||
lib->creds->remove_builder(lib->creds,
|
||||
(builder_constructor_t)openssl_rsa_private_key_builder);
|
||||
@@ -182,13 +182,13 @@ static void destroy(private_openssl_plugin_t *this)
|
||||
(builder_constructor_t)openssl_ec_private_key_builder);
|
||||
lib->creds->remove_builder(lib->creds,
|
||||
(builder_constructor_t)openssl_ec_public_key_builder);
|
||||
|
||||
|
||||
ENGINE_cleanup();
|
||||
EVP_cleanup();
|
||||
CONF_modules_free();
|
||||
|
||||
|
||||
threading_cleanup();
|
||||
|
||||
|
||||
free(this);
|
||||
}
|
||||
|
||||
@@ -198,18 +198,18 @@ static void destroy(private_openssl_plugin_t *this)
|
||||
plugin_t *plugin_create()
|
||||
{
|
||||
private_openssl_plugin_t *this = malloc_thing(private_openssl_plugin_t);
|
||||
|
||||
|
||||
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
|
||||
|
||||
|
||||
threading_init();
|
||||
|
||||
|
||||
OPENSSL_config(NULL);
|
||||
OpenSSL_add_all_algorithms();
|
||||
|
||||
|
||||
/* activate support for hardware accelerators */
|
||||
ENGINE_load_builtin_engines();
|
||||
ENGINE_register_all_complete();
|
||||
|
||||
|
||||
/* crypter */
|
||||
lib->crypto->add_crypter(lib->crypto, ENCR_AES_CBC,
|
||||
(crypter_constructor_t)openssl_crypter_create);
|
||||
@@ -231,7 +231,7 @@ plugin_t *plugin_create()
|
||||
(crypter_constructor_t)openssl_crypter_create);
|
||||
lib->crypto->add_crypter(lib->crypto, ENCR_NULL,
|
||||
(crypter_constructor_t)openssl_crypter_create);
|
||||
|
||||
|
||||
/* hasher */
|
||||
lib->crypto->add_hasher(lib->crypto, HASH_SHA1,
|
||||
(hasher_constructor_t)openssl_hasher_create);
|
||||
@@ -249,7 +249,7 @@ plugin_t *plugin_create()
|
||||
(hasher_constructor_t)openssl_hasher_create);
|
||||
lib->crypto->add_hasher(lib->crypto, HASH_SHA512,
|
||||
(hasher_constructor_t)openssl_hasher_create);
|
||||
|
||||
|
||||
/* ec diffie hellman */
|
||||
lib->crypto->add_dh(lib->crypto, ECP_192_BIT,
|
||||
(dh_constructor_t)openssl_ec_diffie_hellman_create);
|
||||
@@ -261,36 +261,36 @@ plugin_t *plugin_create()
|
||||
(dh_constructor_t)openssl_ec_diffie_hellman_create);
|
||||
lib->crypto->add_dh(lib->crypto, ECP_521_BIT,
|
||||
(dh_constructor_t)openssl_ec_diffie_hellman_create);
|
||||
|
||||
|
||||
/* diffie hellman */
|
||||
lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
|
||||
lib->crypto->add_dh(lib->crypto, MODP_2048_BIT,
|
||||
(dh_constructor_t)openssl_diffie_hellman_create);
|
||||
lib->crypto->add_dh(lib->crypto, MODP_1536_BIT,
|
||||
lib->crypto->add_dh(lib->crypto, MODP_1536_BIT,
|
||||
(dh_constructor_t)openssl_diffie_hellman_create);
|
||||
lib->crypto->add_dh(lib->crypto, MODP_3072_BIT,
|
||||
lib->crypto->add_dh(lib->crypto, MODP_3072_BIT,
|
||||
(dh_constructor_t)openssl_diffie_hellman_create);
|
||||
lib->crypto->add_dh(lib->crypto, MODP_4096_BIT,
|
||||
lib->crypto->add_dh(lib->crypto, MODP_4096_BIT,
|
||||
(dh_constructor_t)openssl_diffie_hellman_create);
|
||||
lib->crypto->add_dh(lib->crypto, MODP_6144_BIT,
|
||||
lib->crypto->add_dh(lib->crypto, MODP_6144_BIT,
|
||||
(dh_constructor_t)openssl_diffie_hellman_create);
|
||||
lib->crypto->add_dh(lib->crypto, MODP_8192_BIT,
|
||||
lib->crypto->add_dh(lib->crypto, MODP_8192_BIT,
|
||||
(dh_constructor_t)openssl_diffie_hellman_create);
|
||||
lib->crypto->add_dh(lib->crypto, MODP_1024_BIT,
|
||||
(dh_constructor_t)openssl_diffie_hellman_create);
|
||||
lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
|
||||
lib->crypto->add_dh(lib->crypto, MODP_768_BIT,
|
||||
(dh_constructor_t)openssl_diffie_hellman_create);
|
||||
|
||||
|
||||
/* rsa */
|
||||
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
|
||||
(builder_constructor_t)openssl_rsa_private_key_builder);
|
||||
lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_RSA,
|
||||
(builder_constructor_t)openssl_rsa_public_key_builder);
|
||||
|
||||
|
||||
/* ec */
|
||||
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_ECDSA,
|
||||
(builder_constructor_t)openssl_ec_private_key_builder);
|
||||
lib->creds->add_builder(lib->creds, CRED_PUBLIC_KEY, KEY_ECDSA,
|
||||
(builder_constructor_t)openssl_ec_public_key_builder);
|
||||
|
||||
|
||||
return &this->public.plugin;
|
||||
}
|
||||
|
||||
@@ -38,17 +38,17 @@ struct private_openssl_rsa_private_key_t {
|
||||
* Public interface for this signer.
|
||||
*/
|
||||
openssl_rsa_private_key_t public;
|
||||
|
||||
|
||||
/**
|
||||
* RSA object from OpenSSL
|
||||
*/
|
||||
RSA *rsa;
|
||||
|
||||
|
||||
/**
|
||||
* TRUE if the key is from an OpenSSL ENGINE and might not be readable
|
||||
*/
|
||||
bool engine;
|
||||
|
||||
|
||||
/**
|
||||
* reference count
|
||||
*/
|
||||
@@ -82,13 +82,13 @@ static bool build_emsa_pkcs1_signature(private_openssl_rsa_private_key_t *this,
|
||||
EVP_PKEY *key;
|
||||
const EVP_MD *hasher;
|
||||
u_int len;
|
||||
|
||||
|
||||
hasher = EVP_get_digestbynid(type);
|
||||
if (!hasher)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
ctx = EVP_MD_CTX_create();
|
||||
key = EVP_PKEY_new();
|
||||
if (!ctx || !key)
|
||||
@@ -111,7 +111,7 @@ static bool build_emsa_pkcs1_signature(private_openssl_rsa_private_key_t *this,
|
||||
{
|
||||
success = TRUE;
|
||||
}
|
||||
|
||||
|
||||
error:
|
||||
if (key)
|
||||
{
|
||||
@@ -140,7 +140,7 @@ static key_type_t get_type(private_openssl_rsa_private_key_t *this)
|
||||
/**
|
||||
* Implementation of openssl_rsa_private_key.sign.
|
||||
*/
|
||||
static bool sign(private_openssl_rsa_private_key_t *this, signature_scheme_t scheme,
|
||||
static bool sign(private_openssl_rsa_private_key_t *this, signature_scheme_t scheme,
|
||||
chunk_t data, chunk_t *signature)
|
||||
{
|
||||
switch (scheme)
|
||||
@@ -192,7 +192,7 @@ static public_key_t* get_public_key(private_openssl_rsa_private_key_t *this)
|
||||
chunk_t enc;
|
||||
public_key_t *key;
|
||||
u_char *p;
|
||||
|
||||
|
||||
enc = chunk_alloc(i2d_RSAPublicKey(this->rsa, NULL));
|
||||
p = enc.ptr;
|
||||
i2d_RSAPublicKey(this->rsa, &p);
|
||||
@@ -218,7 +218,7 @@ static bool get_encoding(private_openssl_rsa_private_key_t *this,
|
||||
key_encoding_type_t type, chunk_t *encoding)
|
||||
{
|
||||
u_char *p;
|
||||
|
||||
|
||||
if (this->engine)
|
||||
{
|
||||
return FALSE;
|
||||
@@ -268,7 +268,7 @@ static void destroy(private_openssl_rsa_private_key_t *this)
|
||||
static private_openssl_rsa_private_key_t *create_empty(void)
|
||||
{
|
||||
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;
|
||||
@@ -280,10 +280,10 @@ static private_openssl_rsa_private_key_t *create_empty(void)
|
||||
this->public.interface.get_encoding = (bool(*)(private_key_t*, key_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;
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -293,9 +293,9 @@ static private_openssl_rsa_private_key_t *create_empty(void)
|
||||
static openssl_rsa_private_key_t *generate(size_t key_size)
|
||||
{
|
||||
private_openssl_rsa_private_key_t *this = create_empty();
|
||||
|
||||
|
||||
this->rsa = RSA_generate_key(key_size, PUBLIC_EXPONENT, NULL, NULL);
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ static openssl_rsa_private_key_t *load(chunk_t blob)
|
||||
{
|
||||
u_char *p = blob.ptr;
|
||||
private_openssl_rsa_private_key_t *this = create_empty();
|
||||
|
||||
|
||||
this->rsa = d2i_RSAPrivateKey(NULL, (const u_char**)&p, blob.len);
|
||||
if (!this->rsa)
|
||||
{
|
||||
@@ -330,28 +330,28 @@ static openssl_rsa_private_key_t *load_from_smartcard(char *keyid, char *pin)
|
||||
EVP_PKEY *key;
|
||||
char *engine_id = lib->settings->get_str(lib->settings,
|
||||
"library.plugins.openssl.engine_id", "pkcs11");
|
||||
|
||||
|
||||
ENGINE *engine = ENGINE_by_id(engine_id);
|
||||
if (!engine)
|
||||
{
|
||||
DBG1("engine '%s' is not available", engine_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (!ENGINE_init(engine))
|
||||
{
|
||||
DBG1("failed to initialize engine '%s'", engine_id);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
if (!ENGINE_ctrl_cmd_string(engine, "PIN", pin, 0))
|
||||
{
|
||||
DBG1("failed to set PIN on engine '%s'", engine_id);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
key = ENGINE_load_private_key(engine, keyid, NULL, NULL);
|
||||
|
||||
|
||||
if (!key)
|
||||
{
|
||||
DBG1("failed to load private key with ID '%s' from engine '%s'", keyid,
|
||||
@@ -359,13 +359,13 @@ static openssl_rsa_private_key_t *load_from_smartcard(char *keyid, char *pin)
|
||||
goto error;
|
||||
}
|
||||
ENGINE_free(engine);
|
||||
|
||||
|
||||
this = create_empty();
|
||||
this->rsa = EVP_PKEY_get1_RSA(key);
|
||||
this->engine = TRUE;
|
||||
|
||||
|
||||
return &this->public;
|
||||
|
||||
|
||||
error:
|
||||
ENGINE_free(engine);
|
||||
return NULL;
|
||||
@@ -393,7 +393,7 @@ struct private_builder_t {
|
||||
static openssl_rsa_private_key_t *build(private_builder_t *this)
|
||||
{
|
||||
openssl_rsa_private_key_t *key = this->key;
|
||||
|
||||
|
||||
if (this->keyid && this->pin)
|
||||
{
|
||||
key = load_from_smartcard(this->keyid, this->pin);
|
||||
@@ -410,7 +410,7 @@ static void add(private_builder_t *this, builder_part_t part, ...)
|
||||
if (!this->key)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
|
||||
switch (part)
|
||||
{
|
||||
case BUILD_BLOB_ASN1_DER:
|
||||
@@ -458,20 +458,20 @@ static void add(private_builder_t *this, builder_part_t part, ...)
|
||||
builder_t *openssl_rsa_private_key_builder(key_type_t type)
|
||||
{
|
||||
private_builder_t *this;
|
||||
|
||||
|
||||
if (type != KEY_RSA)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
this = malloc_thing(private_builder_t);
|
||||
|
||||
|
||||
this->key = NULL;
|
||||
this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add;
|
||||
this->public.build = (void*(*)(builder_t *this))build;
|
||||
this->keyid = NULL;
|
||||
this->pin = NULL;
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,12 +32,12 @@ struct private_openssl_rsa_public_key_t {
|
||||
* Public interface for this signer.
|
||||
*/
|
||||
openssl_rsa_public_key_t public;
|
||||
|
||||
|
||||
/**
|
||||
* RSA object from OpenSSL
|
||||
*/
|
||||
RSA *rsa;
|
||||
|
||||
|
||||
/**
|
||||
* reference counter
|
||||
*/
|
||||
@@ -100,7 +100,7 @@ static bool verify_emsa_pkcs1_signature(private_openssl_rsa_public_key_t *this,
|
||||
goto error;
|
||||
}
|
||||
valid = (EVP_VerifyFinal(ctx, signature.ptr, signature.len, key) == 1);
|
||||
|
||||
|
||||
error:
|
||||
if (key)
|
||||
{
|
||||
@@ -125,7 +125,7 @@ static key_type_t get_type(private_openssl_rsa_public_key_t *this)
|
||||
/**
|
||||
* Implementation of public_key_t.verify.
|
||||
*/
|
||||
static bool verify(private_openssl_rsa_public_key_t *this, signature_scheme_t scheme,
|
||||
static bool verify(private_openssl_rsa_public_key_t *this, signature_scheme_t scheme,
|
||||
chunk_t data, chunk_t signature)
|
||||
{
|
||||
switch (scheme)
|
||||
@@ -177,7 +177,7 @@ bool openssl_rsa_fingerprint(RSA *rsa, key_encoding_type_t type, chunk_t *fp)
|
||||
hasher_t *hasher;
|
||||
chunk_t key;
|
||||
u_char *p;
|
||||
|
||||
|
||||
if (lib->encoding->get_cache(lib->encoding, type, rsa, fp))
|
||||
{
|
||||
return TRUE;
|
||||
@@ -227,7 +227,7 @@ static bool get_encoding(private_openssl_rsa_public_key_t *this,
|
||||
key_encoding_type_t type, chunk_t *encoding)
|
||||
{
|
||||
u_char *p;
|
||||
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case KEY_PUB_SPKI_ASN1_DER:
|
||||
@@ -280,7 +280,7 @@ static void destroy(private_openssl_rsa_public_key_t *this)
|
||||
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_;
|
||||
@@ -290,10 +290,10 @@ static private_openssl_rsa_public_key_t *create_empty()
|
||||
this->public.interface.get_encoding = (bool(*)(public_key_t*, key_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;
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -304,14 +304,14 @@ static openssl_rsa_public_key_t *load(chunk_t blob)
|
||||
{
|
||||
u_char *p = blob.ptr;
|
||||
private_openssl_rsa_public_key_t *this = create_empty();
|
||||
|
||||
|
||||
this->rsa = d2i_RSAPublicKey(NULL, (const u_char**)&p, blob.len);
|
||||
if (!this->rsa)
|
||||
{
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ struct private_builder_t {
|
||||
static openssl_rsa_public_key_t *build(private_builder_t *this)
|
||||
{
|
||||
openssl_rsa_public_key_t *key = this->key;
|
||||
|
||||
|
||||
free(this);
|
||||
return key;
|
||||
}
|
||||
@@ -346,7 +346,7 @@ static void add(private_builder_t *this, builder_part_t part, ...)
|
||||
if (!this->key)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
|
||||
switch (part)
|
||||
{
|
||||
case BUILD_BLOB_ASN1_DER:
|
||||
@@ -373,18 +373,18 @@ static void add(private_builder_t *this, builder_part_t part, ...)
|
||||
builder_t *openssl_rsa_public_key_builder(key_type_t type)
|
||||
{
|
||||
private_builder_t *this;
|
||||
|
||||
|
||||
if (type != KEY_RSA)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
this = malloc_thing(private_builder_t);
|
||||
|
||||
|
||||
this->key = NULL;
|
||||
this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add;
|
||||
this->public.build = (void*(*)(builder_t *this))build;
|
||||
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,30 +33,30 @@ bool openssl_hash_chunk(int hash_type, chunk_t data, chunk_t *hash)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ctx = EVP_MD_CTX_create();
|
||||
|
||||
ctx = EVP_MD_CTX_create();
|
||||
if (!ctx)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
if (!EVP_DigestInit_ex(ctx, hasher, NULL))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
if (!EVP_DigestUpdate(ctx, data.ptr, data.len))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
*hash = chunk_alloc(hasher->md_size);
|
||||
if (!EVP_DigestFinal_ex(ctx, hash->ptr, NULL))
|
||||
{
|
||||
chunk_free(hash);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
ret = TRUE;
|
||||
error:
|
||||
if (ctx)
|
||||
@@ -72,18 +72,18 @@ error:
|
||||
bool openssl_bn_cat(int len, BIGNUM *a, BIGNUM *b, chunk_t *chunk)
|
||||
{
|
||||
int offset;
|
||||
|
||||
|
||||
chunk->len = len + (b ? len : 0);
|
||||
chunk->ptr = malloc(chunk->len);
|
||||
memset(chunk->ptr, 0, chunk->len);
|
||||
|
||||
|
||||
/* convert a */
|
||||
offset = len - BN_num_bytes(a);
|
||||
if (!BN_bn2bin(a, chunk->ptr + offset))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
/* optionally convert and concatenate b */
|
||||
if (b)
|
||||
{
|
||||
@@ -92,8 +92,8 @@ bool openssl_bn_cat(int len, BIGNUM *a, BIGNUM *b, chunk_t *chunk)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
error:
|
||||
chunk_free(chunk);
|
||||
@@ -107,20 +107,20 @@ error:
|
||||
bool openssl_bn_split(chunk_t chunk, BIGNUM *a, BIGNUM *b)
|
||||
{
|
||||
int len;
|
||||
|
||||
|
||||
if ((chunk.len % 2) != 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
len = chunk.len / 2;
|
||||
|
||||
|
||||
if (!BN_bin2bn(chunk.ptr, len, a) ||
|
||||
!BN_bin2bn(chunk.ptr + len, len, b))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@
|
||||
|
||||
/**
|
||||
* Creates a hash of a given type of a chunk of data.
|
||||
*
|
||||
*
|
||||
* Note: this function allocates memory for the hash
|
||||
*
|
||||
*
|
||||
* @param hash_type NID of the hash
|
||||
* @param data the chunk of data to hash
|
||||
* @param hash chunk that contains the hash
|
||||
@@ -44,9 +44,9 @@ bool openssl_hash_chunk(int hash_type, chunk_t data, chunk_t *hash);
|
||||
/**
|
||||
* Concatenates two bignums into a chunk, thereby enfocing the length of
|
||||
* a single BIGNUM, if necessary, by pre-pending it with zeros.
|
||||
*
|
||||
*
|
||||
* Note: this function allocates memory for the chunk
|
||||
*
|
||||
*
|
||||
* @param len the length of a single BIGNUM
|
||||
* @param a first BIGNUM
|
||||
* @param b second BIGNUM
|
||||
@@ -57,7 +57,7 @@ bool openssl_bn_cat(int len, BIGNUM *a, BIGNUM *b, chunk_t *chunk);
|
||||
|
||||
/**
|
||||
* Splits a chunk into two bignums of equal binary length.
|
||||
*
|
||||
*
|
||||
* @param chunk a chunk that contains the two BIGNUMs
|
||||
* @param a first BIGNUM
|
||||
* @param b second BIGNUM
|
||||
|
||||
Reference in New Issue
Block a user