|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectds.ov2.bignat.Testbignat
public class Testbignat
Cardless test frame for the Bignat library. Tests various
functionality of Bignat
, Vector
and Modulus
and of some host data types on a conventional Java virtual machine,
that is, not on a Java Card.
The test frame and parts of the tested sources require
preprocessing with cpp, the C preprocessor. So compile with make
and run the test frame with the script run-testbignat
in the directory of the original sources (src/bignat
).
The single tests are enabled with command line options. To see what
test are available look at the options list produced by -h
or -help
. Apart from the options that enable specific tests
there are also general options for setting the Bignat size or the
number of rounds the tests are performed. Not all tests are
sensible to all options, using test data files is for instance only
supported in the vector exponent test (option -vec-exp
).
The tests usually run with random data. In case an error is
detected the test frame prints the relevant numbers for the test
that failed and exits immediately. To repeat a test with some given
numbers, numbers can be passed in via the option -i
or
-hex
. The latter accepts the hex output produced by the
test frame itself, that is, dots in the hex number are filtered
out.
By using different defines for the cpp preprocessing different versions of the code can be selected (and tested). The following defines can be used.
The defines should be put into the CPPFLAGS
makefile
variable with a -D
switch prepended. For instance
CPPFLAGS:=-DOPT_SPECIAL_SQUAREin src/ConfigMakefile or src/bignat/LocalMakefile. To set them on the command line use
make 'CPPFLAGS=-DOPT_SPECIAL_SQUARE'
For a number of general topics see also the package description.
Field Summary | |
---|---|
private static short |
bignat_size
Bignat size of the -size option. |
private static boolean |
bignat_size_set
Records whether bignat_size has been changed via the
-size option. |
private static BigInteger_inputs |
fix_inputs
User provided inputs. |
static String |
long_application_name
Long name for diagnostics printing. |
private static int |
max_bits
Bit size parameter for random BigInteger creation. |
private static short |
mont_bignat_size
Montgomery size. |
static Option[] |
options
Declaration of all options that this test frame recognizes. |
private static Reference<String> |
read_from_file
Value of the -read option. |
private static Reference<Integer> |
rounds
Value of the -rounds option. |
private static Reference<Boolean> |
run_add
Remember the -add option. |
private static Reference<Boolean> |
run_convenience_exponent
Remember the -conv-exp option. |
private static Reference<Boolean> |
run_convenience_vector_exponent
Remember the -conv-vec-exp option. |
private static Reference<Boolean> |
run_double_mult
Remember the -double-mult option. |
private static Reference<Boolean> |
run_exponent
Remember the -exp option. |
private static Reference<Boolean> |
run_mont_mult
Remember the -mont-mult option. |
private static Reference<Boolean> |
run_remainder_divide
Remember the -div option. |
private static Reference<Boolean> |
run_slow_mult
Remember the -mult option. |
private static Reference<Boolean> |
run_square_mult
Remember the -mult-square option. |
private static Reference<Boolean> |
run_square_mult_4
Remember the -mult-square-4 option. |
private static Reference<Boolean> |
run_times_minus
Remember the -times-minus option. |
private static Reference<Boolean> |
run_vector_exponent
Remember the -vec-exp option. |
static String |
short_application_name
Short name for diagnostics printing. |
private static Reference<Integer> |
vector_exponent_length
Value of the -vec-exp-size option. |
private static Reference<Integer> |
vector_exponent_variable_bases
Value of the -vec-exp-var option. |
private static Reference<Integer> |
verbosity
Verbosity. |
private static Reference<String> |
write_to_file
Value of the -write option. |
Constructor Summary | |
---|---|
protected |
Testbignat()
Static class, object creation disabled. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String short_application_name
public static final String long_application_name
private static Reference<Boolean> run_add
-add
option.
private static Reference<Boolean> run_times_minus
-times-minus
option.
private static Reference<Boolean> run_remainder_divide
-div
option.
private static Reference<Boolean> run_slow_mult
-mult
option.
private static Reference<Boolean> run_double_mult
-double-mult
option.
private static Reference<Boolean> run_mont_mult
-mont-mult
option.
private static Reference<Boolean> run_exponent
-exp
option.
private static Reference<Boolean> run_vector_exponent
-vec-exp
option.
private static Reference<Boolean> run_convenience_exponent
-conv-exp
option.
private static Reference<Boolean> run_convenience_vector_exponent
-conv-vec-exp
option.
private static Reference<Boolean> run_square_mult
-mult-square
option.
private static Reference<Boolean> run_square_mult_4
-mult-square-4
option.
private static boolean bignat_size_set
bignat_size
has been changed via the
-size
option.
private static short bignat_size
-size
option. Defaults to 12.
private static short mont_bignat_size
bignat_size
and
therefore on the -size
option. Two digits less than
#bignat_size
. The number of bytes dependes on Bignat.size_multiplier
.
private static Reference<Integer> vector_exponent_length
-vec-exp-size
option. Defaults to 5.
private static Reference<Integer> vector_exponent_variable_bases
-vec-exp-var
option. Controls for how much
bases precomputed base factors are used in the vector exponent
test (testing Vector.exponent_mod
).
Defaults to -1. A value of -1
means to use randomly
many precomputed factors.
private static int max_bits
bignat_size
.
private static Reference<Integer> rounds
-rounds
option. Number of rounds every
test is run. Defaults to 5000.
private static Reference<String> write_to_file
-write
option. File to write test data to.
Default value null means to not write the test data.
private static Reference<String> read_from_file
-read
option. File to read test data from.
Default value null means to not read any data from file.
private static Reference<Integer> verbosity
-v
, to 5 by -d
, to 10 by
-dd
and to 15 by -ddd
.
private static BigInteger_inputs fix_inputs
public static Option[] options
Constructor Detail |
---|
protected Testbignat()
Method Detail |
---|
public static void main(String[] args) throws FileNotFoundException, IOException
args
- option array
FileNotFoundException
- in case the test data file
specified via -read
does not exist
IOException
- for errors when reading or writing the test
data filesprivate static int max_bits_from_size(int size)
numBits
argument for the
BigInteger.BigInteger(int, Random)
constructor out of a
Bignat byte size. The successor is needed because the result is
used like
new BigInteger(rand.nextInt(max_bits_from_size(...)), rand)where
rand
is an instance of Random
.
size
- size in bytes
8 * size + 1
public static void print_bi_array(String intro_format, String line_start, BigInteger[] bi)
intro_format
is a format string for the
heading, for instance "array foo with %d elements\n". It must
contain at most one integer conversion and should be terminated
with a newline. An empty intro format effectively discards the
heading. Argument line_start
is printed at the
beginning of each line, for instance "foo".
intro_format
- Format string for the heading with at most
one integer conversion (for the number of elements in bi
)line_start
- array name string printed for each array elementbi
- the BigIntegers to be printedpublic static boolean test_add_once(Random rand)
Bignat.add
once. Takes the summands
from the fixed inputs, if available. Otherwise generates random
summands of a random size below the configured Bignat size.
Contains no protection against generating an overflow in Bignat.add
, which would be reported as a failure.
rand
- randomness source
public static void test_add(Random rand)
Bignat.add
rounds
times. Exit
if a failure is detected. If fixed inputs are available, they
will be used.
rand
- randomness sourcepublic static void test_times_minus(Random rand)
Bignat.times_minus
once. Test
arguments are generated randomly in a fashion to simulate the
use of times_minus
in division.
Underflows are avoided. No fixed inputs are used.
rand
- randomness sourcepublic static boolean test_remainder_divide_once(Random rand)
Bignat.remainder_divide
once. If fixed inputs are available the divident and divisor
are taken in this order from the fixed inputs. Otherwise they
are generated randomly in such a way that with a probability of
5 percent the divident is bigger than the divisor.
rand
- randomness source
public static void test_remainder_divide(Random rand)
Bignat.remainder_divide
rounds
times. Exists if a test fails. If fixed inputs
are available, they will be used.
rand
- randomness sourcepublic static boolean test_mult_mod_once(Random rand)
Bignat.mult_mod
once. If fixed
inputs are available the factors and the modulus are taken from
the fixed inputs in this order. Otherwise they are generated
randomly with the side condition that the modulus is non-zero.
rand
- randomness source
public static void test_mult_mod(Random rand)
Bignat.mult_mod
rounds
times. Exists on the first error. If fixed inputs are
available, they will be used.
rand
- randomness sourcepublic static boolean test_double_mult_once(Random rand)
Bignat.mult
once. If fixed inputs are
available the factors are taken from there. Otherwise they are
generated randomly.
rand
- randomness source
public static void test_double_mult(Random rand)
Bignat.mult
rounds
times.
Exists on the first error. If fixed inputs are available they
will be used.
rand
- randomness sourcepublic static boolean test_montgomery_mult_once(Random rand)
Bignat.montgomery_mult
once. If fixed inputs are available the factors and the modulus
are taken in this order from there. Otherwise they are
generated randomly such that the modulus is odd.
rand
- randomness source
public static void test_montgomery_mult(Random rand)
Bignat.montgomery_mult
rounds
times. Exists on the first error. If fixed
inputs are available, they will be used.
rand
- randomness sourcepublic static long[] test_exponent_once(Random rand, BufferedReader data_in, PrintWriter data_out) throws IOException
Bignat.exponent_mod
once.
Honours the -read
and -write
options. If 3
fixed inputs are available the base, the exponent and the
modulus are taken from there. Otherwise, if -read
was
given, the data is taken from the next 3 lines of the input
file. Otherwise they are generated randomly such that the base
and the modulus have mont_bignat_size
significant
bytes, and the exponent has 10 percent of this size. If -write
was given the data is written to the output file.
The time needed to compute the exponent with both the Bignat
library and with BigInteger
is measured and returned.
For the Bignat library only the time for Bignat.exponent_mod
is measured without
the necessary preparations.
Exists if the test fails.
rand
- randomness sourcedata_in
- input data file or null for no inputdata_out
- output data file or null for no output
throws IOException if reading from data_in
fails
IOException
public static void test_exponent(Random rand, BufferedReader data_in, PrintWriter data_out) throws FileNotFoundException, IOException
Bignat.exponent_mod
twice
rounds
times. The first time for warming the cache and
JIT compilation, the second time for real measurements. Exists
immediately in case of an error.
If fixed inputs are available, they will be used.
Otherwise, if -read
was given, the test data is taken
from that file. After the first rounds
test the file
is reopened to do the real measurements with exactly the same
data.
Without -read
the test data is generated randomly. If
-write
was given the data is written to that file
during the first rounds
tests and read from there
afterwards.
Exists on the first error.
rand
- randomness sourcedata_in
- input data file or null for no input filedata_out
- output data file or null for no output
FileNotFoundException
- if reopening read_from_file
fails
throws IOException if reading from data_in
fails XXXX
IOException
public static long[] test_vector_exponent_once(Random rand, BufferedReader data_in, PrintWriter data_out) throws IOException
Vector.exponent_mod
once.
Honours the -read
and -write
options. If enough
fixed inputs are present vector_exponent_length
bases,
the same number of exponents and the modulus are taken from
there in this order. Otherwise, if -read
was given, the
data is taken from the next 2 *
vector_exponent_length
+ 1
lines of the input file.
Otherwise the data is generated randomly such that bases and
modulus have mont_bignat_size
significant bytes and
the exponents are 10 percent of this size. If -write
was
given the data is written to the output file.
The time needed to compute the multi-exponent with both the
Bignat library and with BigInteger
is measured and
returned. For the Bignat library only the time for Vector.exponent_mod
is measured without
the necessary preparations.
Exits if an error is detected.
rand
- randomness sourcedata_in
- input data file or null for no inputdata_out
- output data file or null for no output
data_in
fails
IOException
public static void test_vector_exponent(Random rand, BufferedReader data_in, PrintWriter data_out) throws FileNotFoundException, IOException
Vector.exponent_mod
twice
rounds
times. The first time for warming the cache and
JIT compilation, the second time for real measurements. Exists
immediately in case of an error.
If sufficient fixed inputs are available, they will be used.
Every round discards the first 2 *
vector_exponent_length
+ 1
fixed inputs. Otherwise, if
-read
was given, the test data is taken from that file.
After the first rounds
test the file is reopened to do
the real measurements with exactly the same data.
Without -read
the test data is generated randomly. If
-write
was given the data is written to that file
during the first rounds
tests and read from there
afterwards.
Exists on the first error.
rand
- randomness sourcedata_in
- input data file or null for no input filedata_out
- output data file or null for no output
FileNotFoundException
- if reopening read_from_file
fails
IOException
- if reading from data_in
fails or
some other file error occurspublic static void test_convenience_exponent(Random rand)
Convenience.exponent_mod
rounds
times with randomly generated numbers. Exit if
a failure is detected.
rand
- randomness sourcepublic static void test_convenience_vector_exponent(Random rand)
Convenience.vector_exponent_mod
rounds
times with
randomly generated numbers. Exit if a failure is detected.
rand
- randomness sourcepublic static void test_square_mult(Random rand)
Bignat.squared_rsa_mult_2
rounds
times. Exists on the first error. If fixed
inputs are available, they will be used.
rand
- randomness sourcepublic static void test_square_mult_4(Random rand)
Bignat.squared_rsa_mult_4
rounds
times. Exists on the first error. If fixed
inputs are available, they will be used.
rand
- randomness source
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |