ds.ov2.bignat
Class Resize

java.lang.Object
  extended by ds.ov2.bignat.Resize

public class Resize
extends Object

Centralized resizing of Bignats, Bignat arrays and RSA exponents. The whole resising functionality is meant for test frames only, see the general explanations for resizing. Although on the card all arrays are allocated just once, the three named data types have an optional interface for virtual size and length changes. The interface is optional, because it is only available when VARIABLE_SIZE_BIGNATS is defined. The length and size changes are only virtual, because the underlying arrays do not change and resizing does therefore not cost any memory. An exception is the resizing functionality of RSA_exponent. There, with every init_key operation, a new RSA key is created and probably some memory lost.

This class offers the possibility for registering objects of the three named types for performing centralized resizing operations. One problem thereby is that because of the lack of an garbage collector the java card environment does not really provide the possibility of arrays that grow in size according to demand. Therefore, and for simplicity, the internal arrays that hold the registered objects are allocated just once, with a hardwired size. If one of the arrays turns out to be too small an assertion will fail.

Objects must be registered according to their type of course. Bignats can be registered as long, as short, or as double-sized Bignats. Thereby, long, short and double-sized have no particular meaning. It is only that the resize operation resize_bignats takes three size arguments for Bignats, one for the long ones, one for the short ones, and one for the double-sized ones. The RSA exponents are neither long nor small for these purposes. They get their own cipher_len argument.

(The distinction in long and short comes from the OV-Chip 2.0 context. There bases are 1000-2000 bits long and exponents 150-200 bits. For multiplication of exponent (attribute) values also one double-sized Bignat twice as long as the exponents are needed. The RSA_exponent even requires that the ``long'' bases are longer than the ``short'' exponents.)

Their are two kinds of arrays distinguished here. The first kind are the arrays of bases and exponents, that all have the same size, around 2-15 elements. The second kind are the arrays of precomputed base factors (see Vector.exponent_mod) that grow exponentially with the length of the bases. Therefore arrays can be registered as either vectors (the first kind) or factor arrays (the second kind). The length changing operation, resize_vectors takes two length arguments and treats these two kinds of arrays separately.

Types that wrap one or several Bignats typically offer some register method, that registers all contained objects here, see for instance Bignat_array.register_long_bignats(), Bignat_array.register_short_bignats() and Modulus.register_long_bignats().

This is a static class. All fields and methods are static, object creation is disabled. The class must be initialized with init() before using it.

For a number of general topics see also the package description.

CPP Preprocessing
This class uses the following cpp defines: PACKAGE, PUBLIC, ASSERT, ASSERT_TAG(condition, tag), HOST_TESTFRAME, TESTFRAME, VARIABLE_SIZE_BIGNATS, JAVACARD_APPLET
Execution Environment:
host, card
Author:
Hendrik Tews
Version:
$Revision: 1.17 $
Last Commit:
$Date: 2009-05-23 21:03:30 $ by $Author: tews $

Field Summary
private static short double_bignat_index
          Current index in the double_bignats array.
private static Bignat[] double_bignats
          Array of registered double-sized bignats.
private static short factor_index
          Current index in the factors array.
private static Vector[] factors
          Array of registered factor arrays.
private static short long_bignat_index
          Current index in the long_bignats array.
private static Bignat[] long_bignats
          Array of registered long bignats.
private static RSA_exponent[] long_rsa
          Array of registered RSA exponents.
private static short long_rsa_index
          Current index in the long_rsa array.
private static short max_double_bignats
          Maximal number of double-sized bignats, currently 1.
private static short max_factors
          Maximal number of factor arrays, currently 1.
private static short max_long_bignats
          Maximal number of long bignats, currently 50.
private static short max_long_rsa
          Maximal number of RSA exponents, currently 2.
private static short max_short_bignats
          Maximal number of short bignats, currently 7.
private static short max_vectors
          Maximal number of vectors, currently 2.
private static short short_bignat_index
          Current index in the short_bignats array.
private static Bignat[] short_bignats
          Array of registered short bignats.
private static short vector_index
          Current index in the vectors array.
private static Vector[] vectors
          Array of registered vectors.
 
Constructor Summary
protected Resize()
          Static class, object creation disabled.
 
Method Summary
static void init()
          Initializes all the arrays to their hardwired maximal size.
static void register_double_bignat(Bignat b)
          Register the double-sized bignat b.
static void register_factor(Vector v)
          Register the factor array v.
static void register_long_bignat(Bignat b)
          Register the long bignat b.
static void register_long_rsa(RSA_exponent e)
          Register the RSA exponent e.
static void register_short_bignat(Bignat b)
          Register the short bignat b.
