Skip to content

Commit

Permalink
JDK 1.4 compatibility structures.
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Aug 10, 2016
1 parent a9502fc commit f1e41de
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 7 deletions.
20 changes: 20 additions & 0 deletions core/src/main/jdk1.4/org/bouncycastle/util/Arrays.java
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,26 @@ else if (b == null)
}
}

public static byte[] concatenate(byte[][] arrays)
{
int size = 0;
for (int i = 0; i != arrays.length; i++)
{
size += arrays[i].length;
}

byte[] rv = new byte[size];

int offSet = 0;
for (int i = 0; i != arrays.length; i++)
{
System.arraycopy(arrays[i], 0, rv, offSet, arrays[i].length);
offSet += arrays[i].length;
}

return rv;
}

public static int[] concatenate(int[] a, int[] b)
{
if (a == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class GOST3411_2012_256DigestTest
messages = new String[strList.size()];
for (int i = 0; i < strList.size(); i++)
{
messages[i] = strList.get(i);
messages[i] = (String)strList.get(i);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class GOST3411_2012_512DigestTest
messages = new String[strList.size()];
for (int i = 0; i < strList.size(); i++)
{
messages[i] = strList.get(i);
messages[i] = (String)strList.get(i);
}
}

Expand Down Expand Up @@ -77,7 +77,6 @@ public void performTest()
}
}

@Override
protected Digest cloneDigest(Digest digest)
{
return new GOST3411_2012_512Digest((GOST3411_2012_512Digest)digest);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.bouncycastle.jcajce.spec;

import java.security.spec.KeySpec;

import org.bouncycastle.util.Arrays;

/**
* Key Spec class for generating TLS key/iv material.
*/
public class TLSKeyMaterialSpec
implements KeySpec
{
public static final String MASTER_SECRET = "master secret";
public static final String KEY_EXPANSION = "key expansion";

private final byte[] secret;
private final String label;
private final int length;
private final byte[] seed;

/**
* Constructor specifying the basic parameters for a TLS KDF
*
* @param secret secret to use
* @param label e.g. 'master secret', or 'key expansion'
* @param length number of bytes of material to be generated
* @param seedMaterial1 first element of seed material
* @param seedMaterial2 second element of seed material
*/
public TLSKeyMaterialSpec(byte[] secret, String label, int length, byte[] seedMaterial1, byte[] seedMaterial2)
{
this.secret = Arrays.clone(secret);
this.label = label;
this.length = length;
this.seed = Arrays.concatenate(seedMaterial1, seedMaterial2);
}

/**
* Constructor specifying the basic parameters for a TLS KDF
*
* @param secret secret to use
* @param label e.g. 'master secret', or 'key expansion'
* @param length number of bytes of material to be generated
* @param seedMaterial1 first element of seed material
* @param seedMaterial2 second element of seed material
* @param seedMaterial3 third element of seed material
*/
public TLSKeyMaterialSpec(byte[] secret, String label, int length, byte[] seedMaterial1, byte[] seedMaterial2, byte[] seedMaterial3)
{
this.secret = Arrays.clone(secret);
this.label = label;
this.length = length;
this.seed = Arrays.concatenate(seedMaterial1, seedMaterial2, seedMaterial3);
}

/**
* Return the label associated with this spec.
*
* @return the label to be used with the TLS KDF.
*/
public String getLabel()
{
return label;
}

/**
* Return the number of bytes of key material to be generated for this spec.
*
* @return the length in bytes of the result.
*/
public int getLength()
{
return length;
}

/**
* Return the secret associated with this spec.
*
* @return a copy of the secret.
*/
public byte[] getSecret()
{
return Arrays.clone(secret);
}

/**
* Return the full seed for the spec.
*
* @return a copy of the seed.
*/
public byte[] getSeed()
{
return Arrays.clone(seed);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1616,9 +1616,9 @@ private void pemFileTest()

isTrue("certs size <cr><nl>", certs1.size() == certs2.size());

for (Certificate cert : certs1)
for (Iterator it = certs1.iterator(); it.hasNext();)
{
certs2.remove(cert);
certs2.remove(it.next());
}

isTrue("collection not empty", certs2.isEmpty());
Expand Down Expand Up @@ -1650,9 +1650,9 @@ private void pemFileTestWithNl()

isTrue("certs size <nl>", certs1.size() == certs2.size());

for (Certificate cert : certs1)
for (Iterator it = certs1.iterator(); it.hasNext();)
{
certs2.remove(cert);
certs2.remove(it.next());
}

isTrue("collection not empty", certs2.isEmpty());
Expand Down

0 comments on commit f1e41de

Please sign in to comment.