Skip to content

Commit

Permalink
Add software implementatino of SHA512 as fallback option
Browse files Browse the repository at this point in the history
  • Loading branch information
dufkan committed Jul 20, 2021
1 parent 20018eb commit 70e5f65
Show file tree
Hide file tree
Showing 2 changed files with 782 additions and 1 deletion.
9 changes: 8 additions & 1 deletion applet/src/main/java/applet/MainApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javacard.framework.*;
import javacard.security.*;
import applet.jcmathlib.*;
import applet.swalgs.*;

public class MainApplet extends Applet implements MultiSelectable {
private ECConfig ecc;
Expand All @@ -15,7 +16,7 @@ public class MainApplet extends Applet implements MultiSelectable {
private byte[] prefix = new byte[32];
private byte[] publicKey = new byte[32];

private MessageDigest hasher = MessageDigest.getInstance(MessageDigest.ALG_SHA_512, false);
private MessageDigest hasher;

private byte[] ramArray = JCSystem.makeTransientByteArray(Wei25519.POINT_SIZE, JCSystem.CLEAR_ON_DESELECT);
private RandomData random = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM);
Expand All @@ -28,6 +29,12 @@ public MainApplet(byte[] buffer, short offset, byte length) {
OperationSupport os = OperationSupport.getInstance();
os.setCard(OperationSupport.SIMULATOR);

try {
hasher = MessageDigest.getInstance(MessageDigest.ALG_SHA_512, false);
} catch (CryptoException e) {
hasher = new Sha2(Sha2.SHA_512);
}

ecc = new ECConfig((short) 256);

privateKey = new Bignat((short) 32, JCSystem.MEMORY_TYPE_PERSISTENT, ecc.bnh);
Expand Down
Loading

0 comments on commit 70e5f65

Please sign in to comment.