2 * Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 * ECDSA low level APIs are deprecated for public use, but still ok for
14 #include "internal/deprecated.h"
17 #include <openssl/err.h>
19 int EC_GROUP_check_named_curve(const EC_GROUP *group, int nist_only,
24 BN_CTX *new_ctx = NULL;
27 ctx = new_ctx = BN_CTX_new();
29 ECerr(EC_F_EC_GROUP_CHECK_NAMED_CURVE, ERR_R_MALLOC_FAILURE);
35 nid = ec_curve_nid_from_params(group, ctx);
36 if (nid > 0 && nist_only && EC_curve_nid2nist(nid) == NULL)
46 int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)
50 * ECC domain parameter validation.
51 * See SP800-56A R3 5.5.2 "Assurances of Domain-Parameter Validity" Part 1b.
53 return EC_GROUP_check_named_curve(group, 1, ctx) >= 0 ? 1 : 0;
57 BN_CTX *new_ctx = NULL;
58 EC_POINT *point = NULL;
60 if (group == NULL || group->meth == NULL) {
61 ECerr(EC_F_EC_GROUP_CHECK, ERR_R_PASSED_NULL_PARAMETER);
65 /* Custom curves assumed to be correct */
66 if ((group->meth->flags & EC_FLAGS_CUSTOM_CURVE) != 0)
70 ctx = new_ctx = BN_CTX_new();
72 ECerr(EC_F_EC_GROUP_CHECK, ERR_R_MALLOC_FAILURE);
77 /* check the discriminant */
78 if (!EC_GROUP_check_discriminant(group, ctx)) {
79 ECerr(EC_F_EC_GROUP_CHECK, EC_R_DISCRIMINANT_IS_ZERO);
83 /* check the generator */
84 if (group->generator == NULL) {
85 ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_GENERATOR);
88 if (EC_POINT_is_on_curve(group, group->generator, ctx) <= 0) {
89 ECerr(EC_F_EC_GROUP_CHECK, EC_R_POINT_IS_NOT_ON_CURVE);
93 /* check the order of the generator */
94 if ((point = EC_POINT_new(group)) == NULL)
96 order = EC_GROUP_get0_order(group);
99 if (BN_is_zero(order)) {
100 ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_ORDER);
104 if (!EC_POINT_mul(group, point, order, NULL, NULL, ctx))
106 if (!EC_POINT_is_at_infinity(group, point)) {
107 ECerr(EC_F_EC_GROUP_CHECK, EC_R_INVALID_GROUP_ORDER);
114 BN_CTX_free(new_ctx);
115 EC_POINT_free(point);
117 #endif /* FIPS_MODE */