forked from OpenCryptoProject/JCMathLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
applet/src/test/java/tests/BigNatInternal/getFirstBitPositionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package tests.BigNatInternal; | ||
|
||
import javacard.framework.JCSystem; | ||
import opencrypto.jcmathlib.BigNat; | ||
import opencrypto.jcmathlib.ResourceManager; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class getFirstBitPositionTest { | ||
@Test | ||
public void noZero() { | ||
ResourceManager rm = new ResourceManager((short) 256); | ||
byte memoryType = JCSystem.MEMORY_TYPE_TRANSIENT_RESET; | ||
BigNat bn = new BigNat((short) 10, memoryType, rm); | ||
|
||
byte[] data = {(byte) 0xff}; | ||
bn.fromByteArray(data, (short) 0, (short) data.length); | ||
|
||
short position = bn.getFirstBitPosition((byte) 0); | ||
Assertions.assertEquals((short) 8, position); /* no zero bit */ | ||
} | ||
|
||
@Test | ||
public void noOne() { | ||
ResourceManager rm = new ResourceManager((short) 256); | ||
byte memoryType = JCSystem.MEMORY_TYPE_TRANSIENT_RESET; | ||
BigNat bn = new BigNat((short) 10, memoryType, rm); | ||
|
||
byte[] data = {(byte) 0x00}; | ||
bn.fromByteArray(data, (short) 0, (short) data.length); | ||
|
||
short position = bn.getFirstBitPosition((byte) 1); | ||
Assertions.assertEquals((short) 8, position); /* no zero bit */ | ||
} | ||
|
||
@Test | ||
public void oneByteZero() { | ||
ResourceManager rm = new ResourceManager((short) 256); | ||
byte memoryType = JCSystem.MEMORY_TYPE_TRANSIENT_RESET; | ||
BigNat bn = new BigNat((short) 3, memoryType, rm); | ||
|
||
byte[] data = {(byte) 0x1f}; | ||
bn.fromByteArray(data, (short) 0, (short) data.length); | ||
|
||
short position = bn.getFirstBitPosition((byte) 0); | ||
Assertions.assertEquals((short) 5, position); | ||
} | ||
|
||
@Test | ||
public void oneByteOne() { | ||
ResourceManager rm = new ResourceManager((short) 256); | ||
byte memoryType = JCSystem.MEMORY_TYPE_TRANSIENT_RESET; | ||
BigNat bn = new BigNat((short) 3, memoryType, rm); | ||
|
||
byte[] data = {(byte) 0x20}; | ||
bn.fromByteArray(data, (short) 0, (short) data.length); | ||
|
||
short position = bn.getFirstBitPosition((byte) 1); | ||
Assertions.assertEquals((short) 5, position); | ||
} | ||
|
||
@Test | ||
public void twoBytesZero() { | ||
ResourceManager rm = new ResourceManager((short) 256); | ||
byte memoryType = JCSystem.MEMORY_TYPE_TRANSIENT_RESET; | ||
BigNat bn = new BigNat((short) 3, memoryType, rm); | ||
|
||
byte[] data = {(byte) 0x3F, (byte) 0xff}; | ||
bn.fromByteArray(data, (short) 0, (short) data.length); | ||
|
||
short position = bn.getFirstBitPosition((byte) 0); | ||
Assertions.assertEquals((short) 14, position); | ||
} | ||
|
||
@Test | ||
public void twoBytesOne() { | ||
ResourceManager rm = new ResourceManager((short) 256); | ||
byte memoryType = JCSystem.MEMORY_TYPE_TRANSIENT_RESET; | ||
BigNat bn = new BigNat((short) 3, memoryType, rm); | ||
|
||
byte[] data = {(byte) 0xC0, (byte) 0x00}; | ||
bn.fromByteArray(data, (short) 0, (short) data.length); | ||
|
||
short position = bn.getFirstBitPosition((byte) 1); | ||
Assertions.assertEquals((short) 14, position); | ||
} | ||
} |