From ba5bf89f7e658aa86adba213138a4871ee4596c6 Mon Sep 17 00:00:00 2001 From: Heiko Schaefer Date: Sun, 17 Oct 2021 19:38:56 +0200 Subject: [PATCH] Allow changing of data size in ByteContainer.setBytes(byte[], short, short). The motivation for this patch is https://github.com/ANSSI-FR/SmartPGP/issues/40. However, this workaround avoids looking at the underlying problem: ECKeyImpl(byte, short) should not initialize the DomainParameters (according to its own docs), but does. This leads to problems with NIST P-521 because the default parameter for b has a leading zero bit that gets stripped, leading to a change in data size, when SmartPGP later sets b explicitly with the leading zero bit intact. --- src/main/java/com/licel/jcardsim/crypto/ByteContainer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/licel/jcardsim/crypto/ByteContainer.java b/src/main/java/com/licel/jcardsim/crypto/ByteContainer.java index 240fb74f..7d4a8ef3 100644 --- a/src/main/java/com/licel/jcardsim/crypto/ByteContainer.java +++ b/src/main/java/com/licel/jcardsim/crypto/ByteContainer.java @@ -106,7 +106,7 @@ public void setBytes(byte[] buff) { * @param length length of data in byte array */ public void setBytes(byte[] buff, short offset, short length) { - if (data == null) { + if (data == null || this.length != length) { switch (memoryType) { case JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT: data = JCSystem.makeTransientByteArray(length, JCSystem.CLEAR_ON_DESELECT);