|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectds.ov2.front.RSA_data
public class RSA_data
Data structures for the OV-chip RSA applet. Together with precisely
one of RSA_plain_card
or RSA_mont_card
this class
implements the protocols for the RSA applet. With RSA_plain_card
it yields the plain RSA applet, with RSA_mont_card
it yields the Montgomerizing RSA applet. This class
contains the static and some transient data. Some other data and
the methods are in RSA_plain_card
and RSA_mont_card
. The distribution of the data between this class and
RSA_plain_card
/RSA_mont_card
is very simple: All
variables that take part in the communication with the host are in
this class, the remainder is in RSA_plain_card
/RSA_mont_card
. Therefore the host driver only has to include this
class but not RSA_plain_card
or RSA_mont_card
.
For the RSA applet there are three sizes of bignats: short ones, double short ones and long ones. The short bignats appear in the exponents, they should be 100-200 bits long. The short bignats are never combined with Montgomery multiplication, they therefore never contain Montgomery digits. The long bignats are the bases, the blinding and the modulus. They should be 1000-2000 bits long. The long bignats are combined with Montgomery multiplication. They must therefore always have two leading zero digits (i.e., two leading zero bytes or shorts), the Montgomery digits. Some computations with the exponent numbers have intermediate results of the double size. For these there is one variable of double short length (200-400 bits).
The applet is always in one of four states, see state
:
UNALLOCTED
RSA_squared_card.allocate(short, short, short, short)
) is
run. In this state only the allocate protocol is enabled. All other
entries are null in Front_protocols
in this state.
UNINITIALIZED
RSA_squared_card.allocate(short, short, short, short)
)
finished and before the
initialize protocol (RSA_squared_card.initialize()
)
is run. In this state only the
initialize protocol is enabled. From this state on all protocols
are represented with non-null references in Front_protocols
. In this state all other protocols beside
initialize are disabled with ASSERT.
INITIALIZED
BLINDED
UNALLOCTED
state. For Java Cards
the use of reset will lead to uncollected garbage on the card (the
reset protocol has been implemented for the phone).
Field Summary | |
---|---|
(package private) APDU_byte |
applet_id
Applet identification. |
short |
attribute_length
The number of attributes this card possesses. |
Vector |
base_factors
Base factors needed for Vector.exponent_mod . |
Vector |
bases
Bases. |
static short |
BLINDED
State constant for the state BLINDED, value 3. |
Vector |
current_attributes
Current attributes. |
Bignat |
current_blinded_a
Current blinded attribute expression. |
Bignat |
current_blinding
Current blinding. |
Signature |
current_signature
Current signature on the current blinded attribute expression. |
(package private) Bignat |
gamma_beta_3
Beta_3 and gamma. |
(package private) Bignat |
host_alpha
Host commitment alpha for the signature protocol. |
(package private) Bignat |
host_response
Host response r for the signature protocol. |
static short |
INITIALIZED
State constant for the state INITIALIZED, value 2. |
static byte |
INVALID_APPLET_ID
Invalid applet identification constant, with value 0. |
byte |
mod_first_digit_mask
Digit mask of the most significant byte of the modulus n . |
static byte |
MONT_RSA_APPLET
Montgomerized RSA Applet identification constant, with value 3. |
Bignat |
montgomerized_one
Montgomerized 1. |
(package private) Vector |
montgomery_corrections
Montgomery correction factors. |
Modulus |
n
The RSA parameter n. |
Vector |
new_attributes
New attributes. |
Bignat |
new_blinded_a
New blinded attribute expression. |
Bignat |
new_blinding
New blinding. |
Signature |
new_signature
New signature on the new blinded attribute expression. |
static PrintWriter |
out
Debug printer. |
static byte |
PLAIN_RSA_APPLET
Plain RSA Applet identification constant, with value 2. |
Bignat |
ptls_key
The public key of service provider. |
(package private) Vector |
remainders
Remainders vector. |
(package private) Bignat |
result
Temporary result. |
(package private) Bignat |
sig_remainder
Remainder c in the signature protocol. |
static byte |
SQUARED_RSA_APPLET
Squaring RSA applet identification constant, with value 4. |
static byte |
SQUARED4_RSA_APPLET
Square 4 RSA applet identification constant, with value 5. |
short |
state
State field. |
static short |
UNALLOCTED
State constant for the state UNALLOCTED, value 0. |
static short |
UNINITIALIZED
State constant for the state UNINITIALIZED, value 1. |
Bignat |
v
The RSA parameter v. |
byte |
v_first_digit_mask
Digit mask of the most significant byte of v . |
Constructor Summary | |
---|---|
RSA_data()
Nonallocating constructor. |
Method Summary | |
---|---|
void |
allocate(short short_bignat_size,
short long_bignat_size,
short attribute_length,
short mont_correction_len,
byte applet_id)
Allocate all data and initialize all aliases. |
Bignat |
get_montgomery_correction(short factors)
Return the Montgomery correction factor for factors
factors. |
void |
set_blinding(Bignat beta)
Set beta. |
void |
set_current_blinding()
Set current blinding. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte INVALID_APPLET_ID
public static final byte PLAIN_RSA_APPLET
public static final byte MONT_RSA_APPLET
public static final byte SQUARED_RSA_APPLET
public static final byte SQUARED4_RSA_APPLET
APDU_byte applet_id
allocate(short, short, short, short, byte)
.
public static final short UNALLOCTED
public static final short UNINITIALIZED
public static final short INITIALIZED
public static final short BLINDED
public short state
public Modulus n
This modulus contains a long Bignat.
public byte mod_first_digit_mask
n
. For generating random numbers less than n
.m
we need a mask for the most significant byte in
n.m. The mask will mask everything above the most significant
bit in n.m. Initialized once during personalization of the
applet (in RSA_plain_card.initialize()
/RSA_mont_card.initialize()
).
Has type DIGIT_TYPE.
public Bignat v
n
),
where phi is Eulers phi function. It will always be aliased in
current_attributes
[attribute_length]
and new_attributes
[attribute_length]
. This is a short Bignat.
public byte v_first_digit_mask
v
. Needed
for generating random numbers less then v
.
Initialized once during personalization of the applet (in
RSA_plain_card.initialize()
/RSA_mont_card.initialize()
).
Has type DIGIT_TYPE.
public Bignat ptls_key
x
^v
, where x
is the unknown private key.
This is a long Bignat.
public short attribute_length
remainders
has only
size attribute_length.
public Vector bases
attribute_length
). bases[attribute_length
] is always
an alias to either the current blinding current_blinding
or the current beta. There is no guarantee
on what is contained in bases[attribute_length
], so
always set it before use with either set_current_blinding()
or set_blinding
.
bases has length attribute_length
+ 1. It is filled with
long Bignats.
public Vector base_factors
Vector.exponent_mod
. The array contains the products of all
possible combinations of the bases in montgomerized form with
one exception: the empty product is not contained. See also
Host_vector.make_montgomerized_factors
.
These factors are only needed in the Montgomerizing applet,
therefore, the length of this array is 1 on the plain applet
(zero-length vectors do not exists, see the Bignat_array constructor
).
On the Montgomerizing applet the length is 2^attribute_length
-1. The array contains
long bignats.
public Vector current_attributes
attribute_length
is always
an alias of v
.
At the end of the resign protocol the current_attributes
and the new_attributes
are
atomically swapped. This is done by exchanging the two
references in a transaction, see RSA_plain_card.switch_to_new_attributes
and RSA_mont_card.switch_to_new_attributes
.
Length attribute_length
+ 1. Filled with short
bignats.
public Vector new_attributes
Index attribute_length
is always
an alias of v
.
At the end of the resign protocol the new_attributes
and the current_attributes
are
atomically swapped. This is done by exchanging the two
references in a transaction, see RSA_plain_card.switch_to_new_attributes
and RSA_mont_card.switch_to_new_attributes
.
Length attribute_length
+ 1. Filled with short
bignats.
public Bignat current_blinding
bases
[attribute_length]
.
At the end of the resign protocol the current_blinding
and the new_blinding
are
atomically swapped. This is done by exchanging the two
references in a transaction, see RSA_plain_card.switch_to_new_attributes
and RSA_mont_card.switch_to_new_attributes
.
Long Bignat.
public Bignat new_blinding
bases
[attribute_length]
.
At the end of the resign protocol the new_blinding
and the current_blinding
are
atomically swapped. This is done by exchanging the two
references in a transaction, see RSA_plain_card.switch_to_new_attributes
and RSA_mont_card.switch_to_new_attributes
.
Long Bignat.
public Bignat current_blinded_a
bases
^current_attributes
, where the current_blinding
has been set in bases
.
At the end of the resign protocol current_blinded_a
and the new_blinded_a
are
atomically swapped. This is done by exchanging the two
references in a transaction, see RSA_plain_card.switch_to_new_attributes
and RSA_mont_card.switch_to_new_attributes
.
Long Bignat.
public Bignat new_blinded_a
bases
^new_attributes
, where the new_blinding
has been set in bases
.
At the end of the resign protocol new_blinded_a
and the current_blinded_a
are
atomically swapped. This is done by exchanging the two
references in a transaction, see RSA_plain_card.switch_to_new_attributes
and RSA_mont_card.switch_to_new_attributes
.
Long Bignat.
public Signature current_signature
At the end of the resign protocol the current_signature
and the new_signature
are
atomically swapped. This is done by exchanging the two
references in a transaction, see RSA_plain_card.switch_to_new_attributes
and RSA_mont_card.switch_to_new_attributes
.
public Signature new_signature
At the end of the resign protocol the current_signature
and the new_signature
are
atomically swapped. This is done by exchanging the two
references in a transaction, see RSA_plain_card.switch_to_new_attributes
and RSA_mont_card.switch_to_new_attributes
.
public Bignat montgomerized_one
Vector.exponent_mod
.
Long Bignat.
Vector montgomery_corrections
get_montgomery_correction
for additional explanations.
Length is determined by the mont_correction_len
argument of allocate
. For the plain RSA applet the
length must be at least 5. Filled with long bignats.
Bignat host_alpha
Long bignat.
Bignat host_response
Long bignat.
Vector remainders
RSA_plain_card.make_sig_hash()
/RSA_mont_card.make_sig_hash()
step of the resign protocol it
first carries the attribute updates. Later in that step the
remainder c of the resign protocol is stored in index 0 via the
sig_remainder
alias.
There is no blinding in the remainders. The length is therefore
just attribute_length
. Filled with short Bignats.
Bignat sig_remainder
remainders
[0]
, because the remainders array is
not used when c is needed.
Short bignat.
Bignat result
RSA_plain_card.temp_2
/RSA_mont_card.temp_2
and RSA_plain_card.temp_3
/RSA_mont_card.temp_2
. Long bignat.
Bignat gamma_beta_3
Short bignat.
public static PrintWriter out
Constructor Detail |
---|
public RSA_data()
allocate
.
Method Detail |
---|
public void set_current_blinding()
bases
[attribute_length]
to current_blinding
.
public void set_blinding(Bignat beta)
bases
[attribute_length]
to beta
.
public Bignat get_montgomery_correction(short factors)
factors
factors. In the plain RSA applet non of the numbers is
montgomerized. For most computations, however, Montgomery
multiplication is used. Therefore all computations contain
an additional Montgomery correction factor. To muliply A
and B
do C x A x B
, where x
denotes
Montgomery multiplication and C ==
get_montgomery_correction(2)
.
Note that for counting the number of factors the Montgomery correction factor is not counted. Therefore the smallest number of factors is 2.
factors
- number of factors (not counting the Montgomery
correction factor)
factors
factors
ArrayIndexOutOfBoundsException
- if factors
is
larger than the maximal correction factor contained in montgomery_corrections
.public void allocate(short short_bignat_size, short long_bignat_size, short attribute_length, short mont_correction_len, byte applet_id)
This allocate here is always called twice! In the normal case, where the host application is talking to a java card one object of this class exists both on the card and in the host application. Both must execute allocate, of course.
In the host testframe, where applet code and host code are linked in
one application there is only one RSA_data object. Then allocate
here is called twice on the same object. Once from the action
of the allocate step and once directly from the host driver in
host_side_init
. There are special
provisions to make sure this second call does not reallocate
everything.
short_bignat_size
- size in bytes of the short (exponent) bignatslong_bignat_size
- size in bytes of the long (base) bignatsattribute_length
- number of attributes (without counting
the blinding)mont_correction_len
- length of the montgomery_corrections
arrayapplet_id
- applet identification
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |