ds.ov2.test
Class Exponent_perf_host

java.lang.Object
  extended by ds.ov2.test.Exponent_perf_host

public class Exponent_perf_host
extends Object

Correctness check and performance measurement for all multi-exponent variants in Vector.

Execution Environment:
host
Author:
Hendrik Tews
Version:
$Revision: 1.37 $
Last Commit:
$Date: 2010-02-16 11:06:06 $ by $Author: tews $

Nested Class Summary
private  class Exponent_perf_host.Exp_call_result
          Result record of the Vector_exp protocol.
static class Exponent_perf_host.Vector_exponent_variant
          Enumeration for the different multi-power implementations.
 
Field Summary
private  CardChannel card_channel
          Channel to the applet.
private  Misc_protocols_host misc_host
          Misc protocols instance for the resize protocol.
private  PrintWriter out
          Debug and progress channel.
private  Exponent_perf_stubs stubs
          Stubs for the Vector_exp protocol.
private  Test_protocols test_protocols
          Protocol array instance to set the result sizes after changing the vector length.
 
Constructor Summary
Exponent_perf_host(Test_protocols test_protocols, CardChannel card_channel)
          Constructor.
 
Method Summary
 Exponent_perf_host.Exp_call_result card_vector_exp(Host_vector base, Host_vector exponent, Host_modulus modulus, int base_factor_size, Host_vector base_factors, BigInteger one_or_correction, Exponent_perf_host.Vector_exponent_variant variant, boolean keep_modulus)
          Run the complete vector exponent protocol.
private  void change_vector_length(int new_length, int new_factors_length)
          Run the Vector_length protocol to resize base, exponents and base factors vectors.
 void run_vector_exp_check(Exponent_perf_host.Vector_exponent_variant variant)
          Exception wrapper for vector_exp_check.
 void run_vector_exp_perf(Exponent_perf_host.Vector_exponent_variant variant)
          Exception wrapper for vector_exp_measure.
 void vector_exp_check(Exponent_perf_host.Vector_exponent_variant variant)
          Check State.rounds rounds the multi-power computation on the card.
 void vector_exp_measure_size(BigInteger mod, Random rand, int short_bit_size, int short_byte_size, int effective_byte_size, int long_byte_size, int pre_computed_factors, Exponent_perf_host.Vector_exponent_variant variant, boolean keep_modulus)
          Measure one round of multi-power and print the timings in gnuplot friendly way.
 void vector_exp_measure(Exponent_perf_host.Vector_exponent_variant variant)
          Measure multi-power with increasing number sizes.
 Exponent_perf_host.Exp_call_result vector_exp_once(BigInteger mod, Random rand, int short_bit_size, int short_byte_size, int effective_byte_size, int long_byte_size, int pre_computed_factors, Exponent_perf_host.Vector_exponent_variant variant, boolean keep_modulus)
          Generate input data, run the vector exponent protocol once and check the result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

test_protocols

private Test_protocols test_protocols
Protocol array instance to set the result sizes after changing the vector length.


out

private PrintWriter out
Debug and progress channel.


misc_host

private Misc_protocols_host misc_host
Misc protocols instance for the resize protocol.


stubs

private Exponent_perf_stubs stubs
Stubs for the Vector_exp protocol.


card_channel

private CardChannel card_channel
Channel to the applet.

Constructor Detail

Exponent_perf_host

public Exponent_perf_host(Test_protocols test_protocols,
                          CardChannel card_channel)
Constructor. Initialize all the fields.

Parameters:
test_protocols - protocol array instance
card_channel - channel to the applet
Method Detail

change_vector_length

private void change_vector_length(int new_length,
                                  int new_factors_length)
                           throws CardException
Run the Vector_length protocol to resize base, exponents and base factors vectors.

Parameters:
new_length - new length for bases and exponents
new_factors_length - number of factors the factor array gets, the real array size will then be 2^new_factors_length -1
Throws:
CardException - for communication errors

card_vector_exp

public Exponent_perf_host.Exp_call_result card_vector_exp(Host_vector base,
                                                          Host_vector exponent,
                                                          Host_modulus modulus,
                                                          int base_factor_size,
                                                          Host_vector base_factors,
                                                          BigInteger one_or_correction,
                                                          Exponent_perf_host.Vector_exponent_variant variant,
                                                          boolean keep_modulus)
                                                   throws CardException
Run the complete vector exponent protocol. Computes base[0]^exponent[0] * base[1]^exponent[1] * ... mod modulus on the card and returns the result and the performance timings. Depending on the implementation selected with variant, different extra data is necessary.

To reduce card communication errors the method performs a garbage collection and sleeps some time before each step. The sleep time is hardwired in the method (currently 400 milliseconds).

