I want to optimize SHA-3 algorithm on a Java Card. I need a fast algorithm consuming less memory which allows to easy convert byte[]
to short[]
(or short[]
to byte[]
). My current implementation looks like this:
private short[] byteToShort(byte[] b,int len)
{
short len_conv = (short)(len/2);
for ( short x = 0; x < len_conv;x++)
{
for ( short j = 0 ; j < 2 ; j++)
aux[j] = b[2*x+j];
temp_conv[x] = (short)((((short)aux[1]) & 0xFF) | ((((short)(aux[0]) & 0xFF) << 8 )));
}
return temp_conv;
}
where len
is actual size of the b
array and aux
and temp_conv
are defined as private and allocated as :
short[] temp_conv = JCSystem.makeTransientShortArray((short)255,JCSystem.CLEAR_ON_DESELECT); // used during conversion
byte[] aux = new byte[2];
I currently use Java Card v 2.2.2