Skip to content

Commit 1c76a7d

Browse files
committed
compatibility updates
1 parent 56112ea commit 1c76a7d

File tree

7 files changed

+667
-50
lines changed

7 files changed

+667
-50
lines changed

buildj2me

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,23 @@ then
2828
((cd core/src/main/java; tar cf - * ) | (cd $target/src && tar xf -))
2929
((cd core/src/main/javadoc; tar cf - * ) | (cd $target/src && tar xf -))
3030
((cd core/src/main/jdk1.4; tar cf - * ) | (cd $target/src && tar xf -))
31+
((cd core/src/main/jdk1.3; tar cf - * ) | (cd $target/src && tar xf -))
32+
((cd core/src/main/jdk1.2; tar cf - * ) | (cd $target/src && tar xf -))
3133
((cd core/src/main/jdk1.1; tar cf - org ) | (cd $target/src && tar xf -))
3234
((cd core/src/main/j2me; tar cf - * ) | (cd $target/src && tar xf -))
3335
((cd core/src/test/java; tar cf - * ) | (cd $target/src && tar xf -))
3436
((cd core/src/test/j2me; tar cf - * ) | (cd $target/src && tar xf -))
3537
((cd util/src/main/java; tar cf - * ) | (cd $target/src && tar xf -))
38+
((cd util/src/main/jdk1.4; tar cf - * ) | (cd $target/src && tar xf -))
3639
((cd util/src/main/j2me; tar cf - * ) | (cd $target/src && tar xf -))
3740
((cd pkix/src/main/java; tar cf - * ) | (cd $target/src && tar xf -))
3841
((cd pkix/src/main/javadoc; tar cf - * ) | (cd $target/src && tar xf -))
3942
((cd pkix/src/main/j2me; tar cf - * ) | (cd $target/src && tar xf -))
4043
((cd pkix/src/test/java; tar cf - org/bouncycastle/cert/test ) | (cd $target/src && tar xf - ) )
4144
((cd pkix/src/test/j2me; tar cf - * ) | (cd $target/src && tar xf -))
4245
((cd pg/src/main/java; tar cf - * ) | (cd $target/src && tar xf -))
46+
((cd pg/src/main/jdk1.4; tar cf - * ) | (cd $target/src && tar xf -))
47+
((cd pg/src/main/jdk1.3; tar cf - * ) | (cd $target/src && tar xf -))
4348
((cd pg/src/main/javadoc; tar cf - * ) | (cd $target/src && tar xf -))
4449
((cd pg/src/main/j2me; tar cf - * ) | (cd $target/src && tar xf -))
4550
((cd pg/src/test/j2me; tar cf - * ) | (cd $target/src && tar xf -))
@@ -50,11 +55,16 @@ then
5055
rm src/org/bouncycastle/crypto/test/SHAKEDigestTest.java
5156
rm src/org/bouncycastle/crypto/test/NISTECCTest.java
5257
rm src/org/bouncycastle/crypto/test/LEATest.java
58+
rm src/org/bouncycastle/crypto/test/Grain128AEADTest.java
59+
rm src/org/bouncycastle/crypto/test/RadixConverterTest.java
60+
rm src/org/bouncycastle/crypto/test/DigestConstraintsTest.java
5361
rm src/org/bouncycastle/crypto/CryptoServicesPermission.java
62+
rm src/org/bouncycastle/crypto/constraints/LoggingConstraint.java
5463
rm src/org/bouncycastle/util/StreamParser.java
5564
rm src/org/bouncycastle/util/StreamParsingException.java
5665
rm src/org/bouncycastle/asn1/util/Dump.java
5766
rm src/org/bouncycastle/asn1/test/AllTests.java
67+
rm src/org/bouncycastle/asn1/test/MiscTest.java
5868
rm src/org/bouncycastle/asn1/test/ASN1IntegerTest.java
5969
rm src/org/bouncycastle/asn1/test/ASN1SequenceParserTest.java
6070
rm src/org/bouncycastle/asn1/test/AttributeTableUnitTest.java
@@ -80,22 +90,25 @@ then
8090
rm -rf src/org/bouncycastle/tsp/ers
8191
rm src/org/bouncycastle/crypto/util/JournaledAlgorithm.java
8292
rm -rf src/org/bouncycastle/crypto/fpe/
93+
rm -rf src/org/bouncycastle/crypto/params/FPEParameters.java
94+
rm -rf src/org/bouncycastle/crypto/util/RadixConverter.java
8395
rm -rf src/org/bouncycastle/math/ec/rfc7748/test
8496
rm -rf src/org/bouncycastle/math/ec/rfc8032/test
8597
rm -rf src/org/bouncycastle/math/raw/test
8698
rm -rf src/org/bouncycastle/math/test
87-
rm -rf src/org/bouncycastle/pqc/math/ntru
88-
rm -rf src/org/bouncycastle/pqc/crypto/test/ntru
89-
rm -rf src/org/bouncycastle/pqc/crypto/*/NTRU*
90-
rm -rf src/org/bouncycastle/pqc/crypto/*/BitStringTest*
91-
rm -rf src/org/bouncycastle/pqc/crypto/*/IndexGenerator*
99+
rm -rf src/org/bouncycastle/pqc/legacy/math/ntru
100+
rm -rf src/org/bouncycastle/pqc/crypto/ntru
101+
rm -rf src/org/bouncycastle/pqc/legacy/crypto/test/ntru
102+
rm -rf src/org/bouncycastle/pqc/legacy/crypto/*/NTRU*
103+
rm -rf src/org/bouncycastle/pqc/legacy/crypto/*/BitStringTest*
104+
rm -rf src/org/bouncycastle/pqc/legacy/crypto/*/IndexGenerator*
92105
rm -rf src/org/bouncycastle/pqc/crypto/sphincsplus
93106
rm -rf src/org/bouncycastle/pqc/crypto/xmss
94107
rm -rf src/org/bouncycastle/pqc/crypto/lms
95-
rm -rf src/org/bouncycastle/pqc/crypto/test/XMSS*
96-
rm -rf src/org/bouncycastle/pqc/crypto/test/LMS*
97-
rm -rf src/org/bouncycastle/pqc/crypto/test/HSS*
98-
rm src/org/bouncycastle/pqc/crypto/qtesla/QTeslaKeyEncodingTests.java
108+
rm -rf src/org/bouncycastle/pqc/crypto/test
109+
rm -rf src/org/bouncycastle/pqc/crypto/sike
110+
rm -rf src/org/bouncycastle/pqc/crypto/picnic
111+
rm src/org/bouncycastle/pqc/crypto/legacy/qtesla/QTeslaKeyEncodingTests.java
99112
rm -rf src/org/bouncycastle/gpg/keybox
100113
rm -rf src/org/bouncycastle/gpg/test
101114
rm src/org/bouncycastle/asn1/test/MonetaryValueUnitTest.java
@@ -132,7 +145,7 @@ then
132145
rm src/org/bouncycastle/asn1/test/OctetStringTest.java
133146
rm src/org/bouncycastle/asn1/test/ParseTest.java
134147
rm src/org/bouncycastle/crypto/test/GCMReorderTest.java
135-
rm -r src/org/bouncycastle/pqc/crypto/test
148+
rm -r src/org/bouncycastle/legacy/pqc/crypto/test
136149
rm src/org/bouncycastle/cert/test/BcCertTest.java
137150
rm src/org/bouncycastle/cert/test/GOST3410_2012CMSTest.java
138151
rm src/org/bouncycastle/crypto/test/SCryptTest.java
@@ -173,7 +186,7 @@ then
173186
rm src/org/bouncycastle/cert/test/ExternalKeyTest.java
174187
rm src/org/bouncycastle/mozilla/SignedPublicKeyAndChallenge.java
175188

