Don't generate buildtest_*err.c
[openssl.git] / test / ectest.c
index c057bd903370b00771b9b1c13cfd87e94e864dc9..e49920cec7fd6ea6322d3c7bb6abe8e1ddae2850 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright 2001-2017 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
  *
  * Licensed under the OpenSSL license (the "License").  You may not use
  * this file except in compliance with the License.  You can obtain a copy
@@ -7,21 +8,7 @@
  * https://www.openssl.org/source/license.html
  */
 
-/* ====================================================================
- * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
- *
- * Portions of the attached software ("Contribution") are developed by
- * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
- *
- * The Contribution is licensed pursuant to the OpenSSL open source
- * license provided above.
- *
- * The elliptic curve binary polynomial software is originally written by
- * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
- *
- */
-
-#include "e_os.h"
+#include "internal/nelem.h"
 #include "testutil.h"
 
 #ifndef OPENSSL_NO_EC
 # include <openssl/bn.h>
 # include <openssl/opensslconf.h>
 
-# if defined(_MSC_VER) && defined(_MIPS_) && (_MSC_VER/100==12)
-/* suppress "too big too optimize" warning */
-#  pragma warning(disable:4959)
-# endif
-
 static size_t crv_len = 0;
 static EC_builtin_curve *curves = NULL;
 
@@ -161,7 +143,7 @@ static int prime_field_tests(void)
     const EC_POINT *points[4];
     const BIGNUM *scalars[4];
     unsigned char buf[100];
-    size_t i, len, r = 0;
+    size_t len, r = 0;
     int k;
 
     if (!TEST_ptr(ctx = BN_CTX_new())
@@ -187,15 +169,11 @@ static int prime_field_tests(void)
     if (!TEST_true(EC_GROUP_get_curve_GFp(group, p, a, b, ctx)))
         goto err;
 
-    BIO_printf(bio_out,
-            "Curve defined by Weierstrass equation\n"
-            "     y^2 = x^3 + a*x + b  (mod 0x");
-    BN_print(bio_out, p);
-    BIO_printf(bio_out, ")\n     a = 0x");
-    BN_print(bio_out, a);
-    BIO_printf(bio_out, "\n     b = 0x");
-    BN_print(bio_out, b);
-    BIO_printf(bio_out, "\n");
+    TEST_info("Curve defined by Weierstrass equation");
+    TEST_note("     y^2 = x^3 + a*x + b (mod p)");
+    test_output_bignum("a", a);
+    test_output_bignum("b", b);
+    test_output_bignum("p", p);
 
     buf[0] = 0;
     if (!TEST_ptr(P = EC_POINT_new(group))
@@ -219,32 +197,27 @@ static int prime_field_tests(void)
         if (!TEST_true(EC_POINT_get_affine_coordinates_GFp(group, Q, x, y,
                                                            ctx)))
             goto err;
-        BIO_printf(bio_err, "Point is not on curve: x = 0x");
-        BN_print_fp(stderr, x);
-        BIO_printf(bio_err, ", y = 0x");
-        BN_print_fp(stderr, y);
-        BIO_printf(bio_err, "\n");
+        TEST_info("Point is not on curve");
+        test_output_bignum("x", x);
+        test_output_bignum("y", y);
         goto err;
     }
 
-    BIO_printf(bio_out, "A cyclic subgroup:\n");
+    TEST_note("A cyclic subgroup:");
     k = 100;
     do {
         if (!TEST_int_ne(k--, 0))
             goto err;
 
         if (EC_POINT_is_at_infinity(group, P)) {
-            BIO_printf(bio_out, "     point at infinity\n");
+            TEST_note("     point at infinity");
         } else {
             if (!TEST_true(EC_POINT_get_affine_coordinates_GFp(group, P, x, y,
                                                                ctx)))
                 goto err;
 
-            BIO_printf(bio_out, "     x = 0x");
-            BN_print(bio_out, x);
-            BIO_printf(bio_out, ", y = 0x");
-            BN_print(bio_out, y);
-            BIO_printf(bio_out, "\n");
+            test_output_bignum("x", x);
+            test_output_bignum("y", y);
         }
 
         if (!TEST_true(EC_POINT_copy(R, P))
@@ -259,49 +232,40 @@ static int prime_field_tests(void)
 
     len =
         EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf,
-                           sizeof buf, ctx);
+                           sizeof(buf), ctx);
     if (!TEST_size_t_ne(len, 0)
         || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))
         || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))
         goto err;