Parameters:
base - base vector, Montgomerized for Exponent_perf_host.Vector_exponent_variant.PURE_JAVA, normal otherwise
exponent - exponent vector, always normal
modulus - modulus
base_factor_size - only necessary for the Exponent_perf_host.Vector_exponent_variant.PURE_JAVA variant: number of factors whose products are precomputed in base_factors
base_factors - array of all possible products of the first base_factor_size bases, see Vector.exponent_mod; Only needed for Exponent_perf_host.Vector_exponent_variant.PURE_JAVA, must otherwise contain at least one (arbitrary) element, because the protocol layer does not support empty objects
one_or_correction - for Exponent_perf_host.Vector_exponent_variant.PURE_JAVA montgomerized 1, for Exponent_perf_host.Vector_exponent_variant.MONT_RSA Montgomery correction factor, not used for Exponent_perf_host.Vector_exponent_variant.SQUARED_RSA
variant - chosen implementation variant
keep_modulus - whether the modulus is the same as in the last test and should thus not be installed
Returns:
record with result and duration in nanoseconds
Throws:
CardException - on communiction errors

vector_exp_once

public Exponent_perf_host.Exp_call_result vector_exp_once(BigInteger mod,
                                                          Random rand,
                                                          int short_bit_size,
                                                          int short_byte_size,
                                                          int effective_byte_size,
                                                          int long_byte_size,
                                                          int pre_computed_factors,
                                                          Exponent_perf_host.Vector_exponent_variant variant,
                                                          boolean keep_modulus)
                                                   throws CardException
Generate input data, run the vector exponent protocol once and check the result. Terminate the program if the card result is wrong. The multi-power method to be used on the card is determined by the argument variant. For the RSA variants, where changing the modulus costs some time, the same modulus (passed as mod argument) can be used for a number of successive test.

Parameters:
mod - modulus if non-null, if null generate modulus randomly
rand - randomness source
short_bit_size - exponent size in bits
short_byte_size - exponent size in bytes
effective_byte_size - base size in bytes, excluding the Montgomery digits for those variants that use them
long_byte_size - base size in bytes, including the Montgomery digits for those variants that use them
pre_computed_factors - number of bases for which their products are precomputed on the host side; must be at least 1, even for the RSA variants that do not use precomputed products
variant - the muli-power implementation to use on the card
Returns:
combined result record
Throws:
CardException - on communication errors

vector_exp_check

public void vector_exp_check(Exponent_perf_host.Vector_exponent_variant variant)
                      throws CardException
Check State.rounds rounds the multi-power computation on the card. On any error the program is terminated and the involved numbers are printed.

Parameters:
variant - multi-power implementation to use on the card
Throws:
CardException - on communication errors

vector_exp_measure_size

public void vector_exp_measure_size(BigInteger mod,
                                    Random rand,
                                    int short_bit_size,
                                    int short_byte_size,
                                    int effective_byte_size,
                                    int long_byte_size,
                                    int pre_computed_factors,
                                    Exponent_perf_host.Vector_exponent_variant variant,
                                    boolean keep_modulus)
                             throws CardException
Measure one round of multi-power and print the timings in gnuplot friendly way. Input-data generation and the actual test is done by vector_exp_once. Terminate the program if the card result is wrong. The multi-power method to be used on the card is determined by the argument variant. For the RSA variants, where changing the modulus costs some time, the same modulus (passed as mod argument) can be used for a number of successive test.

Parameters:
mod - modulus if non-null, if null generate modulus randomly
rand - randomness source
short_bit_size - exponent size in bits
short_byte_size - exponent size in bytes
effective_byte_size - base size in bytes, excluding the Montgomery digits for those variants that use them
long_byte_size - base size in bytes, including the Montgomery digits for those variants that use them
pre_computed_factors - number of bases for which their products are precomputed on the host side; must be at least 1, even for the RSA variants that do not use precomputed products
variant - the muli-power implementation to use on the card
keep_modulus - whether the modulus is the same as in the last test and should thus not be installed
Throws:
CardException - on communication errors

vector_exp_measure

public void vector_exp_measure(Exponent_perf_host.Vector_exponent_variant variant)
                        throws CardException
Measure multi-power with increasing number sizes. Perform State.rounds measurements for each size between State.start_size and State.long_bignat_max_size. If State.start_size has not been set, a very small start size is used. Each size is measured and printed with vector_exp_measure_size. The program is terminated if the card computes anything wrong. If State.keep_modulus is set, the same modulus is used for all measurements of one size.

Parameters:
variant - the multi-power variant to measure
Throws:
CardException - on communication errors

run_vector_exp_check

public void run_vector_exp_check(Exponent_perf_host.Vector_exponent_variant variant)
Exception wrapper for vector_exp_check. Checks the given multi-power method and prints traces for all escaping exceptions. If one check fails the program is immediately terminated.

Parameters:
variant - the multi-power variant to check

run_vector_exp_perf

public void run_vector_exp_perf(Exponent_perf_host.Vector_exponent_variant variant)
Exception wrapper for vector_exp_measure. Measures the given multi-power implementation over a range of sizes and prints traces for escaping exceptions. If one computation on the card yields a wrong result, the program is terminated.

Parameters:
variant - the multi-power variant to measure