176-
for i in src/org/bouncycastle/pqc/crypto/*/*.java
189+
for i in src/org/bouncycastle/pqc/crypto/*/*.java src/org/bouncycastle/pqc/crypto/*/*/*.java src/org/bouncycastle/pqc/math/*/*.java src/org/bouncycastle/pqc/math/*/*/*.java src/org/bouncycastle/crypto/engines/*.java
177190
do
178191
ed $i <<%%
179192
g/ .Override/d
@@ -182,6 +195,12 @@ q
182195
%%
183196
done
184197

198+
ed src/org/bouncycastle/asn1/test/RegressionTest.java <<%
199+
g/new MiscTest(),/s///g
200+
w
201+
q
202+
%
203+
185204
ed src/org/bouncycastle/cms/CMSSignedDataGenerator.java <<%
186205
g/LinkedHashSet/s//HashSet/g
187206
w
@@ -332,9 +351,14 @@ q
332351
org.bouncycastle.crypto.examples \
333352
org.bouncycastle.pqc.asn1 \
334353
org.bouncycastle.pqc.crypto \
335-
org.bouncycastle.pqc.crypto.rainbow \
336-
org.bouncycastle.pqc.crypto.mceliece \
337-
org.bouncycastle.pqc.crypto.gmss \
354+
org.bouncycastle.pqc.crypto.cmce \
355+
org.bouncycastle.pqc.crypto.ntruprime \
356+
org.bouncycastle.pqc.crypto.crystals.kyber \
357+
org.bouncycastle.pqc.crypto.crystals.dilithium \
358+
org.bouncycastle.pqc.crypto.falcon \
359+
org.bouncycastle.pqc.legacy.crypto.rainbow \
360+
org.bouncycastle.pqc.legacy.crypto.mceliece \
361+
org.bouncycastle.pqc.legacy.crypto.gmss \
338362
org.bouncycastle.pqc.math.linearalgebra \
339363
org.bouncycastle.util \
340364
org.bouncycastle.util.encoders \

core/src/main/j2me/org/bouncycastle/math/ec/ECCurve.java

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public ECMultiplier getMultiplier()
379379
public ECPoint decodePoint(byte[] encoded)
380380
{
381381
ECPoint p = null;
382-
int expectedLength = (getFieldSize() + 7) / 8;
382+
int expectedLength = (this.getFieldSize() + 7) / 8;
383383

384384
byte type = encoded[0];
385385
switch (type)
@@ -463,7 +463,7 @@ public ECPoint decodePoint(byte[] encoded)
463463
*/
464464
public ECLookupTable createCacheSafeLookupTable(final ECPoint[] points, int off, final int len)
465465
{
466-
final int FE_BYTES = (getFieldSize() + 7) >>> 3;
466+
final int FE_BYTES = (this.getFieldSize() + 7) >>> 3;
467467

468468
final byte[] table = new byte[len * FE_BYTES * 2];
469469
{
@@ -526,7 +526,7 @@ public ECPoint lookupVar(int index)
526526

527527
private ECPoint createPoint(byte[] x, byte[] y)
528528
{
529-
return createRawPoint(fromBigInteger(new BigInteger(1, x)), fromBigInteger(new BigInteger(1, y)));
529+
return createRawPoint(ECCurve.this.fromBigInteger(new BigInteger(1, x)), ECCurve.this.fromBigInteger(new BigInteger(1, y)));
530530
}
531531
};
532532
}
@@ -675,6 +675,7 @@ public static class Fp extends AbstractFp
675675
{
676676
private static final int FP_DEFAULT_COORDS = ECCurve.COORD_JACOBIAN_MODIFIED;
677677
private static final Set<BigInteger> knownQs = Collections.synchronizedSet(new HashSet<BigInteger>());
678+
private static final BigIntegers.Cache validatedQs = new BigIntegers.Cache();
678679

679680
BigInteger q, r;
680681
ECPoint.Fp infinity;
@@ -701,7 +702,7 @@ public Fp(BigInteger q, BigInteger a, BigInteger b, BigInteger order, BigInteger
701702
this.q = q;
702703
knownQs.add(q);
703704
}
704-
else if (knownQs.contains(q))
705+
else if (knownQs.contains(q) || validatedQs.contains(q))
705706
{
706707
this.q = q;
707708
}
@@ -722,6 +723,8 @@ else if (knownQs.contains(q))
722723
throw new IllegalArgumentException("Fp q value not prime");
723724
}
724725

726+
validatedQs.add(q);
727+
725728
this.q = q;
726729
}
727730

@@ -781,6 +784,11 @@ public int getFieldSize()
781784

782785
public ECFieldElement fromBigInteger(BigInteger x)
783786
{
787+
if (x == null || x.signum() < 0 || x.compareTo(q) >= 0)
788+
{
789+
throw new IllegalArgumentException("x value invalid for Fp field element");
790+
}
791+
784792
return new ECFieldElement.Fp(this.q, this.r, x);
785793
}
786794

@@ -837,32 +845,11 @@ public static BigInteger inverse(int m, int[] ks, BigInteger x)
837845

838846
private static FiniteField buildField(int m, int k1, int k2, int k3)
839847
{
840-
if (k1 == 0)
841-
{
842-
throw new IllegalArgumentException("k1 must be > 0");
843-
}
844-
845-
if (k2 == 0)
846-
{
847-
if (k3 != 0)
848-
{
849-
throw new IllegalArgumentException("k3 must be 0 if k2 == 0");
850-
}
851-
852-
return FiniteFields.getBinaryExtensionField(new int[]{ 0, k1, m });
853-
}
848+
int[] exponents = (k2 | k3) == 0
849+
? new int[]{ 0, k1, m }
850+
: new int[]{ 0, k1, k2, k3, m };
854851

855-
if (k2 <= k1)
856-
{
857-
throw new IllegalArgumentException("k2 must be > k1");
858-
}
859-
860-
if (k3 <= k2)
861-
{
862-
throw new IllegalArgumentException("k3 must be > k2");
863-
}
864-
865-
return FiniteFields.getBinaryExtensionField(new int[]{ 0, k1, k2, k3, m });
852+
return FiniteFields.getBinaryExtensionField(exponents);
866853
}
867854

