Latest update.
This commit is contained in:
@@ -16,13 +16,13 @@
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/params.h>
|
||||
#include "internal/param_build.h"
|
||||
#include "crypto/dh.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommon.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "crypto/dh.h"
|
||||
#include "internal/param_build.h"
|
||||
|
||||
static OSSL_OP_keymgmt_new_fn dh_newdata;
|
||||
static OSSL_OP_keymgmt_free_fn dh_freedata;
|
||||
@@ -30,6 +30,7 @@ static OSSL_OP_keymgmt_get_params_fn dh_get_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn dh_gettable_params;
|
||||
static OSSL_OP_keymgmt_has_fn dh_has;
|
||||
static OSSL_OP_keymgmt_match_fn dh_match;
|
||||
static OSSL_OP_keymgmt_validate_fn dh_validate;
|
||||
static OSSL_OP_keymgmt_import_fn dh_import;
|
||||
static OSSL_OP_keymgmt_import_types_fn dh_import_types;
|
||||
static OSSL_OP_keymgmt_export_fn dh_export;
|
||||
@@ -316,6 +317,46 @@ static const OSSL_PARAM *dh_gettable_params(void)
|
||||
return dh_params;
|
||||
}
|
||||
|
||||
static int dh_validate_public(DH *dh)
|
||||
{
|
||||
const BIGNUM *pub_key = NULL;
|
||||
|
||||
DH_get0_key(dh, &pub_key, NULL);
|
||||
return DH_check_pub_key_ex(dh, pub_key);
|
||||
}
|
||||
|
||||
static int dh_validate_private(DH *dh)
|
||||
{
|
||||
int status = 0;
|
||||
const BIGNUM *priv_key = NULL;
|
||||
|
||||
DH_get0_key(dh, NULL, &priv_key);
|
||||
return dh_check_priv_key(dh, priv_key, &status);;
|
||||
}
|
||||
|
||||
static int dh_validate(void *keydata, int selection)
|
||||
{
|
||||
DH *dh = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if ((selection & DH_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && DH_check_params_ex(dh);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && dh_validate_public(dh);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && dh_validate_private(dh);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR)
|
||||
== OSSL_KEYMGMT_SELECT_KEYPAIR)
|
||||
ok = ok && dh_check_pairwise(dh);
|
||||
return ok;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dh_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))dh_newdata },
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))dh_freedata },
|
||||
@@ -323,6 +364,7 @@ const OSSL_DISPATCH dh_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))dh_gettable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))dh_has },
|
||||
{ OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))dh_match },
|
||||
{ OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))dh_validate },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))dh_import },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))dh_import_types },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))dh_export },
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -17,12 +17,11 @@
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/params.h>
|
||||
#include "internal/param_build.h"
|
||||
#include "crypto/dsa.h"
|
||||
#include "prov/implementations.h"
|
||||
#include "prov/providercommon.h"
|
||||
#include "prov/provider_ctx.h"
|
||||
#include "crypto/dsa.h"
|
||||
#include "internal/param_build.h"
|
||||
|
||||
static OSSL_OP_keymgmt_new_fn dsa_newdata;
|
||||
static OSSL_OP_keymgmt_free_fn dsa_freedata;
|
||||
@@ -30,6 +29,7 @@ static OSSL_OP_keymgmt_get_params_fn dsa_get_params;
|
||||
static OSSL_OP_keymgmt_gettable_params_fn dsa_gettable_params;
|
||||
static OSSL_OP_keymgmt_has_fn dsa_has;
|
||||
static OSSL_OP_keymgmt_match_fn dsa_match;
|
||||
static OSSL_OP_keymgmt_validate_fn dsa_validate;
|
||||
static OSSL_OP_keymgmt_import_fn dsa_import;
|
||||
static OSSL_OP_keymgmt_import_types_fn dsa_import_types;
|
||||
static OSSL_OP_keymgmt_export_fn dsa_export;
|
||||
@@ -329,6 +329,55 @@ static const OSSL_PARAM *dsa_gettable_params(void)
|
||||
return dsa_params;
|
||||
}
|
||||
|
||||
static int dsa_validate_domparams(DSA *dsa)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
return dsa_check_params(dsa, &status);
|
||||
}
|
||||
|
||||
static int dsa_validate_public(DSA *dsa)
|
||||
{
|
||||
int status = 0;
|
||||
const BIGNUM *pub_key = NULL;
|
||||
|
||||
DSA_get0_key(dsa, &pub_key, NULL);
|
||||
return dsa_check_pub_key(dsa, pub_key, &status);
|
||||
}
|
||||
|
||||
static int dsa_validate_private(DSA *dsa)
|
||||
{
|
||||
int status = 0;
|
||||
const BIGNUM *priv_key = NULL;
|
||||
|
||||
DSA_get0_key(dsa, NULL, &priv_key);
|
||||
return dsa_check_priv_key(dsa, priv_key, &status);
|
||||
}
|
||||
|
||||
static int dsa_validate(void *keydata, int selection)
|
||||
{
|
||||
DSA *dsa = keydata;
|
||||
int ok = 0;
|
||||
|
||||
if ((selection & DSA_POSSIBLE_SELECTIONS) != 0)
|
||||
ok = 1;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0)
|
||||
ok = ok && dsa_validate_domparams(dsa);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
ok = ok && dsa_validate_public(dsa);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
ok = ok && dsa_validate_private(dsa);
|
||||
|
||||
/* If the whole key is selected, we do a pairwise validation */
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR)
|
||||
== OSSL_KEYMGMT_SELECT_KEYPAIR)
|
||||
ok = ok && dsa_check_pairwise(dsa);
|
||||
return ok;
|
||||
}
|
||||
|
||||
const OSSL_DISPATCH dsa_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))dsa_newdata },
|
||||
{ OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))dsa_freedata },
|
||||
@@ -336,6 +385,7 @@ const OSSL_DISPATCH dsa_keymgmt_functions[] = {
|
||||
{ OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))dsa_gettable_params },
|
||||
{ OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))dsa_has },
|
||||
{ OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))dsa_match },
|
||||
{ OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))dsa_validate },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))dsa_import },
|
||||
{ OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))dsa_import_types },
|
||||
{ OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))dsa_export },
|
||||
|
||||
@@ -473,7 +473,7 @@ static
|
||||
int ec_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
{
|
||||
EC_KEY *ec = keydata;
|
||||
int ok = 0;
|
||||
int ok = 1;
|
||||
|
||||
if (ec == NULL)
|
||||
return 0;
|
||||
|
||||
@@ -27,6 +27,8 @@ static OSSL_OP_keymgmt_import_types_fn ecx_imexport_types;
|
||||
static OSSL_OP_keymgmt_export_fn ecx_export;
|
||||
static OSSL_OP_keymgmt_export_types_fn ecx_imexport_types;
|
||||
|
||||
#define ECX_POSSIBLE_SELECTIONS (OSSL_KEYMGMT_SELECT_KEYPAIR)
|
||||
|
||||
static void *x25519_new_key(void *provctx)
|
||||
{
|
||||
return ecx_key_new(X25519_KEYLEN, 0);
|
||||
@@ -40,12 +42,9 @@ static void *x448_new_key(void *provctx)
|
||||
static int ecx_has(void *keydata, int selection)
|
||||
{
|
||||
ECX_KEY *key = keydata;
|
||||
const int ecx_selections = OSSL_KEYMGMT_SELECT_PUBLIC_KEY
|
||||
| OSSL_KEYMGMT_SELECT_PRIVATE_KEY;
|
||||
int ok = 1;
|
||||
|
||||
if ((selection & ~ecx_selections) != 0
|
||||
|| (selection & ecx_selections) == 0)
|
||||
if ((selection & ECX_POSSIBLE_SELECTIONS) == 0)
|
||||
return 0;
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
|
||||
@@ -63,29 +62,24 @@ static int ecx_import(void *keydata, int selection, const OSSL_PARAM params[])
|
||||
size_t privkeylen = 0, pubkeylen;
|
||||
const OSSL_PARAM *param_priv_key = NULL, *param_pub_key;
|
||||
unsigned char *pubkey;
|
||||
const int ecx_selections = OSSL_KEYMGMT_SELECT_PUBLIC_KEY
|
||||
| OSSL_KEYMGMT_SELECT_PRIVATE_KEY;
|
||||
|
||||
if (key == NULL)
|
||||
return 0;
|
||||
|
||||
if ((selection & ~ecx_selections) != 0
|
||||
|| (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) == 0)
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) == 0)
|
||||
return 0;
|
||||
|
||||
param_pub_key =
|
||||
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
|
||||
|
||||
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
|
||||
param_priv_key =
|
||||
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
|
||||
param_pub_key =
|
||||
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
|
||||
|
||||
/*
|
||||
* If a private key is present then a public key must also be present.
|
||||
* Alternatively we've just got a public key.
|
||||
*/
|
||||
if (param_pub_key == NULL
|
||||
|| (param_priv_key == NULL
|
||||
&& (selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0))
|
||||
if (param_pub_key == NULL)
|
||||
return 0;
|
||||
|
||||
if (param_priv_key != NULL
|
||||
|
||||
Reference in New Issue
Block a user