Latest update.
This commit is contained in:
+34
-105
@@ -282,7 +282,7 @@ static int do_dh_print(BIO *bp, const DH *x, int indent, int ptype)
|
||||
else
|
||||
pub_key = NULL;
|
||||
|
||||
if (x->p == NULL || (ptype == 2 && priv_key == NULL)
|
||||
if (x->params.p == NULL || (ptype == 2 && priv_key == NULL)
|
||||
|| (ptype > 0 && pub_key == NULL)) {
|
||||
reason = ERR_R_PASSED_NULL_PARAMETER;
|
||||
goto err;
|
||||
@@ -296,7 +296,7 @@ static int do_dh_print(BIO *bp, const DH *x, int indent, int ptype)
|
||||
ktype = "DH Parameters";
|
||||
|
||||
if (!BIO_indent(bp, indent, 128)
|
||||
|| BIO_printf(bp, "%s: (%d bit)\n", ktype, BN_num_bits(x->p)) <= 0)
|
||||
|| BIO_printf(bp, "%s: (%d bit)\n", ktype, DH_bits(x)) <= 0)
|
||||
goto err;
|
||||
indent += 4;
|
||||
|
||||
@@ -305,35 +305,9 @@ static int do_dh_print(BIO *bp, const DH *x, int indent, int ptype)
|
||||
if (!ASN1_bn_print(bp, "public-key:", pub_key, NULL, indent))
|
||||
goto err;
|
||||
|
||||
if (!ASN1_bn_print(bp, "prime:", x->p, NULL, indent))
|
||||
if (!ffc_params_print(bp, &x->params, indent))
|
||||
goto err;
|
||||
if (!ASN1_bn_print(bp, "generator:", x->g, NULL, indent))
|
||||
goto err;
|
||||
if (x->q && !ASN1_bn_print(bp, "subgroup order:", x->q, NULL, indent))
|
||||
goto err;
|
||||
if (x->j && !ASN1_bn_print(bp, "subgroup factor:", x->j, NULL, indent))
|
||||
goto err;
|
||||
if (x->seed) {
|
||||
int i;
|
||||
|
||||
if (!BIO_indent(bp, indent, 128)
|
||||
|| BIO_puts(bp, "seed:") <= 0)
|
||||
goto err;
|
||||
for (i = 0; i < x->seedlen; i++) {
|
||||
if ((i % 15) == 0) {
|
||||
if (BIO_puts(bp, "\n") <= 0
|
||||
|| !BIO_indent(bp, indent + 4, 128))
|
||||
goto err;
|
||||
}
|
||||
if (BIO_printf(bp, "%02x%s", x->seed[i],
|
||||
((i + 1) == x->seedlen) ? "" : ":") <= 0)
|
||||
goto err;
|
||||
}
|
||||
if (BIO_write(bp, "\n", 1) <= 0)
|
||||
return 0;
|
||||
}
|
||||
if (x->counter && !ASN1_bn_print(bp, "counter:", x->counter, NULL, indent))
|
||||
goto err;
|
||||
if (x->length != 0) {
|
||||
if (!BIO_indent(bp, indent, 128)
|
||||
|| BIO_printf(bp, "recommended-private-length: %d bits\n",
|
||||
@@ -355,7 +329,7 @@ static int int_dh_size(const EVP_PKEY *pkey)
|
||||
|
||||
static int dh_bits(const EVP_PKEY *pkey)
|
||||
{
|
||||
return BN_num_bits(pkey->pkey.dh->p);
|
||||
return DH_bits(pkey->pkey.dh);
|
||||
}
|
||||
|
||||
static int dh_security_bits(const EVP_PKEY *pkey)
|
||||
@@ -365,59 +339,17 @@ static int dh_security_bits(const EVP_PKEY *pkey)
|
||||
|
||||
static int dh_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
|
||||
{
|
||||
if (BN_cmp(a->pkey.dh->p, b->pkey.dh->p) ||
|
||||
BN_cmp(a->pkey.dh->g, b->pkey.dh->g))
|
||||
return 0;
|
||||
else if (a->ameth == &dhx_asn1_meth) {
|
||||
if (BN_cmp(a->pkey.dh->q, b->pkey.dh->q))
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int int_dh_bn_cpy(BIGNUM **dst, const BIGNUM *src)
|
||||
{
|
||||
BIGNUM *a;
|
||||
|
||||
/*
|
||||
* If source is read only just copy the pointer, so
|
||||
* we don't have to reallocate it.
|
||||
*/
|
||||
if (src == NULL)
|
||||
a = NULL;
|
||||
else if (BN_get_flags(src, BN_FLG_STATIC_DATA)
|
||||
&& !BN_get_flags(src, BN_FLG_MALLOCED))
|
||||
a = (BIGNUM *)src;
|
||||
else if ((a = BN_dup(src)) == NULL)
|
||||
return 0;
|
||||
BN_clear_free(*dst);
|
||||
*dst = a;
|
||||
return 1;
|
||||
return ffc_params_cmp(&a->pkey.dh->params, &a->pkey.dh->params,
|
||||
a->ameth != &dhx_asn1_meth);
|
||||
}
|
||||
|
||||
static int int_dh_param_copy(DH *to, const DH *from, int is_x942)
|
||||
{
|
||||
if (is_x942 == -1)
|
||||
is_x942 = ! !from->q;
|
||||
if (!int_dh_bn_cpy(&to->p, from->p))
|
||||
is_x942 = (from->params.q != NULL);
|
||||
if (!ffc_params_copy(&to->params, &from->params))
|
||||
return 0;
|
||||
if (!int_dh_bn_cpy(&to->g, from->g))
|
||||
return 0;
|
||||
if (is_x942) {
|
||||
if (!int_dh_bn_cpy(&to->q, from->q))
|
||||
return 0;
|
||||
if (!int_dh_bn_cpy(&to->j, from->j))
|
||||
return 0;
|
||||
OPENSSL_free(to->seed);
|
||||
to->seed = NULL;
|
||||
to->seedlen = 0;
|
||||
if (from->seed) {
|
||||
to->seed = OPENSSL_memdup(from->seed, from->seedlen);
|
||||
if (!to->seed)
|
||||
return 0;
|
||||
to->seedlen = from->seedlen;
|
||||
}
|
||||
} else
|
||||
if (!is_x942)
|
||||
to->length = from->length;
|
||||
to->dirty_cnt++;
|
||||
return 1;
|
||||
@@ -449,9 +381,9 @@ static int dh_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
|
||||
|
||||
static int dh_missing_parameters(const EVP_PKEY *a)
|
||||
{
|
||||
if (a->pkey.dh == NULL || a->pkey.dh->p == NULL || a->pkey.dh->g == NULL)
|
||||
return 1;
|
||||
return 0;
|
||||
return a->pkey.dh == NULL
|
||||
|| a->pkey.dh->params.p == NULL
|
||||
|| a->pkey.dh->params.g == NULL;
|
||||
}
|
||||
|
||||
static int dh_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
|
||||
@@ -550,51 +482,47 @@ static size_t dh_pkey_dirty_cnt(const EVP_PKEY *pkey)
|
||||
return pkey->pkey.dh->dirty_cnt;
|
||||
}
|
||||
|
||||
static void *dh_pkey_export_to(const EVP_PKEY *pk, EVP_KEYMGMT *keymgmt,
|
||||
int want_domainparams)
|
||||
static int dh_pkey_export_to(const EVP_PKEY *from, void *to_keydata,
|
||||
EVP_KEYMGMT *to_keymgmt)
|
||||
{
|
||||
DH *dh = pk->pkey.dh;
|
||||
DH *dh = from->pkey.dh;
|
||||
OSSL_PARAM_BLD tmpl;
|
||||
const BIGNUM *p = DH_get0_p(dh), *g = DH_get0_g(dh), *q = DH_get0_q(dh);
|
||||
const BIGNUM *pub_key = DH_get0_pub_key(dh);
|
||||
const BIGNUM *priv_key = DH_get0_priv_key(dh);
|
||||
OSSL_PARAM *params;
|
||||
void *provdata = NULL;
|
||||
int rv;
|
||||
|
||||
if (p == NULL || g == NULL)
|
||||
return NULL;
|
||||
return 0;
|
||||
|
||||
ossl_param_bld_init(&tmpl);
|
||||
if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_FFC_P, p)
|
||||
|| !ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_FFC_G, g))
|
||||
return NULL;
|
||||
return 0;
|
||||
if (q != NULL) {
|
||||
if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_FFC_Q, q))
|
||||
return NULL;
|
||||
return 0;
|
||||
}
|
||||
/* A key must at least have a public part. */
|
||||
if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_DH_PUB_KEY, pub_key))
|
||||
return 0;
|
||||
if (priv_key != NULL) {
|
||||
if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_DH_PRIV_KEY,
|
||||
priv_key))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!want_domainparams) {
|
||||
/* A key must at least have a public part. */
|
||||
if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_DH_PUB_KEY,
|
||||
pub_key))
|
||||
return NULL;
|
||||
|
||||
if (priv_key != NULL) {
|
||||
if (!ossl_param_bld_push_BN(&tmpl, OSSL_PKEY_PARAM_DH_PRIV_KEY,
|
||||
priv_key))
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
params = ossl_param_bld_to_param(&tmpl);
|
||||
if ((params = ossl_param_bld_to_param(&tmpl)) == NULL)
|
||||
return 0;
|
||||
|
||||
/* We export, the provider imports */
|
||||
provdata = want_domainparams
|
||||
? evp_keymgmt_importdomparams(keymgmt, params)
|
||||
: evp_keymgmt_importkey(keymgmt, params);
|
||||
rv = evp_keymgmt_import(to_keymgmt, to_keydata, OSSL_KEYMGMT_SELECT_ALL,
|
||||
params);
|
||||
|
||||
ossl_param_bld_free(params);
|
||||
return provdata;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD dh_asn1_meth = {
|
||||
@@ -820,6 +748,7 @@ static int dh_cms_set_shared_info(EVP_PKEY_CTX *pctx, CMS_RecipientInfo *ri)
|
||||
static int dh_cms_decrypt(CMS_RecipientInfo *ri)
|
||||
{
|
||||
EVP_PKEY_CTX *pctx;
|
||||
|
||||
pctx = CMS_RecipientInfo_get0_pkey_ctx(ri);
|
||||
|
||||
if (pctx == NULL)
|
||||
|
||||
Reference in New Issue
Block a user