+/*
+ * This checks the lookup capability of EC_GROUP_check_named_curve()
+ * when the given group was created with explicit parameters.
+ *
+ * It is possible to retrieve an alternative alias that does not match
+ * the original nid in this case.
+ */
+static int check_named_curve_lookup_test(int id)
+{
+ int ret = 0, nid, rv = 0;
+ EC_GROUP *g = NULL , *ga = NULL;
+ ECPARAMETERS *p = NULL, *pa = NULL;
+ BN_CTX *ctx = NULL;
+
+ /* Do some setup */
+ nid = curves[id].nid;
+ if (!TEST_ptr(ctx = BN_CTX_new())
+ || !TEST_ptr(g = EC_GROUP_new_by_curve_name(nid))
+ || !TEST_ptr(p = EC_GROUP_get_ecparameters(g, NULL)))
+ goto err;
+
+ /* replace with group from explicit parameters */
+ EC_GROUP_free(g);
+ if (!TEST_ptr(g = EC_GROUP_new_from_ecparameters(p)))
+ goto err;
+
+ if (!TEST_int_gt(rv = EC_GROUP_check_named_curve(g, 0), 0))
+ goto err;
+ if (rv != nid) {
+ /*
+ * Found an alias:
+ * fail if the returned nid is not an alias of the original group.
+ *
+ * The comparison here is done by comparing two explicit
+ * parameter EC_GROUPs with EC_GROUP_cmp(), to ensure the
+ * comparison happens with unnamed EC_GROUPs using the same
+ * EC_METHODs.
+ */
+ if (!TEST_ptr(ga = EC_GROUP_new_by_curve_name(rv))
+ || !TEST_ptr(pa = EC_GROUP_get_ecparameters(ga, NULL)))
+ goto err;
+
+ /* replace with group from explicit parameters, then compare */
+ EC_GROUP_free(ga);
+ if (!TEST_ptr(ga = EC_GROUP_new_from_ecparameters(pa))
+ || !TEST_int_eq(EC_GROUP_cmp(g, ga, ctx), 0))
+ goto err;
+ }
+
+ ret = 1;
+
+ err:
+ EC_GROUP_free(g);
+ EC_GROUP_free(ga);
+ ECPARAMETERS_free(p);
+ ECPARAMETERS_free(pa);
+ BN_CTX_free(ctx);
+
+ return ret;
+}
+