Skip to content

Commit

Permalink
Java 1.1 Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Apr 8, 2024
1 parent 5b13608 commit 30c6cc6
Show file tree
Hide file tree
Showing 7 changed files with 604 additions and 3 deletions.
35 changes: 32 additions & 3 deletions build1-1
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ mkdir -p $jdk11src
((cd pkix/src/main/java && tar cf - * ) | (cd $jdk11src && tar xf -))
((cd pkix/src/main/javadoc && tar cf - * ) | (cd $jdk11src && tar xf -))
((cd pkix/src/test/java && tar cf - * ) | (cd $jdk11src && tar xf -))
((cd pg/src/main/jdk1.5 && tar cf - * ) | (cd $jdk11src && tar xf -))
((cd pg/src/main/jdk1.4 && tar cf - * ) | (cd $jdk11src && tar xf -))
((cd pg/src/main/jdk1.3 && tar cf - * ) | (cd $jdk11src && tar xf -))
((cd pg/src/main/jdk1.1 && tar cf - * ) | (cd $jdk11src && tar xf -))
((cd pkix/src/main/jdk1.4 && tar cf - * ) | (cd $jdk11src && tar xf -))
((cd pkix/src/test/jdk1.4 && tar cf - * ) | (cd $jdk11src && tar xf -))
((cd pkix/src/main/jdk1.3 && tar cf - * ) | (cd $jdk11src && tar xf -))
Expand Down Expand Up @@ -234,6 +238,12 @@ find $jdk11src -name "*.java" -exec scripts/useseccert.sh \{\} \;
rm -rf org/bouncycastle/pkcs/test
rm -rf org/bouncycastle/eac/test
rm -rf org/bouncycastle/cms/test
rm -r org/bouncycastle/jcajce/provider/asymmetric/compositesignatures
rm -r org/bouncycastle/jcajce/provider/asymmetric/CompositeSignatures.java
rm org/bouncycastle/pqc/crypto/test/XWingTest.java
rm org/bouncycastle/cert/test/GOSTR3410_2012_256GenerateCertificate.java
rm org/bouncycastle/cert/cmp/test/InvalidMessagesTest.java
rm org/bouncycastle/test/JVMVersionTest.java
rm org/bouncycastle/cms/jcajce/JceAADStream.java
rm org/bouncycastle/cms/jcajce/JceCMSKEM*.java
rm org/bouncycastle/cms/jcajce/JceKEM*.java
Expand Down Expand Up @@ -295,7 +305,11 @@ find $jdk11src -name "*.java" -exec scripts/useseccert.sh \{\} \;
rm -f org/bouncycastle/jcajce/provider/asymmetric/NTRU.java
rm -f org/bouncycastle/jcajce/provider/asymmetric/Falcon.java
rm -f org/bouncycastle/test/PrintTestResult.java
rm org/bouncycastle/openpgp/test/PGPAeadTest.java
rm -f org/bouncycastle/openpgp/test/PGPAeadTest.java
rm -f org/bouncycastle/openpgp/test/BytesBooleansTest.java
rm -f org/bouncycastle/openpgp/test/BcImplProviderTest.java
rm -f org/bouncycastle/openpgp/test/BcpgGeneralTest.java
rm -f org/bouncycastle/openpgp/test/OpenPGPTest.java

