Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hook <dgh@cryptoworkshop.com>2013-05-09 05:32:36 +0400
committerDavid Hook <dgh@cryptoworkshop.com>2013-05-09 05:32:36 +0400
commitae6148456939c37460ce402e46bf616a3dd298f8 (patch)
tree69743b98fd9c89eb2ab3b1f36afd021c654f25b4
parentd9414fd78220e0815eec9ca948985437b5c565ca (diff)
added handling of 168 bit TDEA keys to DES-EDE
added initial test vectors for CTR SP800, fixed Block_Cipher_df
-rw-r--r--src/main/java/org/bouncycastle/crypto/engines/DESedeEngine.java28
-rw-r--r--src/main/java/org/bouncycastle/crypto/prng/CTRSP800DRBG.java131
-rw-r--r--src/main/java/org/bouncycastle/crypto/random/SP800SecureRandomBuilder.java8
-rw-r--r--src/test/java/org/bouncycastle/crypto/test/CTRDRBGTest.java135
-rw-r--r--src/test/java/org/bouncycastle/crypto/test/CTRDRGBTest.java166
-rw-r--r--src/test/java/org/bouncycastle/crypto/test/DRBGTestVector.java25
-rw-r--r--src/test/java/org/bouncycastle/crypto/test/RegressionTest.java2
7 files changed, 276 insertions, 219 deletions
diff --git a/src/main/java/org/bouncycastle/crypto/engines/DESedeEngine.java b/src/main/java/org/bouncycastle/crypto/engines/DESedeEngine.java
index 513eccdf..f6941e3c 100644
--- a/src/main/java/org/bouncycastle/crypto/engines/DESedeEngine.java
+++ b/src/main/java/org/bouncycastle/crypto/engines/DESedeEngine.java
@@ -47,7 +47,21 @@ public class DESedeEngine
if (keyMaster.length != 24 && keyMaster.length != 16)
{
- throw new IllegalArgumentException("key size must be 16 or 24 bytes.");
+ // new style 3TDEA key without parity bits.
+ if (keyMaster.length == 21)
+ {
+ byte[] tmp = new byte[24];
+
+ padKey(keyMaster, 0, tmp, 0);
+ padKey(keyMaster, 7, tmp, 8);
+ padKey(keyMaster, 14, tmp, 16);
+
+ keyMaster = tmp;
+ }
+ else
+ {
+ throw new IllegalArgumentException("key size must be 16, 21, or 24 bytes.");
+ }
}
this.forEncryption = encrypting;
@@ -72,6 +86,18 @@ public class DESedeEngine
}
}
+ private void padKey(byte[] keyMaster, int keyOff, byte[] tmp, int tmpOff)
+ {
+ tmp[tmpOff + 0] = (byte)(keyMaster[keyOff + 0] & 0xfe);
+ tmp[tmpOff + 1] = (byte)((keyMaster[keyOff + 0] << 7) | ((keyMaster[keyOff + 1] & 0xfc) >>> 1));
+ tmp[tmpOff + 2] = (byte)((keyMaster[keyOff + 1] << 6) | ((keyMaster[keyOff + 2] & 0xf8) >>> 2));
+ tmp[tmpOff + 3] = (byte)((keyMaster[keyOff + 2] << 5) | ((keyMaster[keyOff + 3] & 0xf0) >>> 3));
+ tmp[tmpOff + 4] = (byte)((keyMaster[keyOff + 3] << 4) | ((keyMaster[keyOff + 4] & 0xe0) >>> 4));
+ tmp[tmpOff + 5] = (byte)((keyMaster[keyOff + 4] << 3) | ((keyMaster[keyOff + 5] & 0xc0) >>> 5));
+ tmp[tmpOff + 6] = (byte)((keyMaster[keyOff + 5] << 2) | ((keyMaster[keyOff + 6] & 0x80) >>> 6));
+ tmp[tmpOff + 7] = (byte)(keyMaster[keyOff + 6] << 1);
+ }
+
public String getAlgorithmName()
{
return "DESede";
diff --git a/src/main/java/org/bouncycastle/crypto/prng/CTRSP800DRBG.java b/src/main/java/org/bouncycastle/crypto/prng/CTRSP800DRBG.java
index fbdcbfe0..87a49de1 100644
--- a/src/main/java/org/bouncycastle/crypto/prng/CTRSP800DRBG.java
+++ b/src/main/java/org/bouncycastle/crypto/prng/CTRSP800DRBG.java
@@ -17,7 +17,7 @@ public class CTRSP800DRBG
private byte[] _V;
private int _reseedCounter = 0;
- public CTRSP800DRBG(BlockCipher engine, int keySizeInBits, int seedLength, EntropySource entropySource, byte[] nonce,
+ public CTRSP800DRBG(BlockCipher engine, int keySizeInBits, EntropySource entropySource, byte[] nonce,
byte[] personalisationString, int securityStrength)
{
@@ -25,11 +25,11 @@ public class CTRSP800DRBG
_engine = engine;
_keySizeInBits = keySizeInBits;
- _seedLength = seedLength;
+ _seedLength = keySizeInBits + engine.getBlockSize() * 8;
int entropyLengthInBytes = securityStrength;
- if (securityStrength > 128)
+ if (securityStrength > 256)
{
throw new IllegalStateException(
"Security strength is not supported by the derivation function");
@@ -39,17 +39,21 @@ public class CTRSP800DRBG
System.out.println("Constructor Entropy: " + new String(Hex.encode(entropy)));
- addOneTo(nonce);
CTR_DRBG_Instantiate_algorithm(entropy, nonce, personalisationString);
- System.out.println("Constructor V : " + new String(Hex.encode(_V)));
- System.out.println("Constructor Key: " + new String(Hex.encode(_Key)));
+ System.err.println("Constructor V : " + new String(Hex.encode(_V)));
+ System.err.println("Constructor Key: " + new String(Hex.encode(_Key)));
}
private void CTR_DRBG_Instantiate_algorithm(byte[] entropy, byte[] nonce,
byte[] personalisationString)
{
+ if (personalisationString == null)
+ {
+ personalisationString = new byte[0];
+ }
+
byte[] seedMaterial = new byte[entropy.length + nonce.length + personalisationString.length];
int pos = 0;
@@ -61,24 +65,26 @@ public class CTRSP800DRBG
System.out.println("Constructor SeedMaterial: " + new String(Hex.encode(seedMaterial)));
- byte[] seed = Block_Cipher_df(_seedLength, seedMaterial);
+ byte[] seed = Block_Cipher_df(seedMaterial, _seedLength);
System.out.println("Constructor Seed: " + new String(Hex.encode(seed)));
int outlen = _engine.getBlockSize();
- _Key = new byte[outlen];
+
+ _Key = new byte[(_keySizeInBits + 7) / 8];
_V = new byte[outlen];
CTR_DRBG_Update(seed, _Key, _V);
// _Key & _V are modified by this call
-
+ System.out.println("Key: " + new String(Hex.encode(_Key)));
+ System.out.println("V : " + new String(Hex.encode(_V)));
_reseedCounter = 1;
}
private void CTR_DRBG_Update(byte[] seed, byte[] key, byte[] v)
{
byte[] temp = new byte[seed.length];
- byte[] outputBlock = new byte[seed.length];
+ byte[] outputBlock = new byte[_engine.getBlockSize()];
int i=0;
int outLen = _engine.getBlockSize();
@@ -90,17 +96,17 @@ public class CTRSP800DRBG
_engine.processBlock(v, 0, outputBlock, 0);
int bytesToCopy = ((temp.length - i * outLen) > outLen)
- ? outLen
- : (temp.length - i * outLen);
+ ? outLen : (temp.length - i * outLen);
System.arraycopy(outputBlock, 0, temp, i * outLen, bytesToCopy);
++i;
}
-
- XOR(temp, temp, seed, 0);
-
+ System.err.println("seed: " + new String(Hex.encode(seed)));
+ System.err.println("temp: " + new String(Hex.encode(temp)));
+ XOR(temp, seed, temp, 0);
+ System.err.println("temp: " + new String(Hex.encode(temp)));
System.arraycopy(temp, 0, key, 0, key.length);
- System.arraycopy(temp, temp.length-outLen-1, v, 0, outLen);
+ System.arraycopy(temp, key.length, v, 0, v.length);
}
private void CTR_DRBG_Reseed_algorithm(EntropySource entropy, byte[] additionalInput)
@@ -202,7 +208,7 @@ public class CTRSP800DRBG
// 14. requested_bits = Leftmost number_of_bits_to_return of temp.
//
// 15. Return SUCCESS and requested_bits.
- private byte[] Block_Cipher_df(int bitLength, byte[] inputString)
+ private byte[] Block_Cipher_df(byte[] inputString, int bitLength)
{
int outLen = _engine.getBlockSize();
int L = inputString.length; // already in bytes
@@ -216,15 +222,16 @@ public class CTRSP800DRBG
System.arraycopy(inputString, 0, S, 8, L);
S[8 + L] = (byte)0x80;
// S already padded with zeros
-
- byte[] temp = new byte[N+L];
+ System.err.println("S :" + new String(Hex.encode(S)));
+ byte[] temp = new byte[_keySizeInBits / 8 + outLen];
byte[] bccOut = new byte[outLen];
byte[] IV = new byte[outLen];
int i = 0;
byte[] K = new byte[_keySizeInBits / 8];
- System.arraycopy(K_BITS, 0, K, 0, K.length);
+ System.arraycopy(K_BITS, 0, K, 0, K.length);
+
while (i*outLen*8 < _keySizeInBits + outLen *8)
{
copyIntToByteArray(IV, i, 0);
@@ -237,6 +244,28 @@ public class CTRSP800DRBG
System.arraycopy(bccOut, 0, temp, i * outLen, bytesToCopy);
++i;
}
+
+ byte[] X = new byte[outLen];
+ System.arraycopy(temp, 0, K, 0, K.length);
+ System.arraycopy(temp, K.length, X, 0, X.length);
+
+ temp = new byte[bitLength / 2];
+
+ i = 0;
+ _engine.init(true, new KeyParameter(K));
+
+ while (i * outLen < temp.length)
+ {
+ _engine.processBlock(X, 0, X, 0);
+
+ int bytesToCopy = ((temp.length - i * outLen) > outLen)
+ ? outLen
+ : (temp.length - i * outLen);
+
+ System.arraycopy(X, 0, temp, i * outLen, bytesToCopy);
+ i++;
+ }
+
return temp;
}
@@ -258,14 +287,19 @@ public class CTRSP800DRBG
int outlen = _engine.getBlockSize();
byte[] chainingValue = new byte[outlen]; // initial values = 0
int n = data.length / outlen;
-
+
byte[] inputBlock = new byte[outlen];
+
_engine.init(true, new KeyParameter(k));
- for (int i=0; i< n; i++)
+
+ _engine.processBlock(iV, 0, chainingValue, 0);
+
+ for (int i = 0; i < n; i++)
{
XOR(inputBlock, chainingValue, data, i*outlen);
_engine.processBlock(inputBlock, 0, chainingValue, 0);
}
+
System.arraycopy(chainingValue, 0, bccOut, 0, bccOut.length);
}
@@ -277,41 +311,46 @@ public class CTRSP800DRBG
buf[offSet + 3] = ((byte)(value));
}
- private byte[] byteGenProcess(BlockCipher engine, byte[] input, int lengthInBits)
+ public int generate(byte[] output, byte[] additionalInput, boolean predictionResistant)
{
- int m = (lengthInBits / 8) / engine.getBlockSize();
+ if (predictionResistant)
+ {
+ CTR_DRBG_Reseed_algorithm(_entropySource, additionalInput);
+ }
- byte[] data = new byte[input.length];
- System.arraycopy(input, 0, data, 0, input.length);
+ if (additionalInput != null)
+ {
+ additionalInput = Block_Cipher_df(additionalInput, _seedLength);
+ CTR_DRBG_Update(additionalInput, _Key, _V);
+ }
+ else
+ {
+ additionalInput = new byte[_seedLength];
+ }
- byte[] W = new byte[lengthInBits / 8];
+ byte[] out = new byte[_V.length];
- byte[] dig = new byte[engine.getBlockSize()];
+ _engine.init(true, new KeyParameter(_Key));
- for (int i = 0; i <= m; i++)
+ for (int i = 0; i < output.length / out.length; i++)
{
- engine.processBlock(data, data.length, dig, 0);
+ addOneTo(_V);
- int bytesToCopy = ((W.length - i * dig.length) > dig.length)
- ? dig.length
- : (W.length - i * dig.length);
- System.arraycopy(dig, 0, W, i * dig.length, bytesToCopy);
+ _engine.processBlock(_V, 0, out, 0);
- addOneTo(data);
+ int bytesToCopy = ((output.length - i * out.length) > out.length)
+ ? out.length
+ : (output.length - i * _V.length);
+
+ System.arraycopy(out, 0, output, i * out.length, bytesToCopy);
}
- return W;
- }
- public int generate(byte[] output, byte[] additionalInput, boolean predictionResistant)
- {
- if (predictionResistant) {
- CTR_DRBG_Reseed_algorithm(_entropySource, additionalInput);
- }
-
- additionalInput = null;
- // CTR_DRBG_Generate_algorithm(output, output.length*8, additionalInput);
- return output.length*8;
+ CTR_DRBG_Update(additionalInput, _Key, _V);
+
+ _reseedCounter++;
+
+ return output.length * 8;
}
public void reseed(byte[] additionalInput)
diff --git a/src/main/java/org/bouncycastle/crypto/random/SP800SecureRandomBuilder.java b/src/main/java/org/bouncycastle/crypto/random/SP800SecureRandomBuilder.java
index feb61bc3..6e7b50bb 100644
--- a/src/main/java/org/bouncycastle/crypto/random/SP800SecureRandomBuilder.java
+++ b/src/main/java/org/bouncycastle/crypto/random/SP800SecureRandomBuilder.java
@@ -104,7 +104,7 @@ public class SP800SecureRandomBuilder
public SP800SecureRandom build(BlockCipher cipher, int keySizeInBits, int seedLength, byte[] nonce, boolean predictionResistant)
{
- return new SP800SecureRandom(random, entropySourceProvider.get(entropyBitsRequired), new CTRDRBGProvider(cipher, keySizeInBits, seedLength, nonce, personalizationString, securityStrength), predictionResistant);
+ return new SP800SecureRandom(random, entropySourceProvider.get(entropyBitsRequired), new CTRDRBGProvider(cipher, keySizeInBits, nonce, personalizationString, securityStrength), predictionResistant);
}
/**
@@ -205,16 +205,14 @@ public class SP800SecureRandomBuilder
private final BlockCipher blockCipher;
private final int keySizeInBits;
- private final int seedLength;
private final byte[] nonce;
private final byte[] personalizationString;
private final int securityStrength;
- public CTRDRBGProvider(BlockCipher blockCipher, int keySizeInBits, int seedLength, byte[] nonce, byte[] personalizationString, int securityStrength)
+ public CTRDRBGProvider(BlockCipher blockCipher, int keySizeInBits, byte[] nonce, byte[] personalizationString, int securityStrength)
{
this.blockCipher = blockCipher;
this.keySizeInBits = keySizeInBits;
- this.seedLength = seedLength;
this.nonce = nonce;
this.personalizationString = personalizationString;
this.securityStrength = securityStrength;
@@ -222,7 +220,7 @@ public class SP800SecureRandomBuilder
public SP80090DRBG get(EntropySource entropySource)
{
- return new CTRSP800DRBG(blockCipher, keySizeInBits, seedLength, entropySource, nonce, personalizationString, securityStrength);
+ return new CTRSP800DRBG(blockCipher, keySizeInBits, entropySource, nonce, personalizationString, securityStrength);
}
}
}
diff --git a/src/test/java/org/bouncycastle/crypto/test/CTRDRBGTest.java b/src/test/java/org/bouncycastle/crypto/test/CTRDRBGTest.java
new file mode 100644
index 00000000..b60c6b31
--- /dev/null
+++ b/src/test/java/org/bouncycastle/crypto/test/CTRDRBGTest.java
@@ -0,0 +1,135 @@
+package org.bouncycastle.crypto.test;
+
+import org.bouncycastle.crypto.engines.AESFastEngine;
+import org.bouncycastle.crypto.engines.DESedeEngine;
+import org.bouncycastle.crypto.prng.CTRSP800DRBG;
+import org.bouncycastle.crypto.prng.SP80090DRBG;
+import org.bouncycastle.util.encoders.Hex;
+import org.bouncycastle.util.test.SimpleTest;
+
+/**
+ * CTR DRBG Test
+ */
+public class CTRDRBGTest
+ extends SimpleTest
+{
+ public String getName()
+ {
+ return "CTRDRBGTest";
+ }
+
+ public static void main(String[] args)
+ {
+ runTest(new CTRDRBGTest());
+ }
+
+ private DRBGTestVector[] createTestVectorData()
+ {
+ return new DRBGTestVector[]
+ {
+ new DRBGTestVector(
+ new DESedeEngine(), 168,
+ new Bit232EntropyProvider().get(232),
+ false,
+ "20212223242526",
+ 112,
+ new String[]
+ {
+ "ABC88224514D0316EA3D48AEE3C9A2B4",
+ "D3D3F372E43E7ABDC4FA293743EED076"
+ }
+ ),
+ new DRBGTestVector(
+ new DESedeEngine(), 168,
+ new Bit232EntropyProvider().get(232),
+ false,
+ "20212223242526",
+ 112,
+ new String[]
+ {
+ "D4564EE072ACA5BD279536E14F94CB12",
+ "1CCD9AFEF15A9679BA75E35225585DEA"
+ }
+ )
+ .addAdditionalInput("606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C")
+ .addAdditionalInput("A0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBC"),
+ new DRBGTestVector(
+ new AESFastEngine(), 192,
+ new Bit320EntropyProvider().get(320),
+ false,
+ "202122232425262728292A2B",
+ 192,
+ new String[]
+ {
+ "E231244B3235B085C81604424357E85201E3828B5C45568679A5555F867AAC8C",
+ "DDD0F7BCCADADAA31A67652259CE569A271DD85CF66C3D6A7E9FAED61F38D219"
+ }
+ )
+ .setPersonalizationString("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F6061626364656667")
+ };
+ }
+
+ public void performTest()
+ throws Exception
+ {
+ DRBGTestVector[] tests = createTestVectorData();
+
+ for (int i = 0; i != tests.length; i++)
+ {
+ DRBGTestVector tv = tests[i];
+
+ byte[] nonce = tv.nonce();
+ byte[] personalisationString = tv.personalizationString();
+
+ SP80090DRBG d = new CTRSP800DRBG(tv.getCipher(), tv.getKeySizeInBits(), tv.entropySource(), nonce, personalisationString, tv.securityStrength());
+
+ byte[] output = new byte[tv.expectedValue(0).length];
+
+ d.generate(output, tv.additionalInput(0), tv.predictionResistance());
+
+ byte[] expected = tv.expectedValue(0);
+
+ if (!areEqual(expected, output))
+ {
+ fail("Test #" + (i + 1) + ".1 failed, expected " + new String(Hex.encode(tv.expectedValue(0))) + " got " + new String(Hex.encode(output)));
+ }
+
+ output = new byte[tv.expectedValue(0).length];
+
+ d.generate(output, tv.additionalInput(1), tv.predictionResistance());
+
+ expected = tv.expectedValue(1);
+ if (!areEqual(expected, output))
+ {
+ fail("Test #" + (i + 1) + ".2 failed, expected " + new String(Hex.encode(tv.expectedValue(1))) + " got " + new String(Hex.encode(output)));
+ }
+ }
+ }
+
+ private class Bit232EntropyProvider
+ extends TestEntropySourceProvider
+ {
+ Bit232EntropyProvider()
+ {
+ super(Hex.decode(
+ "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C" +
+ "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C" +
+ "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDC"), true);
+ }
+ }
+
+ private class Bit320EntropyProvider
+ extends TestEntropySourceProvider
+ {
+ Bit320EntropyProvider()
+ {
+ super(Hex.decode(
+ "000102030405060708090A0B0C0D0E0F"+
+ "101112131415161718191A1B1C1D1E1F2021222324252627"+
+ "808182838485868788898A8B8C8D8E8F"+
+ "909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7"+
+ "C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF"+
+ "D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7"), true);
+ }
+ }
+}
diff --git a/src/test/java/org/bouncycastle/crypto/test/CTRDRGBTest.java b/src/test/java/org/bouncycastle/crypto/test/CTRDRGBTest.java
deleted file mode 100644
index 5f753922..00000000
--- a/src/test/java/org/bouncycastle/crypto/test/CTRDRGBTest.java
+++ /dev/null
@@ -1,166 +0,0 @@
-package org.bouncycastle.crypto.test;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.bouncycastle.crypto.BlockCipher;
-import org.bouncycastle.crypto.engines.AESFastEngine;
-import org.bouncycastle.crypto.prng.CTRSP800DRBG;
-import org.bouncycastle.crypto.prng.EntropySource;
-import org.bouncycastle.util.encoders.Hex;
-import org.bouncycastle.util.test.SimpleTest;
-import org.bouncycastle.util.test.TestResult;
-
-/**
- * DRBG Test
- */
-public class CTRDRGBTest extends SimpleTest
-{
- public String getName()
- {
- return "DRGBCTRTest";
- }
-
- public static void main(String[] args)
- {
- CTRDRGBTest test = new CTRDRGBTest();
- TestResult result = test.perform();
-
- if (result.getException() != null)
- {
- result.getException().printStackTrace();
- }
- else
- {
- System.out.println(result);
- }
- }
-
- private class TestVector
- {
- private String _entropy;
- private boolean _pr;
- private String _nonce;
- private String _personalisation;
- private int _ss;
- private String _ev;
- private List _ai = new ArrayList();
-
- public TestVector(String entropy, boolean predictionResistance, String nonce, int securityStrength, String expected)
- {
- _entropy = entropy;
- _pr = predictionResistance;
- _nonce = nonce;
- _ss = securityStrength;
- _ev = expected;
- _personalisation = "";
- }
-
- public void setAdditionalInput(String input)
- {
- _ai.add(input);
- }
-
- public String entropy()
- {
- return _entropy;
- }
-
- public boolean predictionResistance()
- {
- return _pr;
- }
-
- public String nonce()
- {
- return _nonce;
- }
-
- public String personalisation()
- {
- return _personalisation;
- }
-
- public int securityStrength()
- {
- return _ss;
- }
-
- public String expectedValue()
- {
- return _ev;
- }
-
- public byte[] additionalInput(int position)
- {
- int len = _ai.size();
- byte[] rv;
- if (position >= len) {
- rv = null;
- }
- else {
- rv = Hex.decode((String)(_ai.get(position)));
- }
- return rv;
- }
- }
-
- private Collection createTestVectorData()
- {
- Collection rv = new ArrayList();
-
- // line 3239
- TestVector tv = new TestVector(
- "d9dc92450a03fa663613395037d50655136b3088ebe84cd3cc99d39733e2c88fa6528dff60b1f934f1ee472a20572eb7",
- true,
- "d3ec0c67136ee08c",
- 128,
- "e7ce8192f1c18613cd5d7ab11ca22da1");
- // rv.add(tv);
-
- // line 4047
- tv = new TestVector(
- "7c0fe58f8f62c25eadbe24600b78426a9df9a69cd131028a055e9ec1e483f37c",
- false,
- "d939ad1e08a80244",
- 128,
- "3487018af191fa961fefac2854d96bf5");
- rv.add(tv);
- return rv;
-
- }
-
- public void performTest() throws Exception
- {
- Collection<TestVector> tests = createTestVectorData();
-
- for (TestVector tv : tests)
- {
- tv.entropy();
- BlockCipher engine = new AESFastEngine();
- EntropySource tes = new TestEntropySourceProvider(Hex.decode(tv.entropy()), tv.predictionResistance()).get(256);
- byte[] nonce = Hex.decode(tv.nonce());
- byte[] personalisationString = Hex.decode(tv.personalisation());
- int securityStrength = tv.securityStrength();
- CTRSP800DRBG d = new CTRSP800DRBG(engine, 256, 256, tes, nonce, personalisationString, securityStrength);
-
- byte[] output = new byte[20];
-
- int rv = d.generate(output, tv.additionalInput(0), true);
- String out = new String(Hex.encode(output));
- System.out.println(out);
- rv = d.generate(output, tv.additionalInput(1), true);
- out = new String(Hex.encode(output));
- System.out.println(out);
-
- byte[] expected = Hex.decode(tv.expectedValue());
-
- if (!areEqual(expected, output))
- {
- throw new Exception("Test Vector Failed, expected "+tv.expectedValue()+" got "+out);
- }
- System.out.println("Test Vector Passed, expected ; "+tv.expectedValue()+" got "+out);
- }
- }
-}
diff --git a/src/test/java/org/bouncycastle/crypto/test/DRBGTestVector.java b/src/test/java/org/bouncycastle/crypto/test/DRBGTestVector.java
index f68aa962..b6af8141 100644
--- a/src/test/java/org/bouncycastle/crypto/test/DRBGTestVector.java
+++ b/src/test/java/org/bouncycastle/crypto/test/DRBGTestVector.java
@@ -3,6 +3,7 @@ package org.bouncycastle.crypto.test;
import java.util.ArrayList;
import java.util.List;
+import org.bouncycastle.crypto.BlockCipher;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.prng.EntropySource;
import org.bouncycastle.util.encoders.Hex;
@@ -10,6 +11,8 @@ import org.bouncycastle.util.encoders.Hex;
public class DRBGTestVector
{
private Digest _digest;
+ private BlockCipher _cipher;
+ private int _keySizeInBits;
private EntropySource _eSource;
private boolean _pr;
private String _nonce;
@@ -29,11 +32,33 @@ public class DRBGTestVector
_personalisation = "";
}
+ public DRBGTestVector(BlockCipher cipher, int keySizeInBits, EntropySource eSource, boolean predictionResistance, String nonce, int securityStrength, String[] expected)
+ {
+ _cipher = cipher;
+ _keySizeInBits = keySizeInBits;
+ _eSource = eSource;
+ _pr = predictionResistance;
+ _nonce = nonce;
+ _ss = securityStrength;
+ _ev = expected;
+ _personalisation = "";
+ }
+
public Digest getDigest()
{
return _digest;
}
+ public BlockCipher getCipher()
+ {
+ return _cipher;
+ }
+
+ public int getKeySizeInBits()
+ {
+ return _keySizeInBits;
+ }
+
public DRBGTestVector addAdditionalInput(String input)
{
_ai.add(input);
diff --git a/src/test/java/org/bouncycastle/crypto/test/RegressionTest.java b/src/test/java/org/bouncycastle/crypto/test/RegressionTest.java
index 1327ea80..aea3003d 100644
--- a/src/test/java/org/bouncycastle/crypto/test/RegressionTest.java
+++ b/src/test/java/org/bouncycastle/crypto/test/RegressionTest.java
@@ -115,7 +115,7 @@ public class RegressionTest
new OCBTest(),
new HashDRBGTest(),
new HMacDRBGTest(),
- new CTRDRGBTest(),
+ new CTRDRBGTest(),
new DualECDRBGTest()
};