-    BIO_printf(bio_out, "Generator as octet string, compressed form:\n     ");
-    for (i = 0; i < len; i++)
-        BIO_printf(bio_out, "%02X", buf[i]);
+    test_output_memory("Generator as octet string, compressed form:",
+                       buf, len);
 
     len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED,
-                             buf, sizeof buf, ctx);
+                             buf, sizeof(buf), ctx);
     if (!TEST_size_t_ne(len, 0)
         || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))
         || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))
         goto err;
-    BIO_printf(bio_out, "\nGenerator as octet string, uncompressed form:\n"
-                        "     ");
-    for (i = 0; i < len; i++)
-        BIO_printf(bio_out, "%02X", buf[i]);
+    test_output_memory("Generator as octet string, uncompressed form:",
+                       buf, len);
 
     len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID,
-                             buf, sizeof buf, ctx);
+                             buf, sizeof(buf), ctx);
     if (!TEST_size_t_ne(len, 0)
         || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))
         || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))
         goto err;
-    BIO_printf(bio_out, "\nGenerator as octet string, hybrid form:\n     ");
-    for (i = 0; i < len; i++)
-        BIO_printf(bio_out, "%02X", buf[i]);
+    test_output_memory("Generator as octet string, hybrid form:",
+                       buf, len);
 
     if (!TEST_true(EC_POINT_get_Jprojective_coordinates_GFp(group, R, x, y, z,
                                                             ctx)))
         goto err;
-    BIO_printf(bio_out,
-               "\nA representation of the inverse of that generator in\n"
-               "Jacobian projective coordinates:\n"
-               "     X = 0x");
-    BN_print(bio_out, x);
-    BIO_printf(bio_out, ", Y = 0x");
-    BN_print(bio_out, y);
-    BIO_printf(bio_out, ", Z = 0x");
-    BN_print(bio_out, z);
-    BIO_printf(bio_out, "\n");
+    TEST_info("A representation of the inverse of that generator in");
+    TEST_note("Jacobian projective coordinates");
+    test_output_bignum("x", x);
+    test_output_bignum("y", y);
+    test_output_bignum("z", z);
 
     if (!TEST_true(EC_POINT_invert(group, P, ctx))
         || !TEST_int_eq(0, EC_POINT_cmp(group, P, R, ctx))
@@ -337,15 +301,13 @@ static int prime_field_tests(void)
         || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))
         || !TEST_true(EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)))
         goto err;
-    BIO_printf(bio_out, "\nSEC2 curve secp160r1 -- Generator:\n     x = 0x");
-    BN_print(bio_out, x);
-    BIO_printf(bio_out, "\n     y = 0x");
-    BN_print(bio_out, y);
-    BIO_printf(bio_out, "\n");
+    TEST_info("SEC2 curve secp160r1 -- Generator");
+    test_output_bignum("x", x);
+    test_output_bignum("y", y);
     /* G_y value taken from the standard: */
     if (!TEST_true(BN_hex2bn(&z,                         "23a62855"
                                  "3168947d59dcc912042351377ac5fb32"))
-        || !TEST_int_eq(0, BN_cmp(y, z))
+        || !TEST_BN_eq(y, z)
         || !TEST_int_eq(EC_GROUP_get_degree(group), 160)
         || !group_order_tests(group)
         || !TEST_ptr(P_160 = EC_GROUP_new(EC_GROUP_method_of(group)))
@@ -372,15 +334,13 @@ static int prime_field_tests(void)
         || !TEST_true(EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)))
         goto err;
 