sh ../../scripts/jdk1.2ed.sh > /dev/null 2>&1
sh ../../scripts/jdk1.1ed.sh > /dev/null 2>&1
Expand Down Expand Up @@ -640,6 +654,7 @@ then
mkdir $artifacts/bcpg-jdk11-$base/src
tar cf - index.html LICENSE.html CONTRIBUTORS.html docs | (cd $artifacts/bcpg-jdk11-$base; tar xf -)
((cd pg/src/main/java && tar cf - * ) | (cd $artifacts/bcpg-jdk11-$base/src && tar xf -))
((cd pg/src/main/jdk1.5 && tar cf - * ) | (cd $artifacts/bcpg-jdk11-$base/src && tar xf -))
((cd pg/src/main/jdk1.4 && tar cf - * ) | (cd $artifacts/bcpg-jdk11-$base/src && tar xf -))
((cd pg/src/main/jdk1.3 && tar cf - * ) | (cd $artifacts/bcpg-jdk11-$base/src && tar xf -))
((cd pg/src/main/jdk1.1 && tar cf - * ) | (cd $artifacts/bcpg-jdk11-$base/src && tar xf -))
Expand Down Expand Up @@ -683,6 +698,12 @@ then
rm -f src/org/bouncycastle/openpgp/examples/DSAElGamalKeyRingGenerator.java
rm -f src/org/bouncycastle/openpgp/examples/EllipticCurveKeyPairGenerator.java
rm src/org/bouncycastle/openpgp/test/PGPAeadTest.java
rm -f src/org/bouncycastle/openpgp/test/BytesBooleansTest.java
rm -f src/org/bouncycastle/openpgp/test/BcImplProviderTest.java
rm -f src/org/bouncycastle/openpgp/test/BcpgGeneralTest.java
rm -f src/org/bouncycastle/openpgp/test/OpenPGPTest.java
rm -f src/org/bouncycastle/openpgp/test/OperatorBcTest.java
rm -f src/org/bouncycastle/openpgp/test/PGPGeneralTest.java

find src -name AllTests.java -exec rm {} \;

Expand Down Expand Up @@ -797,8 +818,16 @@ w
q
%

(cd src/org/bouncycastle; javac -d ../../../classes -classpath ../../../classes:../../../src:../../../../jce-jdk11-$base/classes:$JDK11PATH/lib/classes.zip bcpg/*.java bcpg/*/*.java openpgp/*.java )
(cd src/org/bouncycastle; javac -d ../../../classes -classpath ../../../classes:../../../src:../../../../jce-jdk11-$base/classes:$JDK11PATH/lib/classes.zip openpgp/*/*.java openpgp/*/*/*.java )
ed src/org/bouncycastle/openpgp/operator/bc/BcPublicKeyDataDecryptorFactory.java <<%
g/private.*final.*;/s/final//
w
q
%

(cd src/org/bouncycastle; javac -d ../../../classes -classpath ../../../classes:../../../src:../../../../jce-jdk11-$base/classes:$JDK11PATH/lib/classes.zip bcpg/*.java )
(cd src/org/bouncycastle; javac -d ../../../classes -classpath ../../../classes:../../../src:../../../../jce-jdk11-$base/classes:$JDK11PATH/lib/classes.zip bcpg/*/*.java openpgp/*.java )
(cd src/org/bouncycastle; javac -d ../../../classes -classpath ../../../classes:../../../src:../../../../jce-jdk11-$base/classes:$JDK11PATH/lib/classes.zip openpgp/*/*.java )
(cd src/org/bouncycastle; javac -d ../../../classes -classpath ../../../classes:../../../src:../../../../jce-jdk11-$base/classes:$JDK11PATH/lib/classes.zip openpgp/*/*/*.java )
(cd src/org/bouncycastle; javac -d ../../../classes -classpath ../../../classes:../../../src:../../../../jce-jdk11-$base/classes:$JDK11PATH/lib/classes.zip openpgp/test/RegressionTest.java )

cp ../../../../pg/src/test/resources/org/bouncycastle/openpgp/test/bigpub.asc classes/org/bouncycastle/openpgp/test/bigpub.asc
Expand Down
45 changes: 45 additions & 0 deletions core/src/main/jdk1.1/org/bouncycastle/util/BigIntegers.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,51 @@ private static byte[] createRandom(int bitLength, SecureRandom random)
return rv;
}

