Skip to content

Commit

Permalink
compatibility updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Jul 21, 2014
1 parent e1218a0 commit 11d8fde
Show file tree
Hide file tree
Showing 31 changed files with 4,568 additions and 5,662 deletions.
581 changes: 581 additions & 0 deletions build1-1

Large diffs are not rendered by default.

528 changes: 528 additions & 0 deletions build1-2

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions build1-3
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh -
#
# build script for 1.3
#
# If it's given a buildname it creates a subdirectory and places a build in it,
# otherwise it just creates the docs and class files.
#

JDKPATH=/opt/jdk1.3.1 # JDK 1.3 location
XALAN_HOME=../apache/xalan-j_2_7_0
W3C_HOME=../w3c

JAVA_HOME=$JDKPATH
export JAVA_HOME

PATH=$JDKPATH/bin:$PATH
export PATH

CLASSPATH=$JAVA_MAIL_HOME/mail.jar:$JAVA_ACTIVATION_HOME/activation.jar:$W3C_HOME/w3c.jar:$XALAN_HOME/serializer.jar:$XALAN_HOME/xalan.jar:$XALAN_HOME/xercesImpl.jar:$XALAN_HOME/xml-apis.jar:$XALAN_HOME/xsltc.jar:$CLASSPATH
export CLASSPATH

