2020-01-24 12:09:33 +08:00
|
|
|
/*
|
2022-05-03 18:52:38 +08:00
|
|
|
* Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
|
2020-01-24 12:09:33 +08:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h> /* memset */
|
2020-04-15 19:02:52 +08:00
|
|
|
#include <openssl/core_names.h>
|
2020-01-24 12:09:33 +08:00
|
|
|
#include "internal/ffc.h"
|
2020-04-15 19:02:52 +08:00
|
|
|
#include "internal/param_build_set.h"
|
2020-06-17 09:33:16 +08:00
|
|
|
#include "internal/nelem.h"
|
2020-04-15 19:02:52 +08:00
|
|
|
|
2020-04-14 04:34:56 +08:00
|
|
|
#ifndef FIPS_MODULE
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
# include <openssl/asn1.h> /* ossl_ffc_params_print */
|
2020-01-24 12:09:33 +08:00
|
|
|
#endif
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
void ossl_ffc_params_init(FFC_PARAMS *params)
|
2020-01-24 12:09:33 +08:00
|
|
|
{
|
2020-02-16 16:02:38 +08:00
|
|
|
memset(params, 0, sizeof(*params));
|
2020-01-24 12:09:33 +08:00
|
|
|
params->pcounter = -1;
|
2020-02-06 20:28:36 +08:00
|
|
|
params->gindex = FFC_UNVERIFIABLE_GINDEX;
|
2021-05-10 08:27:42 +08:00
|
|
|
params->flags = FFC_PARAM_FLAG_VALIDATE_PQG;
|
2020-01-24 12:09:33 +08:00
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
void ossl_ffc_params_cleanup(FFC_PARAMS *params)
|
2020-01-24 12:09:33 +08:00
|
|
|
{
|
|
|
|
BN_free(params->p);
|
|
|
|
BN_free(params->q);
|
|
|
|
BN_free(params->g);
|
|
|
|
BN_free(params->j);
|
|
|
|
OPENSSL_free(params->seed);
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
ossl_ffc_params_init(params);
|
2020-01-24 12:09:33 +08:00
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
void ossl_ffc_params_set0_pqg(FFC_PARAMS *d, BIGNUM *p, BIGNUM *q, BIGNUM *g)
|
2020-01-24 12:09:33 +08:00
|
|
|
{
|
|
|
|
if (p != NULL && p != d->p) {
|
|
|
|
BN_free(d->p);
|
|
|
|
d->p = p;
|
|
|
|
}
|
|
|
|
if (q != NULL && q != d->q) {
|
|
|
|
BN_free(d->q);
|
|
|
|
d->q = q;
|
|
|
|
}
|
|
|
|
if (g != NULL && g != d->g) {
|
|
|
|
BN_free(d->g);
|
|
|
|
d->g = g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
void ossl_ffc_params_get0_pqg(const FFC_PARAMS *d, const BIGNUM **p,
|
|
|
|
const BIGNUM **q, const BIGNUM **g)
|
2020-01-24 12:09:33 +08:00
|
|
|
{
|
|
|
|
if (p != NULL)
|
|
|
|
*p = d->p;
|
|
|
|
if (q != NULL)
|
|
|
|
*q = d->q;
|
|
|
|
if (g != NULL)
|
|
|
|
*g = d->g;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* j is the 'cofactor' that is optionally output for ASN1. */
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
void ossl_ffc_params_set0_j(FFC_PARAMS *d, BIGNUM *j)
|
2020-01-24 12:09:33 +08:00
|
|
|
{
|
|
|
|
BN_free(d->j);
|
|
|
|
d->j = NULL;
|
|
|
|
if (j != NULL)
|
|
|
|
d->j = j;
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
int ossl_ffc_params_set_seed(FFC_PARAMS *params,
|
|
|
|
const unsigned char *seed, size_t seedlen)
|
2020-01-24 12:09:33 +08:00
|
|
|
{
|
2020-04-15 19:02:52 +08:00
|
|
|
if (params->seed != NULL) {
|
|
|
|
if (params->seed == seed)
|
|
|
|
return 1;
|
2020-01-24 12:09:33 +08:00
|
|
|
OPENSSL_free(params->seed);
|
2020-04-15 19:02:52 +08:00
|
|
|
}
|
2020-01-24 12:09:33 +08:00
|
|
|
|
|
|
|
if (seed != NULL && seedlen > 0) {
|
|
|
|
params->seed = OPENSSL_memdup(seed, seedlen);
|
|
|
|
if (params->seed == NULL)
|
|
|
|
return 0;
|
|
|
|
params->seedlen = seedlen;
|
|
|
|
} else {
|
|
|
|
params->seed = NULL;
|
|
|
|
params->seedlen = 0;
|
|
|
|
}
|
2020-04-15 19:02:52 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
void ossl_ffc_params_set_gindex(FFC_PARAMS *params, int index)
|
2020-04-15 19:02:52 +08:00
|
|
|
{
|
|
|
|
params->gindex = index;
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
void ossl_ffc_params_set_pcounter(FFC_PARAMS *params, int index)
|
2020-04-15 19:02:52 +08:00
|
|
|
{
|
|
|
|
params->pcounter = index;
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
void ossl_ffc_params_set_h(FFC_PARAMS *params, int index)
|
2020-04-15 19:02:52 +08:00
|
|
|
{
|
|
|
|
params->h = index;
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
void ossl_ffc_params_set_flags(FFC_PARAMS *params, unsigned int flags)
|
2020-06-17 09:33:16 +08:00
|
|
|
{
|
|
|
|
params->flags = flags;
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
void ossl_ffc_params_enable_flags(FFC_PARAMS *params, unsigned int flags,
|
|
|
|
int enable)
|
2020-08-11 08:15:28 +08:00
|
|
|
{
|
|
|
|
if (enable)
|
|
|
|
params->flags |= flags;
|
|
|
|
else
|
|
|
|
params->flags &= ~flags;
|
|
|
|
}
|
|
|
|
|
2023-02-22 12:16:05 +08:00
|
|
|
void ossl_ffc_set_digest(FFC_PARAMS *params, const char *alg, const char *props)
|
2020-06-17 09:33:16 +08:00
|
|
|
{
|
|
|
|
params->mdname = alg;
|
|
|
|
params->mdprops = props;
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
int ossl_ffc_params_set_validate_params(FFC_PARAMS *params,
|
|
|
|
const unsigned char *seed,
|
|
|
|
size_t seedlen, int counter)
|
2020-04-15 19:02:52 +08:00
|
|
|
{
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
if (!ossl_ffc_params_set_seed(params, seed, seedlen))
|
2020-04-15 19:02:52 +08:00
|
|
|
return 0;
|
2020-01-24 12:09:33 +08:00
|
|
|
params->pcounter = counter;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
void ossl_ffc_params_get_validate_params(const FFC_PARAMS *params,
|
|
|
|
unsigned char **seed, size_t *seedlen,
|
|
|
|
int *pcounter)
|
2020-01-24 12:09:33 +08:00
|
|
|
{
|
|
|
|
if (seed != NULL)
|
|
|
|
*seed = params->seed;
|
|
|
|
if (seedlen != NULL)
|
|
|
|
*seedlen = params->seedlen;
|
|
|
|
if (pcounter != NULL)
|
|
|
|
*pcounter = params->pcounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ffc_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;
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
int ossl_ffc_params_copy(FFC_PARAMS *dst, const FFC_PARAMS *src)
|
2020-01-24 12:09:33 +08:00
|
|
|
{
|
|
|
|
if (!ffc_bn_cpy(&dst->p, src->p)
|
|
|
|
|| !ffc_bn_cpy(&dst->g, src->g)
|
|
|
|
|| !ffc_bn_cpy(&dst->q, src->q)
|
|
|
|
|| !ffc_bn_cpy(&dst->j, src->j))
|
|
|
|
return 0;
|
|
|
|
|
2023-02-27 14:35:41 +08:00
|
|
|
dst->mdname = src->mdname;
|
|
|
|
dst->mdprops = src->mdprops;
|
2020-01-24 12:09:33 +08:00
|
|
|
OPENSSL_free(dst->seed);
|
|
|
|
dst->seedlen = src->seedlen;
|
|
|
|
if (src->seed != NULL) {
|
|
|
|
dst->seed = OPENSSL_memdup(src->seed, src->seedlen);
|
|
|
|
if (dst->seed == NULL)
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
dst->seed = NULL;
|
|
|
|
}
|
2020-04-15 19:02:52 +08:00
|
|
|
dst->nid = src->nid;
|
2020-01-24 12:09:33 +08:00
|
|
|
dst->pcounter = src->pcounter;
|
2020-04-15 19:02:52 +08:00
|
|
|
dst->h = src->h;
|
|
|
|
dst->gindex = src->gindex;
|
2021-03-20 01:45:43 +08:00
|
|
|
dst->flags = src->flags;
|
2022-07-14 18:32:03 +08:00
|
|
|
dst->keylength = src->keylength;
|
2020-01-24 12:09:33 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
int ossl_ffc_params_cmp(const FFC_PARAMS *a, const FFC_PARAMS *b, int ignore_q)
|
2020-01-24 12:09:33 +08:00
|
|
|
{
|
|
|
|
return BN_cmp(a->p, b->p) == 0
|
|
|
|
&& BN_cmp(a->g, b->g) == 0
|
|
|
|
&& (ignore_q || BN_cmp(a->q, b->q) == 0); /* Note: q may be NULL */
|
|
|
|
}
|
|
|
|
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
int ossl_ffc_params_todata(const FFC_PARAMS *ffc, OSSL_PARAM_BLD *bld,
|
2020-04-15 19:02:52 +08:00
|
|
|
OSSL_PARAM params[])
|
|
|
|
{
|
2021-05-10 08:27:42 +08:00
|
|
|
int test_flags;
|
|
|
|
|
2020-04-15 19:02:52 +08:00
|
|
|
if (ffc->p != NULL
|
|
|
|
&& !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_FFC_P, ffc->p))
|
|
|
|
return 0;
|
|
|
|
if (ffc->q != NULL
|
|
|
|
&& !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_FFC_Q, ffc->q))
|
|
|
|
return 0;
|
|
|
|
if (ffc->g != NULL
|
|
|
|
&& !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_FFC_G, ffc->g))
|
|
|
|
return 0;
|
|
|
|
if (ffc->j != NULL
|
|
|
|
&& !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_FFC_COFACTOR,
|
|
|
|
ffc->j))
|
|
|
|
return 0;
|
|
|
|
if (!ossl_param_build_set_int(bld, params, OSSL_PKEY_PARAM_FFC_GINDEX,
|
|
|
|
ffc->gindex))
|
|
|
|
return 0;
|
|
|
|
if (!ossl_param_build_set_int(bld, params, OSSL_PKEY_PARAM_FFC_PCOUNTER,
|
|
|
|
ffc->pcounter))
|
|
|
|
return 0;
|
|
|
|
if (!ossl_param_build_set_int(bld, params, OSSL_PKEY_PARAM_FFC_H, ffc->h))
|
|
|
|
return 0;
|
|
|
|
if (ffc->seed != NULL
|
|
|
|
&& !ossl_param_build_set_octet_string(bld, params,
|
|
|
|
OSSL_PKEY_PARAM_FFC_SEED,
|
|
|
|
ffc->seed, ffc->seedlen))
|
|
|
|
return 0;
|
|
|
|
if (ffc->nid != NID_undef) {
|
2020-12-02 02:11:59 +08:00
|
|
|
const DH_NAMED_GROUP *group = ossl_ffc_uid_to_dh_named_group(ffc->nid);
|
|
|
|
const char *name = ossl_ffc_named_group_get_name(group);
|
2020-04-15 19:02:52 +08:00
|
|
|
|
|
|
|
if (name == NULL
|
|
|
|
|| !ossl_param_build_set_utf8_string(bld, params,
|
2020-05-20 21:46:22 +08:00
|
|
|
OSSL_PKEY_PARAM_GROUP_NAME,
|
2020-04-15 19:02:52 +08:00
|
|
|
name))
|
|
|
|
return 0;
|
|
|
|
}
|
2021-05-10 08:27:42 +08:00
|
|
|
test_flags = ((ffc->flags & FFC_PARAM_FLAG_VALIDATE_PQ) != 0);
|
|
|
|
if (!ossl_param_build_set_int(bld, params,
|
|
|
|
OSSL_PKEY_PARAM_FFC_VALIDATE_PQ, test_flags))
|
2020-06-17 09:33:16 +08:00
|
|
|
return 0;
|
2021-05-10 08:27:42 +08:00
|
|
|
test_flags = ((ffc->flags & FFC_PARAM_FLAG_VALIDATE_G) != 0);
|
|
|
|
if (!ossl_param_build_set_int(bld, params,
|
|
|
|
OSSL_PKEY_PARAM_FFC_VALIDATE_G, test_flags))
|
|
|
|
return 0;
|
|
|
|
test_flags = ((ffc->flags & FFC_PARAM_FLAG_VALIDATE_LEGACY) != 0);
|
|
|
|
if (!ossl_param_build_set_int(bld, params,
|
|
|
|
OSSL_PKEY_PARAM_FFC_VALIDATE_LEGACY,
|
|
|
|
test_flags))
|
|
|
|
return 0;
|
|
|
|
|
2020-06-17 09:33:16 +08:00
|
|
|
if (ffc->mdname != NULL
|
|
|
|
&& !ossl_param_build_set_utf8_string(bld, params,
|
|
|
|
OSSL_PKEY_PARAM_FFC_DIGEST,
|
|
|
|
ffc->mdname))
|
|
|
|
return 0;
|
|
|
|
if (ffc->mdprops != NULL
|
|
|
|
&& !ossl_param_build_set_utf8_string(bld, params,
|
|
|
|
OSSL_PKEY_PARAM_FFC_DIGEST_PROPS,
|
|
|
|
ffc->mdprops))
|
|
|
|
return 0;
|
2020-04-15 19:02:52 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-04-14 04:34:56 +08:00
|
|
|
#ifndef FIPS_MODULE
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
int ossl_ffc_params_print(BIO *bp, const FFC_PARAMS *ffc, int indent)
|
2020-01-24 12:09:33 +08:00
|
|
|
{
|
|
|
|
if (!ASN1_bn_print(bp, "prime P:", ffc->p, NULL, indent))
|
|
|
|
goto err;
|
|
|
|
if (!ASN1_bn_print(bp, "generator G:", ffc->g, NULL, indent))
|
|
|
|
goto err;
|
|
|
|
if (ffc->q != NULL
|
|
|
|
&& !ASN1_bn_print(bp, "subgroup order Q:", ffc->q, NULL, indent))
|
|
|
|
goto err;
|
|
|
|
if (ffc->j != NULL
|
|
|
|
&& !ASN1_bn_print(bp, "subgroup factor:", ffc->j, NULL, indent))
|
|
|
|
goto err;
|
|
|
|
if (ffc->seed != NULL) {
|
|
|
|
size_t i;
|
2020-08-24 10:16:24 +08:00
|
|
|
|
|
|
|
if (!BIO_indent(bp, indent, 128)
|
|
|
|
|| BIO_puts(bp, "seed:") <= 0)
|
|
|
|
goto err;
|
2020-01-24 12:09:33 +08:00
|
|
|
for (i = 0; i < ffc->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", ffc->seed[i],
|
|
|
|
((i + 1) == ffc->seedlen) ? "" : ":") <= 0)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (BIO_write(bp, "\n", 1) <= 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ffc->pcounter != -1) {
|
2020-08-24 10:16:24 +08:00
|
|
|
if (!BIO_indent(bp, indent, 128)
|
|
|
|
|| BIO_printf(bp, "counter: %d\n", ffc->pcounter) <= 0)
|
2020-01-24 12:09:33 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
err:
|
|
|
|
return 0;
|
|
|
|
}
|
2020-04-14 04:34:56 +08:00
|
|
|
#endif /* FIPS_MODULE */
|