ds.ov2.bignat
Class Host_vector

java.lang.Object
  extended by ds.ov2.util.Serializable_array
      extended by ds.ov2.bignat.Host_vector
All Implemented Interfaces:
APDU_Serializable

public class Host_vector
extends Serializable_array
implements APDU_Serializable

Host counterpart of Vector. Used to send and receive vectors (i.e., arrays of Bignat) to and from the card. Contains convenience methods to set up arrays of montgomerized numbers, to prepare the factors array needed for Vector.exponent_mod and for creating arrays with montgomery correction factors.

Provides a BigInteger interface to the outside. Internally APDU_BigInteger is used for the conversion from BigInteger to Bignat.

Objects of this class only contain BigIntegers, which are variables sized. When sent to the card the numbers are converted to Bignats, which have a fixed size. The conversion to Bignats can only succeed if all the BigIntegers fit into the size of the Bignats. This size constraint is checked in the compatibility check and in APDU_BigInteger.to_byte_array. But for these checks it is necessary to specify the size of the Bignats on the card in advance in bignat_size arguments of the various constructors. This size is called the configured size hereafter. The BigIntegers that end up in the host vector must be less than 2^(bignat_size * 8).

Host data type. Compatible with nothing. Vector is compatible to this class if Bignat size and length match.

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

CPP Preprocessing
no cpp preprocessing needed
Execution Environment:
host
Author:
Hendrik Tews
Version:
$Revision: 1.21 $
Last Commit:
$Date: 2009-06-19 20:37:35 $ by $Author: tews $

Field Summary
 BigInteger[] a
          BigInteger contents.
 int bignat_size
          Configured size (in bytes) of the numbers.
private  APDU_BigInteger[] sa
          Array for the transmission to and from the card.
 
Constructor Summary
Host_vector(int bignat_size, BigInteger[] args)
          Constructor for sending.
Host_vector(int bignat_size, int length)
          Constructor for receiving.
 
Method Summary
 short from_byte_array(short len, short this_index, byte[] byte_array, short byte_index)
          Deserialization of this object for the OV-chip protocol layer.
protected  APDU_Serializable[] get_array()
          Return the APDU_BigInteger array sa in support for abstract Serializable_array.
static Host_vector make_montgomerized_factors(int bignat_size, BigInteger[] args, Host_modulus mod)
          Make montgomerized base factors for Vector.exponent_mod.
static Host_vector make_montgomerized_vector(int bignat_size, BigInteger[] args, Host_modulus mod)
          Constructor for sending montgomerized numbers to the card.
static Host_vector make_montgomery_corrections(int bignat_size, int len, Host_modulus mod)
          Make Montgomery corrections.
 
Methods inherited from class ds.ov2.util.Serializable_array
get_length, is_compatible_with, size, to_byte_array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ds.ov2.util.APDU_Serializable
is_compatible_with, size, to_byte_array
 

Field Detail

a

public final BigInteger[] a
BigInteger contents. Initialized in the constructor or after receipt.


bignat_size

public final int bignat_size
Configured size (in bytes) of the numbers.


sa

private final APDU_BigInteger[] sa
Array for the transmission to and from the card.

Constructor Detail

Host_vector

public Host_vector(int bignat_size,
                   BigInteger[] args)
Constructor for sending. Creates a Host_vector out of contents of args. The configured size of the numbers will be bignat_size. Only Vectors with the same length (the same number of elements) and where the elements have size bignat_size are compatible to the newly created object.

The elements of args must not be negative and they must fit into bignat_size bytes, i.e., be lesser than 2^(bignat_size * 8).

Parameters:
bignat_size - configured maximal size of the numbers in bytes
args - contents

Host_vector

public Host_vector(int bignat_size,
                   int length)
Constructor for receiving. Sets up an empty Host_vector of length length for receiving Bignats of size bignat_size. After receiving the numbers are available in the array a.

Parameters:
bignat_size - configured Bignat size
length - array size
Method Detail

make_montgomerized_vector

public static Host_vector make_montgomerized_vector(int bignat_size,
                                                    BigInteger[] args,
                                                    Host_modulus mod)
Constructor for sending montgomerized numbers to the card. Montgomerizes the numbers in args and turns them into a Host_vector of configured size bignat_size.

This is a static method, because of the stupid restriction that a call to a different constructor must be the first statement.

Parameters:
bignat_size - configured maximal size of the numbers in bytes
args - not yet montgomerized numbers
mod - modulus
Returns:
Host_vector with the montgomerization of args and configured size bignat_size

make_montgomerized_factors

public static Host_vector make_montgomerized_factors(int bignat_size,
                                                     BigInteger[] args,
                                                     Host_modulus mod)
Make montgomerized base factors for Vector.exponent_mod. Computes all productes of numbers in args and returns them in montgomerized form in a Host_vector of size 2^args.length -1 (the empty product is excluded). The products are ordered as described for Vector.exponent_mod. The returned Host_vector has configured size bignat_size.

This is a static method for the same stupid reason as make_montgomerized_vector(int, java.math.BigInteger[], ds.ov2.bignat.Host_modulus).

Parameters:
bignat_size - configured maximal size
args - base array to compute the factors for
mod - modulus
Returns:
Host_vector of factors as required by Vector.exponent_mod

make_montgomery_corrections

public static Host_vector make_montgomery_corrections(int bignat_size,
                                                      int len,
                                                      Host_modulus mod)
Make Montgomery corrections. Returns a Host_vector with the first len Montgomery corrections, that is with
    mod.mont_fac^1
    mod.mont_fac^2
    mod.mont_fac^3
    ....
 
Everything modulo mod.m of course.

This is a static method for the same stupid reason as make_montgomerized_vector(int, java.math.BigInteger[], ds.ov2.bignat.Host_modulus).

Parameters:
bignat_size - configured size of the returned Host_vector.
len - length of the returned Host_vector
mod - modulus
Returns:
Host_vector with the first len montgomery corrections.

get_array

protected APDU_Serializable[] get_array()
Return the APDU_BigInteger array sa in support for abstract Serializable_array.

Specified by:
get_array in class Serializable_array
Returns:
array of objects to (de-)serialize

from_byte_array

public short from_byte_array(short len,
                             short this_index,
                             byte[] byte_array,
                             short byte_index)
Deserialization of this object for the OV-chip protocol layer. See APDU_Serializable.from_byte_array.

Overridden here to initialize the array a after receipt.

Specified by:
from_byte_array in interface APDU_Serializable
Overrides:
from_byte_array in class Serializable_array
Parameters:
len - available data in byte_array
this_index - number of bytes that have already been read in preceeding calls
byte_array - data array to deserialize from
byte_index - index in byte_array
Returns:
the number of bytes actually read, except for the case where deserialization finished by reading precisely len bytes, in this case len + 1 is returned.