868855
protected AbstractF2m(int m, int k1, int k2, int k3)
@@ -1258,8 +1245,8 @@ public F2m(
12581245
this.cofactor = cofactor;
12591246

12601247
this.infinity = new ECPoint.F2m(this, null, null);
1261-
this.a = this.fromBigInteger(a);
1262-
this.b = this.fromBigInteger(b);
1248+
this.a = fromBigInteger(a);
1249+
this.b = fromBigInteger(b);
12631250
this.coord = F2M_DEFAULT_COORDS;
12641251
}
12651252

@@ -1315,7 +1302,16 @@ public int getFieldSize()
13151302

13161303
public ECFieldElement fromBigInteger(BigInteger x)
13171304
{
1318-
return new ECFieldElement.F2m(this.m, this.k1, this.k2, this.k3, x);
1305+
if (x == null || x.signum() < 0 || x.bitLength() > m)
1306+
{
1307+
throw new IllegalArgumentException("x value invalid in F2m field element");
1308+
}
1309+
1310+
int[] ks = (k2 | k3) == 0
1311+
? new int[]{ k1 }
1312+
: new int[]{ k1, k2, k3 };
1313+
1314+
return new ECFieldElement.F2m(m, ks, new LongArray(x));
13191315
}
13201316

13211317
protected ECPoint createRawPoint(ECFieldElement x, ECFieldElement y)

pg/src/main/j2me/org/bouncycastle/bcpg/BCPGInputStream.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ public BCPGInputStream(
2525
this.in = in;
2626
}
2727

28+
/**
29+
* If the argument is a {@link BCPGInputStream}, return it.
30+
* Otherwise wrap it in a {@link BCPGInputStream} and then return the result.
31+
*
32+
* @param in input stream
33+
* @return BCPGInputStream
34+
*/
35+
public static BCPGInputStream wrap(InputStream in)
36+
{
37+
if (in instanceof BCPGInputStream)
38+
{
39+
return (BCPGInputStream)in;
40+
}
41+
return new BCPGInputStream(in);
42+
}
43+
2844
public int available()
2945
throws IOException
3046
{

0 commit comments

Comments
 (0)