if [ "$1" = "test" ]
then
ant -f ant/jdk13.xml test
else
if [ "$1" = "provider" ]
then
ant -f ant/jdk13.xml build-provider
ant -f ant/jdk13.xml zip-src-provider
else
if ant -f ant/jdk13.xml build-jce
then
ant -f ant/jdk13.xml build
ant -f ant/jdk13.xml zip-src
fi
fi
fi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class SHA512tDigest
extends LongDigest
{
private final int digestLength;
private int digestLength; // non-final due to old flow analyser.

private long H1t, H2t, H3t, H4t, H5t, H6t, H7t, H8t;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,9 @@ protected SecureRandom initSecureRandom(boolean needed, SecureRandom provided)
/**
* CS exception for wrong cipher-texts
*/
public class CramerShoupCiphertextException
public static class CramerShoupCiphertextException
extends Exception
{

private static final long serialVersionUID = -6360977166495345076L;

public CramerShoupCiphertextException(String msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,105 +8,116 @@
import org.bouncycastle.crypto.params.DHParameters;
import org.bouncycastle.util.BigIntegers;

public class CramerShoupParametersGenerator {

private int size;
private int certainty;
private SecureRandom random;

/**
* Initialise the parameters generator.
*
* @param size
* bit length for the prime p
* @param certainty
* a measure of the uncertainty that the caller is willing to tolerate:
* the probability that the generated modulus is prime exceeds (1 - 1/2^certainty).
* The execution time of this method is proportional to the value of this parameter.
* @param random
* a source of randomness
*/
public void init(int size, int certainty, SecureRandom random) {
this.size = size;
this.certainty = certainty;
this.random = random;
}

/**
* which generates the p and g values from the given parameters, returning
* the CramerShoupParameters object.
* <p>
* Note: can take a while...
*/
public CramerShoupParameters generateParameters() {
//
// find a safe prime p where p = 2*q + 1, where p and q are prime.
//
BigInteger[] safePrimes = ParametersHelper.generateSafePrimes(size, certainty, random);
public class CramerShoupParametersGenerator
{
private static final BigInteger ONE = BigInteger.valueOf(1);

private int size;
private int certainty;
private SecureRandom random;

/**
* Initialise the parameters generator.
*
* @param size bit length for the prime p
* @param certainty a measure of the uncertainty that the caller is willing to tolerate:
* the probability that the generated modulus is prime exceeds (1 - 1/2^certainty).
* The execution time of this method is proportional to the value of this parameter.
* @param random a source of randomness
*/
public void init(int size, int certainty, SecureRandom random)
{
this.size = size;
this.certainty = certainty;
this.random = random;
}

/**
* which generates the p and g values from the given parameters, returning
* the CramerShoupParameters object.
* <p/>
* Note: can take a while...
*/
public CramerShoupParameters generateParameters()
{
//
// find a safe prime p where p = 2*q + 1, where p and q are prime.
//
BigInteger[] safePrimes = ParametersHelper.generateSafePrimes(size, certainty, random);

// BigInteger p = safePrimes[0];
BigInteger q = safePrimes[1];
BigInteger g1 = ParametersHelper.selectGenerator(q, random);
BigInteger g2 = ParametersHelper.selectGenerator(q, random);
while(g1.equals(g2)){
g2 = ParametersHelper.selectGenerator(q, random);
}

return new CramerShoupParameters(q, g1, g2, new SHA256Digest());
}

public CramerShoupParameters generateParameters(DHParameters dhParams){
BigInteger p = dhParams.getP();
BigInteger g1 = dhParams.getG();

// now we just need a second generator
BigInteger g2 = ParametersHelper.selectGenerator(p, random);
while(g1.equals(g2)){
g2 = ParametersHelper.selectGenerator(p, random);
}

return new CramerShoupParameters(p, g1, g2, new SHA256Digest());
}

private static class ParametersHelper {

private static final BigInteger TWO = BigInteger.valueOf(2);

/*
* Finds a pair of prime BigInteger's {p, q: p = 2q + 1}
*
* (see: Handbook of Applied Cryptography 4.86)
*/
static BigInteger[] generateSafePrimes(int size, int certainty, SecureRandom random) {
BigInteger p, q;
int qLength = size - 1;

for (;;) {
q = new BigInteger(qLength, 2, random);
p = q.shiftLeft(1).add(BigInteger.ONE);
if (p.isProbablePrime(certainty) && (certainty <= 2 || q.isProbablePrime(certainty))) {
break;
}
}

return new BigInteger[] { p, q };
}

static BigInteger selectGenerator(BigInteger p, SecureRandom random) {
BigInteger pMinusTwo = p.subtract(TWO);
BigInteger g;
BigInteger q = safePrimes[1];
BigInteger g1 = ParametersHelper.selectGenerator(q, random);
BigInteger g2 = ParametersHelper.selectGenerator(q, random);
while (g1.equals(g2))
{
g2 = ParametersHelper.selectGenerator(q, random);
}

return new CramerShoupParameters(q, g1, g2, new SHA256Digest());
}

public CramerShoupParameters generateParameters(DHParameters dhParams)
{
BigInteger p = dhParams.getP();
BigInteger g1 = dhParams.getG();

// now we just need a second generator
BigInteger g2 = ParametersHelper.selectGenerator(p, random);
while (g1.equals(g2))
{
g2 = ParametersHelper.selectGenerator(p, random);
}

return new CramerShoupParameters(p, g1, g2, new SHA256Digest());
}

private static class ParametersHelper
{

private static final BigInteger TWO = BigInteger.valueOf(2);

/*
* Finds a pair of prime BigInteger's {p, q: p = 2q + 1}
*
* (see: Handbook of Applied Cryptography 4.86)
*/
static BigInteger[] generateSafePrimes(int size, int certainty, SecureRandom random)
{
BigInteger p, q;
int qLength = size - 1;

for (; ; )
{
q = new BigInteger(qLength, 2, random);
p = q.shiftLeft(1).add(ONE);
if (p.isProbablePrime(certainty) && (certainty <= 2 || q.isProbablePrime(certainty)))
{
break;
}
}

return new BigInteger[]{p, q};
}

static BigInteger selectGenerator(BigInteger p, SecureRandom random)
{
BigInteger pMinusTwo = p.subtract(TWO);
BigInteger g;

/*
* RFC 2631 2.2.1.2 (and see: Handbook of Applied Cryptography 4.81)
* RFC 2631 2.2.1.2 (and see: Handbook of Applied Cryptography 4.81)
*/
do {
BigInteger h = BigIntegers.createRandomInRange(TWO, pMinusTwo, random);
do
{
BigInteger h = BigIntegers.createRandomInRange(TWO, pMinusTwo, random);

g = h.modPow(TWO, p);
} while (g.equals(BigInteger.ONE));
g = h.modPow(TWO, p);
}
while (g.equals(ONE));

return g;
}
}
return g;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class CipherInputStream
{
private static final int INPUT_BUF_SIZE = 2048;

private final SkippingCipher skippingCipher;
private final byte[] inBuf;
private SkippingCipher skippingCipher;
private byte[] inBuf;

private BufferedBlockCipher bufferedBlockCipher;
private StreamCipher streamCipher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class ECNamedDomainParameters
extends ECDomainParameters
{
private final ASN1ObjectIdentifier name;
private ASN1ObjectIdentifier name;

public ECNamedDomainParameters(ASN1ObjectIdentifier name, ECCurve curve, ECPoint G, BigInteger n)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public final class KDFCounterParameters
implements DerivationParameters
{

private final byte[] ki;
private final byte[] fixedInputDataCounterPrefix;
private final byte[] fixedInputDataCounterSuffix;
private final int r;
private byte[] ki;
private byte[] fixedInputDataCounterPrefix;
private byte[] fixedInputDataCounterSuffix;
private int r;

/**
* Base constructor - suffix fixed input data only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private static BigInteger truncate(BigInteger x, int bitLength)
{
if (x.bitLength() > bitLength)
{
x = x.mod(BigInteger.ONE.shiftLeft(bitLength));
x = x.mod(ONE.shiftLeft(bitLength));
}
return x;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static BigInteger[] extEuclidBezout(BigInteger[] ab)
BigInteger s0 = ECConstants.ONE, s1 = ECConstants.ZERO;
BigInteger t0 = ECConstants.ZERO, t1 = ECConstants.ONE;

while (r1.compareTo(BigInteger.ONE) > 0)
while (r1.compareTo(ECConstants.ONE) > 0)
{
BigInteger[] qr = r0.divideAndRemainder(r1);
BigInteger q = qr[0], r2 = qr[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.ASN1GeneralizedTime;
import org.bouncycastle.asn1.DERGeneralizedTime;
import org.bouncycastle.asn1.DEROutputStream;
import org.bouncycastle.asn1.util.ASN1Dump;
Expand Down Expand Up @@ -2148,7 +2149,7 @@ public boolean match(Certificate cert)
// TODO fix this, Sequence contains tagged objects
ASN1Sequence derObject = (ASN1Sequence)derInputStream
.readObject();
DERGeneralizedTime derDate = DERGeneralizedTime
ASN1GeneralizedTime derDate = DERGeneralizedTime
.getInstance(derObject.getObjectAt(0));
SimpleDateFormat dateF = new SimpleDateFormat(
"yyyyMMddHHmmssZ");
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/jdk1.1/java/util/Collections.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

public class Collections
{
public static List EMPTY_LIST = new ArrayList();
public static final List EMPTY_LIST = unmodifiableList(new ArrayList());
public static final Set EMPTY_SET = unmodifiableSet(new HashSet());

private Collections()
{
Expand Down
Loading

0 comments on commit 11d8fde

Please sign in to comment.