Skip to content

Commit 327e037

Browse files
committed
1.1/1.2 compatibility updates
1 parent 9184f1b commit 327e037

File tree

9 files changed

+630
-6
lines changed

9 files changed

+630
-6
lines changed

build1-1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ find $jdk11src -name "*.java" -exec scripts/useseccert.sh \{\} \;
105105
rm -rf org/bouncycastle/crypto/CryptoServicesPermission.java
106106
rm -rf org/bouncycastle/crypto/tls/test
107107
rm -rf org/bouncycastle/crypto/digests/Blake3Digest.java
108+
rm -rf org/bouncycastle/jcajce/provider/digest/Blake3.java
109+
rm -rf org/bouncycastle/jcajce/provider/asymmetric/SPHINCSPlus.java
108110
rm -rf org/bouncycastle/crypto/macs/Blake3Mac.java
109111
rm -rf org/bouncycastle/crypto/test/Blake3Test.java
110112
rm -rf org/bouncycastle/crypto/test/SimpleTestTest.java
@@ -122,6 +124,7 @@ find $jdk11src -name "*.java" -exec scripts/useseccert.sh \{\} \;
122124
rm -rf org/bouncycastle/jcajce/provider/asymmetric/EdEC.java
123125
rm -rf org/bouncycastle/jcajce/provider/config/ProviderConfigurationPermission.java
124126
rm -rf org/bouncycastle/jcajce/provider/test
127+
rm -rf org/bouncycastle/asn1/misc/test/CMPUpdates16Test.java
125128
rm org/bouncycastle/jcajce/BCFKSStoreParameter.java
126129
rm -rf org/bouncycastle/jce/provider/test/ECDSA5Test.java
127130
rm -rf org/bouncycastle/jce/provider/test/CRL5Test.java
@@ -220,11 +223,15 @@ find $jdk11src -name "*.java" -exec scripts/useseccert.sh \{\} \;
220223
rm -rf org/bouncycastle/cms/test
221224
rm org/bouncycastle/cms/jcajce/JceAADStream.java
222225
rm org/bouncycastle/jcajce/provider/keystore/util/ParameterUtil.java
226+
rm -rf org/bouncycastle/pqc/crypto/*/CMCEVectorTest*
227+
rm -rf org/bouncycastle/pqc/crypto/*/FrodoVectorTest*
228+
rm -rf org/bouncycastle/pqc/crypto/*/SABERVectorTest*
223229
rm -rf org/bouncycastle/pkix/jcajce/X509*
224230
rm -rf org/bouncycastle/pkix/jcajce/RFC3280*
225231
rm -rf org/bouncycastle/pkix/jcajce/Revocation*
226232
rm -rf org/bouncycastle/pkix/test/Revocation*
227233
rm -rf org/bouncycastle/pkix/test/TestUtil*
234+
rm org/bouncycastle/pkix/test/CheckerTest.java
228235
rm org/bouncycastle/cms/jcajce/JceKeyTransAuthEnvelopedRecipient.java
229236
rm -rf org/bouncycastle/mime/
230237
rm -rf org/bouncycastle/its/
@@ -357,6 +364,7 @@ javac -d ../../../classes -classpath ../../../classes:../../../src:$JDK11PATH/li
357364
javac -d ../../../classes -classpath ../../../classes:../../../src:$JDK11PATH/lib/classes.zip util/io/*/*.java
358365
javac -d ../../../classes -classpath ../../../classes:../../../src:$JDK11PATH/lib/classes.zip pqc/math/*/*.java
359366
javac -d ../../../classes -classpath ../../../classes:../../../src:$JDK11PATH/lib/classes.zip pqc/crypto/*/*.java pqc/crypto/*/*/*.java
367+
javac -d ../../../classes -classpath ../../../classes:../../../src:$JDK11PATH/lib/classes.zip pqc/crypto/en*/*.java
360368
javac -d ../../../classes -classpath ../../../classes:../../../src:$JDK11PATH/lib/classes.zip */u*/*.java )
361369

362370
cp ../../../../core/src/test/resources/org/bouncycastle/crypto/test/*.txt classes/org/bouncycastle/crypto/test/
@@ -597,6 +605,7 @@ then
597605
PATH=$JDK11PATH/bin:$PATH
598606
export PATH
599607

608+
600609
rm -rf src/java
601610
rm -rf src/org/bouncycastle/jce
602611
rm -rf src/org/bouncycastle/ocsp
@@ -619,6 +628,7 @@ then
619628
rm -f src/org/bouncycastle/openpgp/test/DSA2Test.java
620629
rm -f src/org/bouncycastle/openpgp/test/PGPUnicodeTest.java
621630
rm -f src/org/bouncycastle/openpgp/test/BcPGPEd25519JcaKeyPairConversionTest.java
631+
rm src/org/bouncycastle/openpgp/test/ArmoredOutputStreamUTF8Test.java
622632
rm -f src/org/bouncycastle/openpgp/examples/DSAElGamalKeyRingGenerator.java
623633

624634
find src -name AllTests.java -exec rm {} \;
@@ -639,6 +649,15 @@ then
639649
echo "compiling"
640650

641651

652+
for i in src/org/bouncycastle/pqc/jcajce/provider/*/*.java src/org/bouncycastle/pqc/crypto/*/*.java src/org/bouncycastle/openpgp/test/*.java
653+
do
654+
ed $i <<%%
655+
g/.Override/d
656+
w
657+
q
658+
%%
659+
done
660+
642661
ed src/org/bouncycastle/gpg/SExpression.java <<%
643662
g/\.\.\. /s//[]/
644663
w

build1-2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,17 @@ find $jdk12src -name "*.java" -exec scripts/usejcecert.sh \{\} \;
7878
rm -rf org/bouncycastle/pqc/crypto/*/HSS*
7979
rm -rf org/bouncycastle/pqc/crypto/*/EncryptionKey*
8080
rm -rf org/bouncycastle/pqc/crypto/*/BitStringT*
81+
rm -rf org/bouncycastle/pqc/crypto/*/CMCEVectorTest*
82+
rm -rf org/bouncycastle/pqc/crypto/*/FrodoVectorTest*
83+
rm -rf org/bouncycastle/pqc/crypto/*/SABERVectorTest*
8184
rm org/bouncycastle/pqc/jcajce/spec/LMS*
8285
rm -rf org/bouncycastle/crypto/*/test
8386
rm -rf org/bouncycastle/crypto/*/IndexGenerator*
8487
rm -rf org/bouncycastle/crypto/test/SimpleTestTest.java
8588
rm -rf org/bouncycastle/util/utiltest
8689
rm -rf org/bouncycastle/mail
8790
rm -rf org/bouncycastle/mime
91+
rm org/bouncycastle/pkix/test/CheckerTest.java
8892
rm org/bouncycastle/pkix/jcajce/Revocation*.java
8993
rm org/bouncycastle/pkix/jcajce/X509RevocationChecker.java
9094
rm org/bouncycastle/pkix/jcajce/RFC3280*.java
@@ -184,6 +188,7 @@ find $jdk12src -name "*.java" -exec scripts/usejcecert.sh \{\} \;
184188
rm -rf org/bouncycastle/tsp/GenTimeAccuracyUnit*
185189
rm -rf org/bouncycastle/tsp/TimeStampTokenInfoUnit*
186190
rm org/bouncycastle/openpgp/test/BcPGPEd25519JcaKeyPairConversionTest.java
191+
rm org/bouncycastle/openpgp/test/ArmoredOutputStreamUTF8Test.java
187192

188193
sh ../../scripts/jdk1.2ed.sh
189194

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package org.bouncycastle.crypto.params;
2+
3+
import java.math.BigInteger;
4+
5+
import org.bouncycastle.crypto.CryptoServicesRegistrar;
6+
import org.bouncycastle.math.Primes;
7+
import org.bouncycastle.util.BigIntegers;
8+
import org.bouncycastle.util.Properties;
9+
10+
public class RSAKeyParameters
11+
extends AsymmetricKeyParameter
12+
{
13+
// Hexadecimal value of the product of the 131 smallest odd primes from 3 to 743
14+
private static final BigInteger SMALL_PRIMES_PRODUCT = new BigInteger(
15+
"8138e8a0fcf3a4e84a771d40fd305d7f4aa59306d7251de54d98af8fe95729a1f"
16+
+ "73d893fa424cd2edc8636a6c3285e022b0e3866a565ae8108eed8591cd4fe8d2"
17+
+ "ce86165a978d719ebf647f362d33fca29cd179fb42401cbaf3df0c614056f9c8"
18+
+ "f3cfd51e474afb6bc6974f78db8aba8e9e517fded658591ab7502bd41849462f",
19+
16);
20+
21+
private static final BigInteger ONE = BigInteger.valueOf(1);
22+
23+
private BigInteger modulus;
24+
private BigInteger exponent;
25+
26+
public RSAKeyParameters(
27+
boolean isPrivate,
28+
BigInteger modulus,
29+
BigInteger exponent)
30+
{
31+
this(isPrivate, modulus, exponent, false);
32+
}
33+
34+
public RSAKeyParameters(
35+
boolean isPrivate,
36+
BigInteger modulus,
37+
BigInteger exponent,
38+
boolean isInternal)
39+
{
40+
super(isPrivate);
41+
42+
if (!isPrivate)
43+
{
44+
if ((exponent.intValue() & 1) == 0)
45+
{
46+
throw new IllegalArgumentException("RSA publicExponent is even");
47+
}
48+
}
49+
50+
// only check public keys
51+
this.modulus = isPrivate ? modulus : validate(modulus, isInternal);
52+
this.exponent = exponent;
53+
}
54+
55+
private BigInteger validate(BigInteger modulus, boolean isInternal)
56+
{
57+
if (isInternal)
58+
{
59+
return modulus;
60+
}
61+
62+
if ((modulus.intValue() & 1) == 0)
63+
{
64+
throw new IllegalArgumentException("RSA modulus is even");
65+
}
66+
67+
// If you need to set this you need to have a serious word to whoever is generating
68+
// your keys.
69+
if (Properties.isOverrideSet("org.bouncycastle.rsa.allow_unsafe_mod"))
70+
{
71+
return modulus;
72+
}
73+
74+
int maxBitLength = Properties.asInteger("org.bouncycastle.rsa.max_size", 15360);
75+
76+
int modBitLength = modulus.bitLength();
77+
if (maxBitLength < modBitLength)
78+
{
79+
throw new IllegalArgumentException("modulus value out of range");
80+
}
81+
82+
if (!modulus.gcd(SMALL_PRIMES_PRODUCT).equals(ONE))
83+
{
84+
throw new IllegalArgumentException("RSA modulus has a small prime factor");
85+
}
86+
87+
int bits = modulus.bitLength() / 2;
88+
int iterations = bits >= 1536 ? 3
89+
: bits >= 1024 ? 4
90+
: bits >= 512 ? 7
91+
: 50;
92+
93+
Primes.MROutput mr = Primes.enhancedMRProbablePrimeTest(modulus, CryptoServicesRegistrar.getSecureRandom(), iterations);
94+
if (!mr.isProvablyComposite())
95+
{
96+
throw new IllegalArgumentException("RSA modulus is not composite");
97+
}
98+
99+
//validated.add(modulus);
100+
101+
return modulus;
102+
}
103+
104+
public BigInteger getModulus()
105+
{
106+
return modulus;
107+
}
108+
109+
public BigInteger getExponent()
110+
{
111+
return exponent;
112+
}
113+
}

0 commit comments

Comments
 (0)