-    BIO_printf(bio_out, "\nNIST curve P-192 -- Generator:\n     x = 0x");
-    BN_print(bio_out, x);
-    BIO_printf(bio_out, "\n     y = 0x");
-    BN_print(bio_out, y);
-    BIO_printf(bio_out, "\n");
+    TEST_info("NIST curve P-192 -- Generator");
+    test_output_bignum("x", x);
+    test_output_bignum("y", y);
     /* G_y value taken from the standard: */
     if (!TEST_true(BN_hex2bn(&z,                 "07192B95FFC8DA78"
                                  "631011ED6B24CDD573F977A11E794811"))
-        || !TEST_int_eq(0, BN_cmp(y, z))
+        || !TEST_BN_eq(y, z)
         || !TEST_true(BN_add(yplusone, y, BN_value_one()))
     /*
      * When (x, y) is on the curve, (x, y + 1) is, as it happens, not,
@@ -414,15 +374,13 @@ static int prime_field_tests(void)
         || !TEST_true(EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)))
         goto err;
 
-    BIO_printf(bio_out, "\nNIST curve P-224 -- Generator:\n     x = 0x");
-    BN_print(bio_out, x);
-    BIO_printf(bio_out, "\n     y = 0x");
-    BN_print(bio_out, y);
-    BIO_printf(bio_out, "\n");
+    TEST_info("NIST curve P-224 -- Generator");
+    test_output_bignum("x", x);
+    test_output_bignum("y", y);
     /* G_y value taken from the standard: */
     if (!TEST_true(BN_hex2bn(&z,         "BD376388B5F723FB4C22DFE6"
                                  "CD4375A05A07476444D5819985007E34"))
-        || !TEST_int_eq(0, BN_cmp(y, z))
+        || !TEST_BN_eq(y, z)
         || !TEST_true(BN_add(yplusone, y, BN_value_one()))
     /*
      * When (x, y) is on the curve, (x, y + 1) is, as it happens, not,
@@ -457,15 +415,13 @@ static int prime_field_tests(void)
         || !TEST_true(EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)))
         goto err;
 
-    BIO_printf(bio_out, "\nNIST curve P-256 -- Generator:\n     x = 0x");
-    BN_print(bio_out, x);
-    BIO_printf(bio_out, "\n     y = 0x");
-    BN_print(bio_out, y);
-    BIO_printf(bio_out, "\n");
+    TEST_info("NIST curve P-256 -- Generator");
+    test_output_bignum("x", x);
+    test_output_bignum("y", y);
     /* G_y value taken from the standard: */
     if (!TEST_true(BN_hex2bn(&z, "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"
                                  "2BCE33576B315ECECBB6406837BF51F5"))
-        || !TEST_int_eq(0, BN_cmp(y, z))
+        || !TEST_BN_eq(y, z)
         || !TEST_true(BN_add(yplusone, y, BN_value_one()))
     /*
      * When (x, y) is on the curve, (x, y + 1) is, as it happens, not,
@@ -505,16 +461,14 @@ static int prime_field_tests(void)
         || !TEST_true(EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)))
         goto err;
 
-    BIO_printf(bio_out, "\nNIST curve P-384 -- Generator:\n     x = 0x");
-    BN_print(bio_out, x);
-    BIO_printf(bio_out, "\n     y = 0x");
-    BN_print(bio_out, y);
-    BIO_printf(bio_out, "\n");
+    TEST_info("NIST curve P-384 -- Generator");
+    test_output_bignum("x", x);
+    test_output_bignum("y", y);
     /* G_y value taken from the standard: */
     if (!TEST_true(BN_hex2bn(&z, "3617DE4A96262C6F5D9E98BF9292DC29"
                                  "F8F41DBD289A147CE9DA3113B5F0B8C0"
                                  "0A60B1CE1D7E819D7A431D7C90EA0E5F"))
-        || !TEST_int_eq(0, BN_cmp(y, z))
+        || !TEST_BN_eq(y, z)
         || !TEST_true(BN_add(yplusone, y, BN_value_one()))
     /*
      * When (x, y) is on the curve, (x, y + 1) is, as it happens, not,
@@ -562,18 +516,16 @@ static int prime_field_tests(void)
         || !TEST_true(EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)))
         goto err;
 
-    BIO_printf(bio_out, "\nNIST curve P-521 -- Generator:\n     x = 0x");
-    BN_print(bio_out, x);
-    BIO_printf(bio_out, "\n     y = 0x");
-    BN_print(bio_out, y);
-    BIO_printf(bio_out, "\n");
+    TEST_info("NIST curve P-521 -- Generator");
+    test_output_bignum("x", x);
+    test_output_bignum("y", y);
     /* G_y value taken from the standard: */
     if (!TEST_true(BN_hex2bn(&z,                              "118"
                                  "39296A789A3BC0045C8A5FB42C7D1BD9"
                                  "98F54449579B446817AFBD17273E662C"
                                  "97EE72995EF42640C550B9013FAD0761"
                                  "353C7086A272C24088BE94769FD16650"))
-        || !TEST_int_eq(0, BN_cmp(y, z))
+        || !TEST_BN_eq(y, z)
         || !TEST_true(BN_add(yplusone, y, BN_value_one()))
     /*
      * When (x, y) is on the curve, (x, y + 1) is, as it happens, not,
@@ -607,20 +559,20 @@ static int prime_field_tests(void)
 
     if (!TEST_true(EC_GROUP_get_order(group, z, ctx))
         || !TEST_true(BN_add(y, z, BN_value_one()))
-        || !TEST_false(BN_is_odd(y))
+        || !TEST_BN_even(y)
         || !TEST_true(BN_rshift1(y, y)))
         goto err;
     scalars[0] = y;         /* (group order + 1)/2, so y*Q + y*Q = Q */
     scalars[1] = y;
 
-    BIO_printf(bio_out, "combined multiplication ...");
+    TEST_note("combined multiplication ...");
 
     /* z is still the group order */
     if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))
         || !TEST_true(EC_POINTs_mul(group, R, z, 2, points, scalars, ctx))
         || !TEST_int_eq(0, EC_POINT_cmp(group, P, R, ctx))
         || !TEST_int_eq(0, EC_POINT_cmp(group, R, Q, ctx))
-        || !TEST_true(BN_pseudo_rand(y, BN_num_bits(y), 0, 0))
+        || !TEST_true(BN_rand(y, BN_num_bits(y), 0, 0))
         || !TEST_true(BN_add(z, z, y)))
         goto err;
     BN_set_negative(z, 1);
@@ -629,7 +581,7 @@ static int prime_field_tests(void)
 
     if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))
         || !TEST_true(EC_POINT_is_at_infinity(group, P))
