pluto supports ECDSA authentication
This commit is contained in:
@@ -128,36 +128,18 @@ static bool sig2chunk(const EC_GROUP *group, ECDSA_SIG *sig, chunk_t *chunk)
|
||||
* Build the signature
|
||||
*/
|
||||
static bool build_signature(private_openssl_ec_private_key_t *this,
|
||||
int hash_type, chunk_t data, chunk_t *signature)
|
||||
chunk_t hash, chunk_t *signature)
|
||||
{
|
||||
chunk_t hash = chunk_empty;
|
||||
ECDSA_SIG *sig;
|
||||
bool ret = FALSE;
|
||||
|
||||
if (!openssl_hash_chunk(hash_type, data, &hash))
|
||||
ECDSA_SIG *sig = ECDSA_do_sign(hash.ptr, hash.len, this->ec);
|
||||
bool success;
|
||||
|
||||
if (!sig)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
sig = ECDSA_do_sign(hash.ptr, hash.len, this->ec);
|
||||
if (!sig)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!sig2chunk(EC_KEY_get0_group(this->ec), sig, signature))
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
error:
|
||||
chunk_free(&hash);
|
||||
if (sig)
|
||||
{
|
||||
ECDSA_SIG_free(sig);
|
||||
}
|
||||
return ret;
|
||||
success = sig2chunk(EC_KEY_get0_group(this->ec), sig, signature);
|
||||
ECDSA_SIG_free(sig);
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,36 +156,51 @@ static key_type_t get_type(private_openssl_ec_private_key_t *this)
|
||||
static bool sign(private_openssl_ec_private_key_t *this, signature_scheme_t scheme,
|
||||
chunk_t data, chunk_t *signature)
|
||||
{
|
||||
EC_GROUP *req_group;
|
||||
const EC_GROUP *my_group;
|
||||
int hash, curve;
|
||||
|
||||
if (!lookup_scheme(scheme, &hash, &curve))
|
||||
bool success;
|
||||
|
||||
if (scheme == SIGN_ECDSA_WITH_NULL)
|
||||
{
|
||||
DBG1("signature scheme %N not supported in EC",
|
||||
signature_scheme_names, scheme);
|
||||
return FALSE;
|
||||
success = build_signature(this, data, signature);
|
||||
}
|
||||
|
||||
req_group = EC_GROUP_new_by_curve_name(curve);
|
||||
if (!req_group)
|
||||
else
|
||||
{
|
||||
DBG1("signature scheme %N not supported in EC (required curve not supported)",
|
||||
signature_scheme_names, scheme);
|
||||
return FALSE;
|
||||
}
|
||||
EC_GROUP *req_group;
|
||||
const EC_GROUP *my_group;
|
||||
chunk_t hash = chunk_empty;
|
||||
int hash_type, curve;
|
||||
|
||||
if (!lookup_scheme(scheme, &hash_type, &curve))
|
||||
{
|
||||
DBG1("signature scheme %N not supported in EC",
|
||||
signature_scheme_names, scheme);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
my_group = EC_KEY_get0_group(this->ec);
|
||||
if (EC_GROUP_cmp(my_group, req_group, NULL) != 0)
|
||||
{
|
||||
DBG1("signature scheme %N not supported by private key",
|
||||
signature_scheme_names, scheme);
|
||||
return FALSE;
|
||||
}
|
||||
req_group = EC_GROUP_new_by_curve_name(curve);
|
||||
if (!req_group)
|
||||
{
|
||||
DBG1("signature scheme %N not supported in EC (required curve not supported)",
|
||||
signature_scheme_names, scheme);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
EC_GROUP_free(req_group);
|
||||
|
||||
return build_signature(this, hash, data, signature);
|
||||
my_group = EC_KEY_get0_group(this->ec);
|
||||
if (EC_GROUP_cmp(my_group, req_group, NULL) != 0)
|
||||
{
|
||||
DBG1("signature scheme %N not supported by private key",
|
||||
signature_scheme_names, scheme);
|
||||
return FALSE;
|
||||
}
|
||||
EC_GROUP_free(req_group);
|
||||
|
||||
if (!openssl_hash_chunk(hash_type, data, &hash))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
success = build_signature(this, hash, signature);
|
||||
chunk_free(&hash);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user