|| !TEST_true(BN_add_word(other_cofactor, 1)))
goto err;
- /* Determine if the inbuilt curve has a seed field set */
+ /* Determine if the built-in curve has a seed field set */
has_seed = (EC_GROUP_get_seed_len(group) > 0);
field_nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group));
if (field_nid == NID_X9_62_characteristic_two_field) {
if (has_seed) {
/*
- * If the built in curve has a seed and we set the seed to another value
+ * If the built-in curve has a seed and we set the seed to another value
* then it will fail the check.
*/
if (!TEST_int_eq(EC_GROUP_check_named_curve(group, 0), 0))
goto err;
} else {
/*
- * If the built in curve does not have a seed then setting the seed will
+ * If the built-in curve does not have a seed then setting the seed will
* pass the check (as the seed is optional).
*/
if (!TEST_int_eq(EC_GROUP_check_named_curve(group, 0), nid))
unsigned char *buf = NULL;
int r = 0, len;
- if (!TEST_ptr(group = EC_GROUP_new_by_curve_name(NID_secp112r1))
+ if (!TEST_ptr(group = EC_GROUP_new_by_curve_name(NID_secp224r1))
|| !TEST_ptr(ecparameters = EC_GROUP_get_ecparameters(group, NULL))
|| !TEST_ptr(group2 = EC_GROUP_new_from_ecparameters(ecparameters))
|| !TEST_int_eq(EC_GROUP_cmp(group, group2, NULL), 0))
OPENSSL_free(buf);
return r;
}
+
+static int check_ec_key_field_public_range_test(int id)
+{
+ int ret = 0, type = 0;
+ const EC_POINT *pub = NULL;
+ const EC_GROUP *group = NULL;
+ const EC_METHOD *meth = NULL;
+ const BIGNUM *field = NULL;
+ BIGNUM *x = NULL, *y = NULL;
+ EC_KEY *key = NULL;
+
+ if (!(TEST_ptr(x = BN_new())
+ && TEST_ptr(y = BN_new())
+ && TEST_ptr(key = EC_KEY_new_by_curve_name(curves[id].nid))
+ && TEST_ptr(group = EC_KEY_get0_group(key))
+ && TEST_ptr(meth = EC_GROUP_method_of(group))
+ && TEST_ptr(field = EC_GROUP_get0_field(group))
+ && TEST_int_gt(EC_KEY_generate_key(key), 0)
+ && TEST_int_gt(EC_KEY_check_key(key), 0)
+ && TEST_ptr(pub = EC_KEY_get0_public_key(key))
+ && TEST_int_gt(EC_POINT_get_affine_coordinates(group, pub, x, y,
+ NULL), 0)))
+ goto err;
+
+ /*
+ * Make the public point out of range by adding the field (which will still
+ * be the same point on the curve). The add is different for char2 fields.
+ */
+ type = EC_METHOD_get_field_type(meth);
+#ifndef OPENSSL_NO_EC2M
+ if (type == NID_X9_62_characteristic_two_field) {
+ /* test for binary curves */
+ if (!TEST_true(BN_GF2m_add(x, x, field)))
+ goto err;
+ } else
#endif
+ if (type == NID_X9_62_prime_field) {
+ /* test for prime curves */
+ if (!TEST_true(BN_add(x, x, field)))
+ goto err;
+ } else {
+ /* this should never happen */
+ TEST_error("Unsupported EC_METHOD field_type");
+ goto err;
+ }
+ if (!TEST_int_le(EC_KEY_set_public_key_affine_coordinates(key, x, y), 0))
+ goto err;
+
+ ret = 1;
+err:
+ BN_free(x);
+ BN_free(y);
+ EC_KEY_free(key);
+ return ret;
+}
+#endif /* OPENSSL_NO_EC */
int setup_tests(void)
{
ADD_TEST(group_field_test);
ADD_ALL_TESTS(check_named_curve_test, crv_len);
ADD_ALL_TESTS(check_named_curve_lookup_test, crv_len);
-#endif
+ ADD_ALL_TESTS(check_ec_key_field_public_range_test, crv_len);
+#endif /* OPENSSL_NO_EC */
return 1;
}