The unified diff between revisions [7ee04f35..] and [11a5f681..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'checks/bigint.cpp'

#
#
# patch "checks/bigint.cpp"
#  from [ca4137d2ebc424e42e04bfd28b00643167dc4b4f]
#    to [42fd0bfcf3602642e4309c39141cb3fe0a68e922]
#
============================================================
--- checks/bigint.cpp	ca4137d2ebc424e42e04bfd28b00643167dc4b4f
+++ checks/bigint.cpp	42fd0bfcf3602642e4309c39141cb3fe0a68e922
@@ -5,8 +5,9 @@
 #include <cstdlib>

 #include <botan/bigint.h>
+#include <botan/exceptn.h>
 #include <botan/numthry.h>
-#include <botan/rng.h>
+#include <botan/libstate.h>
 using namespace Botan;

 #include "common.h"
@@ -16,6 +17,7 @@ u32bit check_mul(const std::vector<std::
 u32bit check_add(const std::vector<std::string>&);
 u32bit check_sub(const std::vector<std::string>&);
 u32bit check_mul(const std::vector<std::string>&);
+u32bit check_sqr(const std::vector<std::string>&);
 u32bit check_div(const std::vector<std::string>&);
 u32bit check_mod(const std::vector<std::string>&);
 u32bit check_shr(const std::vector<std::string>&);
@@ -29,10 +31,7 @@ u32bit do_bigint_tests(const std::string
    std::ifstream test_data(filename.c_str());

    if(!test_data)
-       {
-       std::cout << "Couldn't open test file " << filename << std::endl;
-       std::exit(1);
-       }
+      throw Botan::Stream_IO_Error("Couldn't open test file " + filename);

    u32bit errors = 0, alg_count = 0;
    std::string algorithm;
@@ -42,10 +41,8 @@ u32bit do_bigint_tests(const std::string
    while(!test_data.eof())
       {
       if(test_data.bad() || test_data.fail())
-         {
-         std::cout << "File I/O error." << std::endl;
-         std::exit(1);
-         }
+         throw Botan::Stream_IO_Error("File I/O error reading from " +
+                                      filename);

       std::string line;
       std::getline(test_data, line);
@@ -91,6 +88,8 @@ u32bit do_bigint_tests(const std::string
          new_errors = check_sub(substr);
       else if(algorithm.find("Multiplication") != std::string::npos)
          new_errors = check_mul(substr);
+      else if(algorithm.find("Square") != std::string::npos)
+         new_errors = check_sqr(substr);
       else if(algorithm.find("Division") != std::string::npos)
          new_errors = check_div(substr);
       else if(algorithm.find("Modulo") != std::string::npos)
@@ -141,6 +140,7 @@ u32bit results(std::string op,

       std::cout << "a = " << std::hex << a << std::endl;
       std::cout << "b = " << std::hex << b << std::endl;
+
       std::cout << "c = " << std::hex << c << std::endl;
       std::cout << "d = " << std::hex << d << std::endl;
       std::cout << "e = " << std::hex << e << std::endl;
@@ -218,6 +218,20 @@ u32bit check_mul(const std::vector<std::
    return results("*", a, b, c, d, e);
    }

+u32bit check_sqr(const std::vector<std::string>& args)
+   {
+   BigInt a(args[0]);
+   BigInt b(args[1]);
+
+   a.grow_reg(16);
+   b.grow_reg(16);
+
+   BigInt c = square(a);
+   BigInt d = a * a;
+
+   return results("sqr", a, a, b, c, d);
+   }
+
 u32bit check_div(const std::vector<std::string>& args)
    {
    BigInt a(args[0]);
@@ -250,7 +264,7 @@ u32bit check_mod(const std::vector<std::
    /* Won't work for us, just pick one at random */
    while(b_word == 0)
       for(u32bit j = 0; j != 2*sizeof(word); j++)
-         b_word = (b_word << 4) ^ Global_RNG::random();
+         b_word = (b_word << 4) ^ global_state().random();

    b = b_word;