-        || !TEST_true(BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0))
+        || !TEST_true(BN_rand(x, BN_num_bits(y) - 1, 0, 0))
         || !TEST_true(BN_add(z, x, y)))
         goto err;
     BN_set_negative(z, 1);
@@ -646,7 +598,7 @@ static int prime_field_tests(void)
         || !TEST_true(EC_POINT_is_at_infinity(group, P)))
         goto err;
 
-    BIO_printf(bio_out, " ok\n\n");
+    TEST_note(" ok\n");
 
 
     r = 1;
@@ -898,14 +850,12 @@ static int char2_curve_test(int n)
         || !TEST_true(EC_POINT_get_affine_coordinates_GF2m(group, P, x, y,
                                                            ctx)))
         goto err;
-    BIO_printf(bio_out, "\n%s -- Generator:\n     x = 0x", test->name);
-    BN_print(bio_out, x);
-    BIO_printf(bio_out, "\n     y = 0x");
-    BN_print(bio_out, y);
-    BIO_printf(bio_out, "\n");
+    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_int_eq(0, BN_cmp(y, z)))
+        || !TEST_BN_eq(y, z))
         goto err;
 # else
     /*
@@ -920,11 +870,9 @@ static int char2_curve_test(int n)
         || !TEST_true(BN_hex2bn(&cof, test->cof))
         || !TEST_true(EC_GROUP_set_generator(group, P, z, cof)))
         goto err;
-    BIO_printf(bio_out, "\n%s -- Generator:\n     x = 0x", test->name); \
-    BN_print(bio_out, x); \
-    BIO_printf(bio_out, "\n     y = 0x"); \
-    BN_print(bio_out, y); \
-    BIO_printf(bio_out, "\n");
+    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)
@@ -953,13 +901,13 @@ static int char2_curve_test(int n)
         points[2] = Q;
 
         if (!TEST_true(BN_add(y, z, BN_value_one()))
-            || !TEST_false(BN_is_odd(y))
+            || !TEST_BN_even(y)
             || !TEST_true(BN_rshift1(y, y)))
             goto err;
         scalars[0] = y;         /* (group order + 1)/2, so y*Q + y*Q = Q */
         scalars[1] = y;
 
-        BIO_printf(bio_out, "combined multiplication ...");
+        TEST_note("combined multiplication ...");
 
         /* z is still the group order */
         if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))
@@ -968,7 +916,7 @@ static int char2_curve_test(int n)
             || !TEST_int_eq(0, EC_POINT_cmp(group, R, Q, ctx)))
             goto err;
 
