Skip to content

Commit 3b40be3

Browse files
committed
J2ME changes
1 parent 3b4c9bc commit 3b40be3

File tree

5 files changed

+150
-8
lines changed

5 files changed

+150
-8
lines changed

buildj2me

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ then
8383
rm -rf src/org/bouncycastle/pqc/crypto/*/BitStringTest*
8484
rm -rf src/org/bouncycastle/pqc/crypto/*/IndexGenerator*
8585
rm -rf src/org/bouncycastle/pqc/crypto/xmss
86+
rm -rf src/org/bouncycastle/pqc/crypto/lms
8687
rm -rf src/org/bouncycastle/pqc/crypto/test/XMSS*
88+
rm -rf src/org/bouncycastle/pqc/crypto/test/LMS*
89+
rm -rf src/org/bouncycastle/pqc/crypto/test/HSS*
8790
rm src/org/bouncycastle/pqc/crypto/qtesla/QTeslaKeyEncodingTests.java
8891
rm -rf src/org/bouncycastle/gpg/keybox
8992
rm -rf src/org/bouncycastle/gpg/test

core/src/main/j2me/org/bouncycastle/asn1/StreamUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static int findLimit(InputStream in)
1616
{
1717
if (in instanceof LimitedInputStream)
1818
{
19-
return ((LimitedInputStream)in).getRemaining();
19+
return ((LimitedInputStream)in).getLimit();
2020
}
2121
else if (in instanceof ASN1InputStream)
2222
{
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package org.bouncycastle.crypto.macs;
2+
3+
import org.bouncycastle.crypto.DataLengthException;
4+
import org.bouncycastle.util.Pack;
5+
6+
/**
7+
* Implementation of SipHash with 128 bit output.
8+
* <p>
9+
* Based on the {@link SipHash} and the C reference implementation
10+
* https://github.com/veorq/SipHash.
11+
*
12+
*/
13+
public class SipHash128
14+
extends SipHash
15+
{
16+
17+
/**
18+
* SipHash128-2-4
19+
*/
20+
public SipHash128()
21+
{
22+
super();
23+
}
24+
25+
/**
26+
* SipHash128-c-d
27+
*
28+
* @param c the number of compression rounds
29+
* @param d the number of finalization rounds
30+
*/
31+
public SipHash128(int c, int d)
32+
{
33+
super(c, d);
34+
}
35+
36+
public String getAlgorithmName()
37+
{
38+
return "SipHash128-" + c + "-" + d;
39+
}
40+
41+
public int getMacSize()
42+
{
43+
return 16;
44+
}
45+
46+
public long doFinal()
47+
throws DataLengthException, IllegalStateException {
48+
throw new IllegalStateException("doFinal() is not supported");
49+
}
50+
51+
public int doFinal(byte[] out, int outOff)
52+
throws DataLengthException, IllegalStateException
53+
{
54+
// NOTE: 2 distinct shifts to avoid "64-bit shift" when wordPos == 0
55+
m >>>= ((7 - wordPos) << 3);
56+
m >>>= 8;
57+
m |= (((wordCount << 3) + wordPos) & 0xffL) << 56;
58+
59+
processMessageWord();
60+
61+
v2 ^= 0xeeL;
62+
63+
applySipRounds(d);
64+
65+
long r0 = v0 ^ v1 ^ v2 ^ v3;
66+
67+
v1 ^= 0xddL;
68+
applySipRounds(d);
69+
70+
long r1 = v0 ^ v1 ^ v2 ^ v3;
71+
72+
reset();
73+
74+
Pack.longToLittleEndian(r0, out, outOff);
75+
Pack.longToLittleEndian(r1, out, outOff + 8);
76+
return 16;
77+
}
78+
79+
public void reset()
80+
{
81+
super.reset();
82+
v1 ^= 0xeeL;
83+
}
84+
85+
}
Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,67 @@
11
package org.bouncycastle.util;
22

3+
import java.math.BigInteger;
4+
import java.util.Collections;
5+
import java.util.HashMap;
6+
import java.util.HashSet;
7+
import java.util.Map;
8+
import java.util.Set;
9+
import java.util.StringTokenizer;
10+
311
/**
412
* Utility method for accessing system properties.
513
*/
614
public class Properties
715
{
8-
public static boolean isOverrideSet(final String propertyName)
16+
private Properties()
17+
{
18+
}
19+
20+
/**
21+
* Return whether a particular override has been set to true.
22+
*
23+
* @param propertyName the property name for the override.
24+
* @return true if the property is set to "true", false otherwise.
25+
*/
26+
public static boolean isOverrideSet(String propertyName)
27+
{
28+
String p = getPropertyValue(propertyName);
29+
30+
return "true".equalsIgnoreCase(p);
31+
}
32+
33+
public static BigInteger asBigInteger(String propertyName)
34+
{
35+
String p = getPropertyValue(propertyName);
36+
37+
if (p != null)
38+
{
39+
return new BigInteger(p);
40+
}
41+
42+
return null;
43+
}
44+
45+
public static Set<String> asKeySet(String propertyName)
946
{
10-
String value = System.getProperty(propertyName);
11-
if (value == null)
12-
{
13-
return false;
14-
}
47+
Set<String> set = new HashSet<String>();
48+
49+
String p = getPropertyValue(propertyName);
1550

16-
return "true".equals(Strings.toLowerCase(value));
51+
if (p != null)
52+
{
53+
StringTokenizer sTok = new StringTokenizer(p, ",");
54+
while (sTok.hasMoreElements())
55+
{
56+
set.add(Strings.toLowerCase(sTok.nextToken()).trim());
57+
}
58+
}
59+
60+
return Collections.unmodifiableSet(set);
61+
}
62+
63+
public static String getPropertyValue(final String propertyName)
64+
{
65+
return System.getProperty(propertyName);
1766
}
1867
}

core/src/main/j2me/org/bouncycastle/util/test/SimpleTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ protected boolean areEqual(
128128
{
129129
return Arrays.areEqual(a, b);
130130
}
131+
132+
protected boolean areEqual(byte[] a, int aFromIndex, int aToIndex, byte[] b, int bFromIndex, int bToIndex)
133+
{
134+
return Arrays.areEqual(a, aFromIndex, aToIndex, b, bFromIndex, bToIndex);
135+
}
131136

132137
public TestResult perform()
133138
{

0 commit comments

Comments
 (0)