Skip to content

Commit 4cdc156

Browse files
committed
compatibility updates
1 parent 346b0f9 commit 4cdc156

File tree

8 files changed

+39
-29
lines changed

8 files changed

+39
-29
lines changed

core/src/main/java/org/bouncycastle/crypto/engines/Grain128AEADEngine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,8 @@ public byte[] getBuf()
553553
public void erase()
554554
{
555555
Arrays.fill(this.buf, (byte)0);
556-
reset();
556+
// this for JVM compatibility
557+
this.reset();
557558
}
558559
}
559560
}

core/src/main/java/org/bouncycastle/pqc/crypto/picnic/LowmcConstants.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.bouncycastle.pqc.crypto.picnic;
22

3+
import java.io.ByteArrayOutputStream;
34
import java.io.IOException;
45
import java.io.InputStream;
56
import java.util.Properties;
@@ -195,8 +196,7 @@ class LowmcConstants
195196
static private int[] ReadFromProperty(Properties props, String key, int intSize)
196197
{
197198
String s = props.getProperty(key);
198-
s = s.replaceAll(",", "");
199-
byte[] bytes = Hex.decode(s);
199+
byte[] bytes = Hex.decode(removeCommas(s));
200200
int[] ints = new int[intSize];
201201
for (int i = 0; i < bytes.length / 4; i++)
202202
{
@@ -205,6 +205,21 @@ static private int[] ReadFromProperty(Properties props, String key, int intSize)
205205
return ints;
206206
}
207207

208+
private static byte[] removeCommas(String s)
209+
{
210+
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
211+
for (int i = 0; i != s.length(); i++)
212+
{
213+
if (s.charAt(i) == ',')
214+
{
215+
continue;
216+
}
217+
bOut.write(s.charAt(i));
218+
219+
}
220+
return bOut.toByteArray();
221+
}
222+
208223
// Functions to return individual matricies and round constants
209224

210225
/* Return a pointer to the r-th matrix. The caller must know the dimensions */

core/src/test/java/org/bouncycastle/crypto/test/Grain128AEADTest.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ private void testVectors()
3939
InputStream src = Grain128AEADTest.class.getResourceAsStream("/org/bouncycastle/crypto/test/LWC_AEAD_KAT_128_96.txt");
4040
BufferedReader bin = new BufferedReader(new InputStreamReader(src));
4141
String line;
42-
String[] data;
4342
byte[] ptByte, adByte;
4443
byte[] rv;
4544
HashMap<String, String> map = new HashMap<String, String>();
4645
while ((line = bin.readLine()) != null)
4746
{
48-
data = line.split(" ");
49-
if (data.length == 1)
47+
int a = line.indexOf('=');
48+
if (a < 0)
5049
{
5150
params = new ParametersWithIV(new KeyParameter(Hex.decode((String)map.get("Key"))), Hex.decode((String)map.get("Nonce")));
5251
grain.init(true, params);
@@ -65,14 +64,7 @@ private void testVectors()
6564
}
6665
else
6766
{
68-
if (data.length >= 3)
69-
{
70-
map.put(data[0].trim(), data[2].trim());
71-
}
72-
else
73-
{
74-
map.put(data[0].trim(), "");
75-
}
67+
map.put(line.substring(0, a).trim(), line.substring(a + 1).trim());
7668
}
7769
}
7870
}

core/src/test/java/org/bouncycastle/pqc/crypto/test/SNTRUPrimeTest.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ public void testKEM()
4848
{
4949
if (! line.startsWith("count"))
5050
continue;
51-
int count = Integer.parseInt(line.split("=")[1].trim());
52-
line = resourceReader.readLine();
53-
byte[] seed = Hex.decode(line.split("=")[1].trim());
54-
line = resourceReader.readLine();
55-
byte[] pk = Hex.decode(line.split("=")[1].trim());
56-
line = resourceReader.readLine();
57-
byte[] sk = Hex.decode(line.split("=")[1].trim());
58-
line = resourceReader.readLine();
59-
byte[] ct = Hex.decode(line.split("=")[1].trim());
60-
line = resourceReader.readLine();
61-
byte[] ss = Hex.decode(line.split("=")[1].trim());
51+
52+
int a = line.indexOf("=");
53+
int count = Integer.parseInt(line.substring(a + 1).trim());
54+
line = resourceReader.readLine(); a = line.indexOf("=");
55+
byte[] seed = Hex.decode(line.substring(a + 1).trim());
56+
line = resourceReader.readLine(); a = line.indexOf("=");
57+
byte[] pk = Hex.decode(line.substring(a + 1).trim());
58+
line = resourceReader.readLine(); a = line.indexOf("=");
59+
byte[] sk = Hex.decode(line.substring(a + 1).trim());
60+
line = resourceReader.readLine(); a = line.indexOf("=");
61+
byte[] ct = Hex.decode(line.substring(a + 1).trim());
62+
line = resourceReader.readLine(); a = line.indexOf("=");
63+
byte[] ss = Hex.decode(line.substring(a + 1).trim());
6264

6365
if (sampler.skipTest(count))
6466
{

util/src/main/java/org/bouncycastle/asn1/cmp/CertAnnContent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static CertAnnContent getInstance(Object o)
6868
}
6969
catch (IOException e)
7070
{
71-
throw new RuntimeException(e.getMessage(), e);
71+
throw new IllegalArgumentException(e.getMessage(), e);
7272
}
7373
}
7474

util/src/main/java/org/bouncycastle/asn1/cmp/OOBCert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static OOBCert getInstance(Object o)
6363
}
6464
catch (IOException e)
6565
{
66-
throw new RuntimeException(e.getMessage(), e);
66+
throw new IllegalArgumentException(e.getMessage(), e);
6767
}
6868
}
6969

util/src/main/jdk1.4/org/bouncycastle/asn1/cmp/CertAnnContent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static CMPCertificate getInstance(Object o)
6868
}
6969
catch (IOException e)
7070
{
71-
throw new RuntimeException(e.getMessage(), e);
71+
throw new IllegalArgumentException(e.getMessage());
7272
}
7373
}
7474

util/src/main/jdk1.4/org/bouncycastle/asn1/cmp/OOBCert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static CMPCertificate getInstance(Object o)
6363
}
6464
catch (IOException e)
6565
{
66-
throw new RuntimeException(e.getMessage(), e);
66+
throw new IllegalArgumentException(e.getMessage());
6767
}
6868
}
6969

0 commit comments

Comments
 (0)