-        if (!TEST_true(BN_pseudo_rand(y, BN_num_bits(y), 0, 0))
+        if (!TEST_true(BN_rand(y, BN_num_bits(y), 0, 0))
             || !TEST_true(BN_add(z, z, y)))
             goto err;
         BN_set_negative(z, 1);
@@ -979,7 +927,7 @@ static int char2_curve_test(int n)
             || !TEST_true(EC_POINT_is_at_infinity(group, P)))
             goto err;
 
-        if (!TEST_true(BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0))
+        if (!TEST_true(BN_rand(x, BN_num_bits(y) - 1, 0, 0))
             || !TEST_true(BN_add(z, x, y)))
             goto err;
         BN_set_negative(z, 1);
@@ -1019,7 +967,7 @@ static int char2_field_tests(void)
     EC_POINT *P = NULL, *Q = NULL, *R = NULL;
     BIGNUM *x = NULL, *y = NULL, *z = NULL, *cof = NULL, *yplusone = NULL;
     unsigned char buf[100];
-    size_t i, len;
+    size_t len;
     int k, r = 0;
 
     if (!TEST_ptr(ctx = BN_CTX_new())
@@ -1047,15 +995,11 @@ static int char2_field_tests(void)
     if (!TEST_true(EC_GROUP_get_curve_GF2m(group, p, a, b, ctx)))
         goto err;
 
-    BIO_printf(bio_out,
-            "Curve defined by Weierstrass equation\n"
-            "     y^2 + x*y = x^3 + a*x^2 + b  (mod 0x");
-    BN_print(bio_out, p);
-    BIO_printf(bio_out, ")\n     a = 0x");
-    BN_print(bio_out, a);
-    BIO_printf(bio_out, "\n     b = 0x");
-    BN_print(bio_out, b);
-    BIO_printf(bio_out, "\n(0x... means binary polynomial)\n");
+    TEST_info("Curve defined by Weierstrass equation");
+    TEST_note("     y^2 + x*y = x^3 + a*x^2 + b (mod p)");
+    test_output_bignum("a", a);
+    test_output_bignum("b", b);
+    test_output_bignum("p", p);
 
      if (!TEST_ptr(P = EC_POINT_new(group))
         || !TEST_ptr(Q = EC_POINT_new(group))
@@ -1091,32 +1035,27 @@ static int char2_field_tests(void)
                                                             ctx)))
             goto err;
 #  endif
-        BIO_printf(bio_err, "Point is not on curve: x = 0x");
-        BN_print_fp(stderr, x);
-        BIO_printf(bio_err, ", y = 0x");
-        BN_print_fp(stderr, y);
-        BIO_printf(bio_err, "\n");
+        TEST_info("Point is not on curve");
+        test_output_bignum("x", x);
+        test_output_bignum("y", y);
         goto err;
     }
 
-    BIO_printf(bio_out, "A cyclic subgroup:\n");
+    TEST_note("A cyclic subgroup:");
     k = 100;
     do {
         if (!TEST_int_ne(k--, 0))
             goto err;
 
         if (EC_POINT_is_at_infinity(group, P))
-            BIO_printf(bio_out, "     point at infinity\n");
+            TEST_note("     point at infinity");
         else {
             if (!TEST_true(EC_POINT_get_affine_coordinates_GF2m(group, P, x, y,
                                                                 ctx)))
                 goto err;
 
-            BIO_printf(bio_out, "     x = 0x");
-            BN_print(bio_out, x);
-            BIO_printf(bio_out, ", y = 0x");
-            BN_print(bio_out, y);
-            BIO_printf(bio_out, "\n");
+            test_output_bignum("x", x);
+            test_output_bignum("y", y);
         }
 
         if (!TEST_true(EC_POINT_copy(R, P))
@@ -1132,50 +1071,42 @@ static int char2_field_tests(void)
 /* Change test based on whether binary point compression is enabled or not. */
 #  ifdef OPENSSL_EC_BIN_PT_COMP
     len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED,
-                             buf, sizeof buf, ctx);
+                             buf, sizeof(buf), ctx);
     if (!TEST_size_t_ne(len, 0)
         || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))
         || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))
         goto err;
-    BIO_printf(bio_out, "Generator as octet string, compressed form:\n     ");
-    for (i = 0; i < len; i++)
-        BIO_printf(bio_out, "%02X", buf[i]);
+    test_output_memory("Generator as octet string, compressed form:",
+                       buf, len);
 #  endif
 
     len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED,