static void register_vector(Vector v)
          Register the vector v.
static void resize_bignats(short short_len, short long_len, short double_len, short cipher_len)
          Resize bignats and RSA exponents.
static void resize_vectors(short vector_len, short factors_len)
          Resize arrays.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

max_short_bignats

private static final short max_short_bignats
Maximal number of short bignats, currently 7.

See Also:
Constant Field Values

max_long_bignats

private static final short max_long_bignats
Maximal number of long bignats, currently 50.

See Also:
Constant Field Values

max_double_bignats

private static final short max_double_bignats
Maximal number of double-sized bignats, currently 1.

See Also:
Constant Field Values

max_vectors

private static final short max_vectors
Maximal number of vectors, currently 2.

See Also:
Constant Field Values

max_factors

private static final short max_factors
Maximal number of factor arrays, currently 1.

See Also:
Constant Field Values

max_long_rsa

private static final short max_long_rsa
Maximal number of RSA exponents, currently 2.

See Also:
Constant Field Values

short_bignats

private static Bignat[] short_bignats
Array of registered short bignats.


long_bignats

private static Bignat[] long_bignats
Array of registered long bignats.


double_bignats

private static Bignat[] double_bignats
Array of registered double-sized bignats.


vectors

private static Vector[] vectors
Array of registered vectors.


factors

private static Vector[] factors
Array of registered factor arrays.


long_rsa

private static RSA_exponent[] long_rsa
Array of registered RSA exponents. This field is only available if JAVACARD_APPLET is defined, because RSA_exponent does only exist there.


short_bignat_index

private static short short_bignat_index
Current index in the short_bignats array.


long_bignat_index

private static short long_bignat_index
Current index in the long_bignats array.


double_bignat_index

private static short double_bignat_index
Current index in the double_bignats array.


vector_index

private static short vector_index
Current index in the vectors array.


factor_index

private static short factor_index
Current index in the factors array.


long_rsa_index

private static short long_rsa_index
Current index in the long_rsa array.

Constructor Detail

Resize

protected Resize()
Static class, object creation disabled.

Method Detail

init

public static void init()
Initializes all the arrays to their hardwired maximal size. This method must be called once before the first registration.


register_short_bignat

public static void register_short_bignat(Bignat b)
Register the short bignat b.

Asserts that the arrays have been allocated and that there is still space in the array for short bignats.

Parameters:
b - bignat to register

register_long_bignat

public static void register_long_bignat(Bignat b)
Register the long bignat b.

Asserts that the arrays have been allocated and that there is still space in the array for long bignats.

Parameters:
b - bignat to register

register_double_bignat

public static void register_double_bignat(Bignat b)
Register the double-sized bignat b.

Asserts that the arrays have been allocated and that there is still space in the array for double-sized bignats.

Parameters:
b - bignat to register

register_vector

public static void register_vector(Vector v)
Register the vector v.

Asserts that the arrays have been allocated and that there is still space in the array for vectors.

Parameters:
v - vector to register

register_factor

public static void register_factor(Vector v)
Register the factor array v.

Asserts that the arrays have been allocated and that there is still space in the array for factor arrays.

Parameters:
v - vector of factors to register

register_long_rsa

public static void register_long_rsa(RSA_exponent e)
Register the RSA exponent e.

Asserts that the arrays have been allocated and that there is still space in the array for RSA exponents.

This method is only available if JAVACARD_APPLET is defined, because RSA_exponent is only available there.

Parameters:
e - RSA exponent to register

resize_bignats

public static void resize_bignats(short short_len,
                                  short long_len,
                                  short double_len,
                                  short cipher_len)
Resize bignats and RSA exponents. Resizes all registered long and short bignats and, possibly, the registered RSA exponents. On the registered bignats the method Bignat.resize is called. On the RSA exponents RSA_exponent.init_key is called.

If cipher_len is 0 the RSA exponent size change is skipped.

Parameters:
short_len - new size for the short bignats
long_len - new size for the long bignats
cipher_len - new size for the RSA exponents

resize_vectors

public static void resize_vectors(short vector_len,
                                  short factors_len)
Resize arrays. Changes the length of all registered vectors and factor arrays by calling the Vector.set_length method on them. Because the factor array will always store all possible products of some number of factors, its size will always be equal to 2^n - 1, where n is the number of factors (the -1 is there because the array does not contain the empty product, see Vector.exponent_mod). The factors_len argument gets the n rather than the real factor array size.

Parameters:
vector_len - new length for the (normal) vectors
factors_len - base 2 log of the new length for the factor arrays, i.e., if the factor array stores the products of 4 factors, its length would be 15 and factors_len would be 4.