Skip to content

Commit

Permalink
remove debug traces in mult_rsa_trick()
Browse files Browse the repository at this point in the history
  • Loading branch information
Toporin committed Sep 5, 2023
1 parent c97f350 commit 5f3c1f5
Showing 1 changed file with 0 additions and 48 deletions.
48 changes: 0 additions & 48 deletions src/org/satochip/applet/Biginteger.java
Expand Up @@ -366,24 +366,10 @@ public static short mult_rsa_trick(byte[] x, short offsetx, byte[] y, short offs
// x+y => buffer1
Util.arrayFillNonAtomic(buffer1, (short) 0, (short) buffer1.length, (byte) 0);

// // debug return empty buffer... => SW9000
// if (true){
// Util.arrayCopyNonAtomic(buffer1, (short)0, z, offsetz, (short)buffer1.length);
// return (short)buffer1.length;
// }
// //endbug

// copy x (retains MSBF order)
short offsetb1= (short)(buffer1.length-size);
Util.arrayCopyNonAtomic(x, offsetx, buffer1, offsetb1, size);

// // debug return x => SW9000
// if (true){
// Util.arrayCopyNonAtomic(buffer1, (short)0, z, offsetz, (short)buffer1.length);
// return (short)buffer1.length;
// }
// //endbug

// copy y
short offsetb2= (short)(buffer2.length-size);
Util.arrayFillNonAtomic(buffer2, (short) 0, (short) buffer2.length, (byte) 0);
Expand All @@ -393,33 +379,8 @@ public static short mult_rsa_trick(byte[] x, short offsetx, byte[] y, short offs
boolean carry= add_carry(buffer1, (short)0, buffer2, (short)0, (short)buffer1.length);
// should be no carry since buffer are sufficiently large

// // debug return x+y => sw9000
// if (true){
// Util.arrayCopyNonAtomic(buffer1, (short)0, z, offsetz, (short)buffer1.length);
// return (short)buffer1.length;
// }
// //endbug

// debug check FLAG_FAST_MULT_VIA_RSA => return 01 01 01 01 IF MULT
// if (FLAG_FAST_MULT_VIA_RSA == true ){
// Util.arrayFillNonAtomic(z, (short)0, (short)buffer1.length, (byte)1);
// return (short)buffer1.length;
// }
// if (FLAG_FAST_MULT_VIA_RSA == false ) {
// Util.arrayFillNonAtomic(z, (short)0, (short)buffer1.length, (byte)0xf);
// return (short)buffer1.length;
// }
//endbug

// ((x+y)^2) => buffer1
rsa_cipher.doFinal(buffer1, (byte) 0, (short) buffer1.length, buffer1, (short) 0);

// // debug return (x+y)^2 => SW9000, calcul ok
// if (true){
// Util.arrayCopyNonAtomic(buffer1, (short)0, z, offsetz, (short)buffer1.length);
// return (short)buffer1.length;
// }
// //endbug

// y^2 => buffer2
// y is already present in buffer2
Expand All @@ -432,7 +393,6 @@ public static short mult_rsa_trick(byte[] x, short offsetx, byte[] y, short offs
carry= subtract(buffer1, (short)0, buffer2, (short)0, (short)buffer1.length);
// todo: carry should be false


// x^2 => buffer2
// todo: support x^2 precomputation if reused multiple times
Util.arrayFillNonAtomic(buffer2, (short) 0, (short) buffer2.length, (byte) 0);
Expand All @@ -444,13 +404,6 @@ public static short mult_rsa_trick(byte[] x, short offsetx, byte[] y, short offs
carry= subtract(buffer1, (short)0, buffer2, (short)0, (short)buffer1.length);
// todo: carry should be false

// // debug return (x+y)^2 - y^2 - x^2 => OK!
// if (true){
// Util.arrayCopyNonAtomic(buffer1, (short)0, z, offsetz, (short)buffer1.length);
// return (short)buffer1.length;
// }
// //endbug

// we now have 2xy in buffer1, divide it by 2 => shift by one bit and fill back into z
short res = 0;
short res2 = 0;
Expand All @@ -466,7 +419,6 @@ public static short mult_rsa_trick(byte[] x, short offsetx, byte[] y, short offs
z[offsetz]= (byte)res;
return (short)buffer1.length;

// return SW90000 and calcul correct!
// todo: optimization: for 32bytes mult, bytes 0 to 31 (out of 96) should be 0 => skip computations?
}

Expand Down

0 comments on commit 5f3c1f5

Please sign in to comment.