ds.ov2.bignat
Class Host_modulus

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

public class Host_modulus
extends Serializable_array
implements APDU_Serializable

Host counterpart of Modulus. Used to send and receive objects of type Modulus to and from the card. The constructor conveniently computes auxiliary numbers from the pure modulus that are needed on the card (Modulus.last_digit_inverse) and on the host (mont_fac, demont_fac).

This class can only be used for odd moduli, because it is designed to be used with Montgomery multiplication.

This class provides a BigInteger interface to the outside. When communicating with the card, conversion to and from Bignat is done internally with the help of APDU_BigInteger.

For checking compatibility and sizes it is necessary to specify the size of the Bignat inside the Modulus on the card in advance. This size will be called the configured size hereafter. The Modulus must be less than 2^(bignat_size * 8).

This is a host data type. It is compatible with nothing. The card data type Modulus is compatible with this class.

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

CPP Preprocessing
This class uses the following cpp defines: BIGNAT_USE_BYTE , DOUBLE_DIGIT_TYPE, APDU_DOUBLE_DIGIT_TYPE
Execution Environment:
host
Author:
Hendrik Tews
Version:
$Revision: 1.23 $
Last Commit:
$Date: 2009-06-19 20:37:35 $ by $Author: tews $

Field Summary
private  APDU_short apdu_last_digit_inverse
          APDU wrapper of type APDU_DOUBLE_DIGIT_TYPE for last_digit_inverse.
private  APDU_BigInteger apdu_m
          APDU wrapper for the modulus m.
 int bignat_size
          Configured Bignat size.
 BigInteger demont_fac
          Demontgomerization factor.
 long last_digit_inverse
          Negated modular inverse of the last digit of m.
 BigInteger m
          Modulus.
 BigInteger mont_fac
          Montgomerization factor.
private  APDU_Serializable[] serializable_array
          Serializable array for the Serializable_array base class.
 
Constructor Summary
Host_modulus(int bignat_size)
          Constructor for receiving.
Host_modulus(int bignat_size, BigInteger m)
          Constructor for sending.
 
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 serializable_array in support for abstract Serializable_array.
 
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

bignat_size

public final int bignat_size
Configured Bignat size. Initialized from the constructor argument bignat_size.


m

public BigInteger m
Modulus. Initialized in the sending constructor or after receipt.


mont_fac

public BigInteger mont_fac
Montgomerization factor. Initialized only by the sending constructor.

To montgomerize a number x on the host, compute x.multiply(mod.mont_fac).mod(mod.m), where mod is the Host_modulus.


demont_fac

public BigInteger demont_fac
Demontgomerization factor. Initialized only by the sending constructor.

To demontgomerize a number x on the host, compute x.multiply(mod.demont_fac).mod(mod.m), where mod is the Host_modulus.


last_digit_inverse

public long last_digit_inverse
Negated modular inverse of the last digit of m. See Modulus.last_digit_inverse. Initialized to the correct value in the sending constructor. Left uninitialized by the receiving constructor. Is set to the received value after receipt.


apdu_m

private final APDU_BigInteger apdu_m
APDU wrapper for the modulus m.


apdu_last_digit_inverse

private final APDU_short apdu_last_digit_inverse
APDU wrapper of type APDU_DOUBLE_DIGIT_TYPE for last_digit_inverse.


serializable_array

private final APDU_Serializable[] serializable_array
Serializable array for the Serializable_array base class. Will contain Modulus.serializable_contents_length length elements, currently the modulus m and apdu_last_digit_inverse in this order. Must be compatible with Modulus.serializable_contents.

Constructor Detail

Host_modulus

public Host_modulus(int bignat_size)
Constructor for receiving. Initializes the arrays and the APDU wrappers but not the auxiliary data mont_fac, demont_fac and last_digit_inverse. The two factors remains invalid for ever, even after a complete receipt from the card. Only the modulus m and last_digit_inverse will be initialized after receipt.

Only a Modulus of size bignat_size is compatible with an object created from this constructor.

Parameters:
bignat_size - configured size

Host_modulus

public Host_modulus(int bignat_size,
                    BigInteger m)
Constructor for sending. Initializes everything.

Only a Modulus of size bignat_size is compatible with an object created from this constructor.

Parameters:
bignat_size - configured size in bytes
m - modulus
Method Detail

get_array

protected APDU_Serializable[] get_array()
Return serializable_array 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 set m and last_digit_inverse 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.