Move more non-bc tests down.

Change-Id: Ib661e2f3b87543a4b7a091631e9e2a66709a70e8
Reviewed-on: https://boringssl-review.googlesource.com/8530
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/bn/bn_test.cc b/crypto/bn/bn_test.cc
index 158b520..446fd27 100644
--- a/crypto/bn/bn_test.cc
+++ b/crypto/bn/bn_test.cc
@@ -107,8 +107,6 @@
 static bool test_mod_exp_mont_consttime(FILE *fp, BN_CTX *ctx);
 static bool test_exp(FILE *fp, BN_CTX *ctx);
 static bool test_mod_sqrt(FILE *fp, BN_CTX *ctx);
-static bool test_exp_mod_zero(void);
-static bool test_small_prime(FILE *fp, BN_CTX *ctx);
 static bool test_mod_exp_mont5(FILE *fp, BN_CTX *ctx);
 static bool test_sqrt(FILE *fp, BN_CTX *ctx);
 static bool TestBN2BinPadded(BN_CTX *ctx);
@@ -120,6 +118,8 @@
 static bool TestASN1();
 static bool TestNegativeZero(BN_CTX *ctx);
 static bool TestBadModulus(BN_CTX *ctx);
+static bool TestExpModZero();
+static bool TestSmallPrime(BN_CTX *ctx);
 static bool RunTest(FileTest *t, void *arg);
 
 // A wrapper around puts that takes its arguments in the same order as our *_fp
@@ -204,8 +204,7 @@
   flush_fp(bc_file.get());
 
   message(bc_file.get(), "BN_exp");
-  if (!test_exp(bc_file.get(), ctx.get()) ||
-      !test_exp_mod_zero()) {
+  if (!test_exp(bc_file.get(), ctx.get())) {
     return 1;
   }
   flush_fp(bc_file.get());
@@ -216,12 +215,6 @@
   }
   flush_fp(bc_file.get());
 
-  message(bc_file.get(), "Small prime generation");
-  if (!test_small_prime(bc_file.get(), ctx.get())) {
-    return 1;
-  }
-  flush_fp(bc_file.get());
-
   message(bc_file.get(), "BN_sqrt");
   if (!test_sqrt(bc_file.get(), ctx.get())) {
     return 1;
@@ -236,7 +229,9 @@
       !TestRand() ||
       !TestASN1() ||
       !TestNegativeZero(ctx.get()) ||
-      !TestBadModulus(ctx.get())) {
+      !TestBadModulus(ctx.get()) ||
+      !TestExpModZero() ||
+      !TestSmallPrime(ctx.get())) {
     return 1;
   }
 
@@ -885,31 +880,6 @@
   return true;
 }
 
-// test_exp_mod_zero tests that 1**0 mod 1 == 0.
-static bool test_exp_mod_zero(void) {
-  ScopedBIGNUM zero(BN_new()), a(BN_new()), r(BN_new());
-  if (!zero || !a || !r || !BN_rand(a.get(), 1024, 0, 0)) {
-    return false;
-  }
-  BN_zero(zero.get());
-
-  if (!BN_mod_exp(r.get(), a.get(), zero.get(), BN_value_one(), nullptr) ||
-      !BN_is_zero(r.get()) ||
-      !BN_mod_exp_mont(r.get(), a.get(), zero.get(), BN_value_one(), nullptr,
-                       nullptr) ||
-      !BN_is_zero(r.get()) ||
-      !BN_mod_exp_mont_consttime(r.get(), a.get(), zero.get(), BN_value_one(),
-                                 nullptr, nullptr) ||
-      !BN_is_zero(r.get()) ||
-      !BN_mod_exp_mont_word(r.get(), 42, zero.get(), BN_value_one(), nullptr,
-                            nullptr) ||
-      !BN_is_zero(r.get())) {
-    return false;
-  }
-
-  return true;
-}
-
 static bool test_mod_sqrt(FILE *fp, BN_CTX *ctx) {
   ScopedBIGNUM a(BN_new());
   ScopedBIGNUM p(BN_new());
@@ -970,23 +940,6 @@
   return true;
 }
 
-static bool test_small_prime(FILE *fp, BN_CTX *ctx) {
-  static const unsigned kBits = 10;
-
-  ScopedBIGNUM r(BN_new());
-  if (!r || !BN_generate_prime_ex(r.get(), static_cast<int>(kBits), 0, NULL,
-                                  NULL, NULL)) {
-    return false;
-  }
-  if (BN_num_bits(r.get()) != kBits) {
-    fprintf(fp, "Expected %u bit prime, got %u bit number\n", kBits,
-            BN_num_bits(r.get()));
-    return false;
-  }
-
-  return true;
-}
-
 static bool test_sqrt(FILE *fp, BN_CTX *ctx) {
   ScopedBIGNUM n(BN_new());
   ScopedBIGNUM nn(BN_new());
@@ -1623,3 +1576,45 @@
 
   return true;
 }
+
+// TestExpModZero tests that 1**0 mod 1 == 0.
+static bool TestExpModZero() {
+  ScopedBIGNUM zero(BN_new()), a(BN_new()), r(BN_new());
+  if (!zero || !a || !r || !BN_rand(a.get(), 1024, 0, 0)) {
+    return false;
+  }
+  BN_zero(zero.get());
+
+  if (!BN_mod_exp(r.get(), a.get(), zero.get(), BN_value_one(), nullptr) ||
+      !BN_is_zero(r.get()) ||
+      !BN_mod_exp_mont(r.get(), a.get(), zero.get(), BN_value_one(), nullptr,
+                       nullptr) ||
+      !BN_is_zero(r.get()) ||
+      !BN_mod_exp_mont_consttime(r.get(), a.get(), zero.get(), BN_value_one(),
+                                 nullptr, nullptr) ||
+      !BN_is_zero(r.get()) ||
+      !BN_mod_exp_mont_word(r.get(), 42, zero.get(), BN_value_one(), nullptr,
+                            nullptr) ||
+      !BN_is_zero(r.get())) {
+    return false;
+  }
+
+  return true;
+}
+
+static bool TestSmallPrime(BN_CTX *ctx) {
+  static const unsigned kBits = 10;
+
+  ScopedBIGNUM r(BN_new());
+  if (!r || !BN_generate_prime_ex(r.get(), static_cast<int>(kBits), 0, NULL,
+                                  NULL, NULL)) {
+    return false;
+  }
+  if (BN_num_bits(r.get()) != kBits) {
+    fprintf(stderr, "Expected %u bit prime, got %u bit number\n", kBits,
+            BN_num_bits(r.get()));
+    return false;
+  }
+
+  return true;
+}