+ "NIST curve B-409",
+ "0200000000000000000000000000000000000000"
+ "0000000000000000000000000000000000000000008000000000000000000001",
+ "0000000000000000000000000000000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000001",
+ "0021A5C2C8EE9FEB5C4B9A753B7B476B7FD6422E"
+ "F1F3DD674761FA99D6AC27C8A9A197B272822F6CD57A55AA4F50AE317B13545F",
+ "015D4860D088DDB3496B0C6064756260441CDE4A"
+ "F1771D4DB01FFE5B34E59703DC255A868A1180515603AEAB60794E54BB7996A7",
+ "0061B1CFAB6BE5F32BBFA78324ED106A7636B9C5"
+ "A7BD198D0158AA4F5488D08F38514F1FDF4B4F40D2181B3681C364BA0273C706",
+ 1,
+ "0100000000000000000000000000000000000000"
+ "00000000000001E2AAD6A612F33307BE5FA47C3C9E052F838164CD37D9A21173",
+ "2", 409
+ },
+ /* Curve K-571 (FIPS PUB 186-2, App. 6) */
+ {
+ "NIST curve K-571",
+ "800000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000425",
+ "0",
+ "1",
+ "026EB7A859923FBC"
+ "82189631F8103FE4AC9CA2970012D5D46024804801841CA44370958493B205E6"
+ "47DA304DB4CEB08CBBD1BA39494776FB988B47174DCA88C7E2945283A01C8972",
+ "0349DC807F4FBF37"
+ "4F4AEADE3BCA95314DD58CEC9F307A54FFC61EFC006D8A2C9D4979C0AC44AEA7"
+ "4FBEBBB9F772AEDCB620B01A7BA7AF1B320430C8591984F601CD4C143EF1C7A3",
+ 0,
+ "0200000000000000"
+ "00000000000000000000000000000000000000000000000000000000131850E1"
+ "F19A63E4B391A8DB917F4138B630D84BE5D639381E91DEB45CFE778F637C1001",
+ "4", 571
+ },
+ /* Curve B-571 (FIPS PUB 186-2, App. 6) */
+ {
+ "NIST curve B-571",
+ "800000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000425",
+ "0000000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000001",
+ "02F40E7E2221F295"
+ "DE297117B7F3D62F5C6A97FFCB8CEFF1CD6BA8CE4A9A18AD84FFABBD8EFA5933"
+ "2BE7AD6756A66E294AFD185A78FF12AA520E4DE739BACA0C7FFEFF7F2955727A",
+ "0303001D34B85629"
+ "6C16C0D40D3CD7750A93D1D2955FA80AA5F40FC8DB7B2ABDBDE53950F4C0D293"
+ "CDD711A35B67FB1499AE60038614F1394ABFA3B4C850D927E1E7769C8EEC2D19",
+ "037BF27342DA639B"
+ "6DCCFFFEB73D69D78C6C27A6009CBBCA1980F8533921E8A684423E43BAB08A57"
+ "6291AF8F461BB2A8B3531D2F0485C19B16E2F1516E23DD3C1A4827AF1B8AC15B",
+ 1,
+ "03FFFFFFFFFFFFFF"
+ "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE661CE18"
+ "FF55987308059B186823851EC7DD9CA1161DE93D5174D66E8382E9BB2FE84E47",
+ "2", 571
+ }
+};
+
+static int char2_curve_test(int n)
+{
+ int r = 0;
+ BN_CTX *ctx = NULL;
+ BIGNUM *p = NULL, *a = NULL, *b = NULL;
+ BIGNUM *x = NULL, *y = NULL, *z = NULL, *cof = NULL, *yplusone = NULL;
+ EC_GROUP *group = NULL, *variable = NULL;
+ EC_POINT *P = NULL, *Q = NULL, *R = NULL;
+ const EC_POINT *points[3];
+ const BIGNUM *scalars[3];
+ struct c2_curve_test *const test = char2_curve_tests + n;
+
+ if (!TEST_ptr(ctx = BN_CTX_new())
+ || !TEST_ptr(p = BN_new())
+ || !TEST_ptr(a = BN_new())
+ || !TEST_ptr(b = BN_new())
+ || !TEST_ptr(x = BN_new())
+ || !TEST_ptr(y = BN_new())
+ || !TEST_ptr(z = BN_new())
+ || !TEST_ptr(yplusone = BN_new())
+ || !TEST_true(BN_hex2bn(&p, test->p))
+ || !TEST_true(BN_hex2bn(&a, test->a))
+ || !TEST_true(BN_hex2bn(&b, test->b))
+ || !TEST_true(group = EC_GROUP_new(EC_GF2m_simple_method()))
+ || !TEST_true(EC_GROUP_set_curve_GF2m(group, p, a, b, ctx))
+ || !TEST_ptr(P = EC_POINT_new(group))
+ || !TEST_ptr(Q = EC_POINT_new(group))
+ || !TEST_ptr(R = EC_POINT_new(group))
+ || !TEST_true(BN_hex2bn(&x, test->x))
+ || !TEST_true(BN_hex2bn(&y, test->y))
+ || !TEST_true(BN_add(yplusone, y, BN_value_one())))
+ goto err;
+
+/* Change test based on whether binary point compression is enabled or not. */
+# ifdef OPENSSL_EC_BIN_PT_COMP
+ /*
+ * When (x, y) is on the curve, (x, y + 1) is, as it happens, not,
+ * and therefore setting the coordinates should fail.
+ */
+ if (!TEST_false(EC_POINT_set_affine_coordinates_GF2m(group, P, x, yplusone,
+ ctx))
+ || !TEST_true(EC_POINT_set_compressed_coordinates_GF2m(group, P, x,
+ test->y_bit,
+ ctx))
+ || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)
+ || !TEST_true(BN_hex2bn(&z, test->order))
+ || !TEST_true(BN_hex2bn(&cof, test->cof))
+ || !TEST_true(EC_GROUP_set_generator(group, P, z, cof))
+ || !TEST_true(EC_POINT_get_affine_coordinates_GF2m(group, P, x, y,
+ ctx)))
+ goto err;
+ TEST_info("%s -- Generator", test->name);
+ test_output_bignum("x", x);
+ test_output_bignum("y", y);
+ /* G_y value taken from the standard: */
+ if (!TEST_true(BN_hex2bn(&z, test->y))
+ || !TEST_BN_eq(y, z))
+ goto err;
+# else
+ /*
+ * When (x, y) is on the curve, (x, y + 1) is, as it happens, not,
+ * and therefore setting the coordinates should fail.
+ */
+ if (!TEST_false(EC_POINT_set_affine_coordinates_GF2m(group, P, x, yplusone,
+ ctx))
+ || !TEST_true(EC_POINT_set_affine_coordinates_GF2m(group, P, x, y, ctx))
+ || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)
+ || !TEST_true(BN_hex2bn(&z, test->order))
+ || !TEST_true(BN_hex2bn(&cof, test->cof))
+ || !TEST_true(EC_GROUP_set_generator(group, P, z, cof)))
+ goto err;
+ TEST_info("%s -- Generator:", test->name);
+ test_output_bignum("x", x);
+ test_output_bignum("y", y);
+# endif
+
+ if (!TEST_int_eq(EC_GROUP_get_degree(group), test->degree)
+ || !group_order_tests(group)
+ || !TEST_ptr(variable = EC_GROUP_new(EC_GROUP_method_of(group)))
+ || !TEST_true(EC_GROUP_copy(variable, group)))
+ goto err;
+
+ /* more tests using the last curve */
+ if (n == OSSL_NELEM(char2_curve_tests) - 1) {
+ if (!TEST_true(EC_POINT_set_affine_coordinates_GF2m(group, P, x, y,
+ ctx))
+ || !TEST_true(EC_POINT_copy(Q, P))
+ || !TEST_false(EC_POINT_is_at_infinity(group, Q))
+ || !TEST_true(EC_POINT_dbl(group, P, P, ctx))
+ || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)
+ || !TEST_true(EC_POINT_invert(group, Q, ctx)) /* P = -2Q */
+ || !TEST_true(EC_POINT_add(group, R, P, Q, ctx))
+ || !TEST_true(EC_POINT_add(group, R, R, Q, ctx))
+ || !TEST_true(EC_POINT_is_at_infinity(group, R)) /* R = P + 2Q */
+ || !TEST_false(EC_POINT_is_at_infinity(group, Q)))
+ goto err;