|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectds.ov2.util.Serializable_array
ds.ov2.bignat.Modulus
public class Modulus
Division modulus for Java Card. Contains the modulus itself and the negated inverse of its last digit. The latter is needed inside Montgomery multiplication.
For a number of general topics see also the package description.
This is a card data type. It is compatible with
Host_moduli, configured to the same
size
| Field Summary | |
|---|---|
short |
last_digit_inverse
Negated modular inverse of the last digit. |
private APDU_short |
last_digit_inverse_box
APDU wrapper for last_digit_inverse. |
Bignat |
m
The modulus itself. |
Bignat |
mod_x_2
Modulus times 2. |
Bignat |
mod_x_3
Modulus times 3. |
private APDU_Serializable[] |
serializable_contents
Serializable array for the Serializable_array base
class. |
(package private) static short |
serializable_contents_length
Length of the underlying serializable array. |
| Constructor Summary | |
|---|---|
Modulus(short bignat_size,
boolean in_ram)
Allocating constructor. |
|
| Method Summary | |
|---|---|
void |
allocate_multiples()
Allocate the space for the multiples mod_x_2 and
mod_x_3 of the modulus m. |
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_contents in support for abstract
Serializable_array. |
short |
get_length()
Return serializable_contents_length
as effective size in support for abstract
Serializable_array. |
private void |
initialize_multiples()
(Re-)Initialize the multiples mod_x_2 and mod_x_3 if they have been allocated before with allocate_multiples(). |
boolean |
is_compatible_with(Object o)
Compatibility check for the OV-chip protocol layer. |
void |
register_long_bignats()
Register the modulus and the multiples (if allocated) in Resize for resizing. |
short |
to_byte_array(short len,
short this_index,
byte[] byte_array,
short byte_index)
Serialization of this object for the OV-chip protocol layer. |
| Methods inherited from class ds.ov2.util.Serializable_array |
|---|
size |
| 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 |
|---|
size |
| Field Detail |
|---|
public Bignat m
public Bignat mod_x_2
allocate_multiples only when
needed for squared_rsa_mult_4.
public Bignat mod_x_3
allocate_multiples only when
needed for squared_rsa_mult_4.
public short last_digit_inverse
Conveniently computed by the initializing
Host_modulus constructor, see Host_modulus.last_digit_inverse.
Must fulfill the following property: m *
last_digit_inverse + 1 == 0 (modulo Bignat.bignat_base), where bignat_base is 256 for the
byte/short configuration and 2^32 for the int/long
configuration.
To compute one takes the inverse of the last digit of m with respect to Bignat.bignat_base and multiplies
it with -1, i.e., Bignat.bignat_base -1, again modulo
Bignat.bignat_base. Because Bignat.bignat_base
is a power of 2, the modular inverse exists only for odd
moduli.
private APDU_short last_digit_inverse_box
last_digit_inverse. Used for
(de-)serialization of last_digit_inverse.
static final short serializable_contents_length
private APDU_Serializable[] serializable_contents
Serializable_array base
class. Will contain serializable_contents_length
length elements, currently the modulus m and last_digit_inverse_box in this order. Must be compatible with
Host_modulus.serializable_array.
| Constructor Detail |
|---|
public Modulus(short bignat_size,
boolean in_ram)
Bignat of size
bignat_size for the modulus and allocates and fills the
remaining fields, in particular serializable_contents.
The argument in_ram is passed through to the Bignat constructor, that is,
if in_ram is true then the modulus is allocated in
transient RAM.
bignat_size - size of the modulusin_ram - allocate modulus in transient ram if true| Method Detail |
|---|
public void register_long_bignats()
Resize for resizing. Only available if
VARIABLE_SIZE_BIGNATS is defined. The internal Bignat, containing the modulus, is registered as a long
Bignat.
public void allocate_multiples()
mod_x_2 and
mod_x_3 of the modulus m.
They are needed only inside squared_rsa_mult_4, so only call this method if squared_rsa_mult_4 is used with this
modulus.
If VARIABLE_SIZE_BIGNATS
is defined this method must be called before register_long_bignats() (and thus before the first resize)
otherwise the multiples will not be resized.
Once allocated the multiples are automatically initialized when
the modulus is initialized inside from_byte_array. This requires of course that the first two
bits of the modulus are empty, because otherwise an overflow
will occur inside add.
Asserts that that mod_x_2 and mod_x_3 are
null, ie. that this method has not been called before.
private void initialize_multiples()
mod_x_2 and mod_x_3 if they have been allocated before with allocate_multiples(). Automatically called from from_byte_array.
Requires that the first two bits of the just received modulus
are zero, because otherwise add will
overflow.
protected APDU_Serializable[] get_array()
serializable_contents in support for abstract
Serializable_array.
get_array in class Serializable_arraypublic short get_length()
serializable_contents_length
as effective size in support for abstract
Serializable_array.
get_length in class Serializable_arrayserializable_contents_lengthpublic boolean is_compatible_with(Object o)
APDU_Serializable.is_compatible_with.
An object of this class is compatible with instances of Modulus
or Host_modulus if the internal modulus has the same
size.
is_compatible_with in interface APDU_Serializableis_compatible_with in class Serializable_arrayo - actual argument or result
o.
public short to_byte_array(short len,
short this_index,
byte[] byte_array,
short byte_index)
APDU_Serializable.to_byte_array. Overridden here to update
last_digit_inverse_box before serialization.
to_byte_array in interface APDU_Serializableto_byte_array in class Serializable_arraylen - available space in byte_arraythis_index - number of bytes that
have already been written in preceeding callsbyte_array - data array to serialize the state intobyte_index - index in byte_array
len bytes, in this case len + 1 is
returned.
public short from_byte_array(short len,
short this_index,
byte[] byte_array,
short byte_index)
APDU_Serializable.from_byte_array. Overridden here to update
last_digit_inverse after deserialization.
from_byte_array in interface APDU_Serializablefrom_byte_array in class Serializable_arraylen - available data in byte_arraythis_index - number of bytes that
have already been read in preceeding callsbyte_array - data array to deserialize frombyte_index - index in byte_array
len bytes, in this case len + 1 is
returned.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||