-                             buf, sizeof buf, ctx);
+                             buf, sizeof(buf), ctx);
     if (!TEST_size_t_ne(len, 0)
         || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))
         || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))
         goto err;
-    BIO_printf(bio_out, "\nGenerator as octet string, uncompressed form:\n"
-                        "     ");
-    for (i = 0; i < len; i++)
-        BIO_printf(bio_out, "%02X", buf[i]);
+    test_output_memory("Generator as octet string, uncompressed form:",
+                       buf, len);
 
 /* Change test based on whether binary point compression is enabled or not. */
 #  ifdef OPENSSL_EC_BIN_PT_COMP
     len =
-        EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf,
+        EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof(buf),
                            ctx);
     if (!TEST_size_t_ne(len, 0)
         || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))
         || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))
         goto err;
-    BIO_printf(bio_out, "\nGenerator as octet string, hybrid form:\n     ");
-    for (i = 0; i < len; i++)
-        BIO_printf(bio_out, "%02X", buf[i]);
+    test_output_memory("Generator as octet string, hybrid form:",
+                       buf, len);
 #  endif
-    BIO_printf(bio_out, "\n");
 
     if (!TEST_true(EC_POINT_invert(group, P, ctx))
         || !TEST_int_eq(0, EC_POINT_cmp(group, P, R, ctx)))
         goto err;
 
-
-#if 0
-#endif
-    BIO_printf(bio_out, "\n\n");
+    TEST_note("\n");
 
     r = 1;
 err:
@@ -1221,12 +1152,6 @@ static int internal_curve_test_method(int n)
     int r, nid = curves[n].nid;
     EC_GROUP *group;
 
-    /*
-     * Skip for X25519 because low level operations such as EC_POINT_mul()
-     * are not supported for this curve
-     */
-    if (nid == NID_X25519)
-        return 1;
     if (!TEST_ptr(group = EC_GROUP_new_by_curve_name(nid))) {
         TEST_info("Curve %s failed\n", OBJ_nid2sn(nid));
         return 0;
@@ -1352,8 +1277,8 @@ static int nistp_single_test(int idx)
     EC_POINT *G = NULL, *P = NULL, *Q = NULL, *Q_CHECK = NULL;
     int r = 0;
 
-    BIO_printf(bio_out, "\nNIST curve P-%d (optimised implementation):\n",
-            test->degree);
+    TEST_note("NIST curve P-%d (optimised implementation):",
+              test->degree);
     if (!TEST_ptr(ctx = BN_CTX_new())
         || !TEST_ptr(p = BN_new())
         || !TEST_ptr(a = BN_new())
@@ -1394,7 +1319,7 @@ static int nistp_single_test(int idx)
         || !TEST_int_eq(EC_GROUP_get_degree(NISTP), test->degree))
         goto err;
 
-    BIO_printf(bio_out, "NIST test vectors ... ");
+    TEST_note("NIST test vectors ... ");
     if (!TEST_true(BN_hex2bn(&n, test->d)))
         goto err;
     /* fixed point multiplication */
@@ -1489,22 +1414,15 @@ static int parameter_test(void)
     ECPARAMETERS_free(ecparameters);
     return r;
 }
-
-static const char rnd_seed[] =
-    "string to make the random number generator think it has entropy";
 #endif
 
-int test_main(int argc, char *argv[])
+int setup_tests(void)
 {
-    int result = EXIT_SUCCESS;
 #ifndef OPENSSL_NO_EC
-
     crv_len = EC_get_builtin_curves(NULL, 0);
     if (!TEST_ptr(curves = OPENSSL_malloc(sizeof(*curves) * crv_len))
         || !TEST_true(EC_get_builtin_curves(curves, crv_len)))
-        return EXIT_FAILURE;
-
-    RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */
+        return 0;
 
     ADD_TEST(parameter_test);
     ADD_TEST(prime_field_tests);
@@ -1517,9 +1435,13 @@ int test_main(int argc, char *argv[])
 # endif
     ADD_ALL_TESTS(internal_curve_test, crv_len);
     ADD_ALL_TESTS(internal_curve_test_method, crv_len);
+#endif
+    return 1;
+}
 
-    result = run_tests(argv[0]);
+void cleanup_tests(void)
+{
+#ifndef OPENSSL_NO_EC
     OPENSSL_free(curves);
 #endif
-    return result;
 }