public static boolean modOddIsCoprime(BigInteger M, BigInteger X)
{
if (!M.testBit(0))
{
throw new IllegalArgumentException("'M' must be odd");
}
if (M.signum() != 1)
{
throw new ArithmeticException("BigInteger: modulus not positive");
}
if (X.signum() < 0 || X.bitLength() > M.bitLength())
{
X = X.mod(M);
}

int bits = M.bitLength();
int[] m = Nat.fromBigInteger(bits, M);
int[] x = Nat.fromBigInteger(bits, X);
return 0 != Mod.modOddIsCoprime(m, x);
}

public static boolean modOddIsCoprimeVar(BigInteger M, BigInteger X)
{
if (!M.testBit(0))
{
throw new IllegalArgumentException("'M' must be odd");
}
if (M.signum() != 1)
{
throw new ArithmeticException("BigInteger: modulus not positive");
}
if (X.signum() < 0 || X.bitLength() > M.bitLength())
{
X = X.mod(M);
}
if (X.equals(ONE))
{
return true;
}

int bits = M.bitLength();
int[] m = Nat.fromBigInteger(bits, M);
int[] x = Nat.fromBigInteger(bits, X);
return Mod.modOddIsCoprimeVar(m, x);
}
public static class Cache
{
private final Map values = new HashMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.bouncycastle.openpgp.operator.jcajce;

import java.io.IOException;
import java.math.BigInteger;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.Key;
import java.security.PublicKey;
import java.security.spec.AlgorithmParameterSpec;

import javax.crypto.KeyAgreement;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.x9.ECNamedCurveTable;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.bcpg.PublicKeyPacket;
import org.bouncycastle.crypto.ec.CustomNamedCurves;
import org.bouncycastle.jcajce.spec.HybridValueParameterSpec;
import org.bouncycastle.jcajce.spec.UserKeyingMaterialSpec;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECPoint;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.BigIntegers;
import org.bouncycastle.util.Strings;

/**
* Basic utility class
*/
class JcaJcePGPUtil
{
public static SecretKey makeSymmetricKey(
int algorithm,
byte[] keyBytes)
throws PGPException
{
String algName = org.bouncycastle.openpgp.PGPUtil.getSymmetricCipherName(algorithm);

if (algName == null)
{
throw new PGPException("unknown symmetric algorithm: " + algorithm);
}

return new SecretKeySpec(keyBytes, algName);
}

static ECPoint decodePoint(
BigInteger encodedPoint,
ECCurve curve)
throws IOException
{
return curve.decodePoint(BigIntegers.asUnsignedByteArray(encodedPoint));
}

static X9ECParameters getX9Parameters(ASN1ObjectIdentifier curveOID)
{
X9ECParameters x9Params = CustomNamedCurves.getByOID(curveOID);

if (x9Params == null)
{
return ECNamedCurveTable.getByOID(curveOID);
}

return x9Params;
}

static HybridValueParameterSpec getHybridValueParameterSpecWithPrepend(byte[] ephmeralPublicKey, PublicKeyPacket pkp, String algorithmName)
throws IOException
{
return new HybridValueParameterSpec(Arrays.concatenate(ephmeralPublicKey, pkp.getEncoded()), true, new UserKeyingMaterialSpec(Strings.toByteArray("OpenPGP " + algorithmName)));
}

static Key getSecret(OperatorHelper helper, PublicKey cryptoPublicKey, String keyEncryptionOID, String agreementName, AlgorithmParameterSpec ukmSpec, Key privKey)
throws GeneralSecurityException
{
try
{
KeyAgreement agreement = helper.createKeyAgreement(agreementName);
agreement.init(privKey, ukmSpec);
agreement.doPhase(cryptoPublicKey, true);
return agreement.generateSecret(keyEncryptionOID);
}
catch (InvalidKeyException e)
{
throw new GeneralSecurityException(e.toString());
}
catch (NoSuchAlgorithmException e)
{
throw new GeneralSecurityException(e.toString());
}
}
}
Loading

0 comments on commit 30c6cc6

Please sign in to comment.