diff options
Diffstat (limited to 'core/src/test/java/org/bouncycastle/crypto/test/cavp')
7 files changed, 0 insertions, 681 deletions
diff --git a/core/src/test/java/org/bouncycastle/crypto/test/cavp/CAVPListener.java b/core/src/test/java/org/bouncycastle/crypto/test/cavp/CAVPListener.java deleted file mode 100644 index 81f86e57..00000000 --- a/core/src/test/java/org/bouncycastle/crypto/test/cavp/CAVPListener.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.bouncycastle.crypto.test.cavp; - -import java.util.Properties; - -public interface CAVPListener -{ - public void setup(); - - public void receiveStart(String name); - - public void receiveCAVPVectors(String name, Properties config, Properties vectors); - - public void receiveCommentLine(String commentLine); - - public void receiveEnd(); - - public void tearDown(); -} diff --git a/core/src/test/java/org/bouncycastle/crypto/test/cavp/CAVPReader.java b/core/src/test/java/org/bouncycastle/crypto/test/cavp/CAVPReader.java deleted file mode 100644 index 9cd33afc..00000000 --- a/core/src/test/java/org/bouncycastle/crypto/test/cavp/CAVPReader.java +++ /dev/null @@ -1,152 +0,0 @@ -package org.bouncycastle.crypto.test.cavp; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.Reader; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.bouncycastle.crypto.BlockCipher; -import org.bouncycastle.crypto.Digest; -import org.bouncycastle.crypto.Mac; -import org.bouncycastle.crypto.digests.SHA1Digest; -import org.bouncycastle.crypto.digests.SHA224Digest; -import org.bouncycastle.crypto.digests.SHA256Digest; -import org.bouncycastle.crypto.digests.SHA384Digest; -import org.bouncycastle.crypto.digests.SHA512Digest; -import org.bouncycastle.crypto.engines.AESFastEngine; -import org.bouncycastle.crypto.engines.DESedeEngine; -import org.bouncycastle.crypto.macs.CMac; -import org.bouncycastle.crypto.macs.HMac; - -public class CAVPReader -{ - - private static final Pattern COMMENT_PATTERN = Pattern.compile("^\\s*\\#\\s*(.*)$"); - private static final Pattern CONFIG_PATTERN = Pattern.compile("^\\s*+\\[\\s*+(.*?)\\s*+=\\s*+(.*?)\\s*+\\]\\s*+$"); - private static final Pattern VECTOR_PATTERN = Pattern.compile("^\\s*+(.*?)\\s*+=\\s*+(.*?)\\s*+$"); - private static final Pattern EMPTY_PATTERN = Pattern.compile("^\\s*+$"); - static final Pattern PATTERN_FOR_R = Pattern.compile("(\\d+)_BITS"); - private final CAVPListener listener; - private String name; - private BufferedReader lineReader; - - - public CAVPReader(CAVPListener listener) - { - this.listener = listener; - } - - public void setInput(String name, Reader reader) - { - this.name = name; - this.lineReader = new BufferedReader(reader); - } - - public void readAll() - throws IOException - { - - listener.setup(); - - Properties config = new Properties(); - - boolean startNewVector = true; - - Properties vectors = new Properties(); - - while (true) - { - final String line = lineReader.readLine(); - if (line == null) - { - listener.receiveEnd(); - break; - } - - final Matcher commentMatcher = COMMENT_PATTERN.matcher(line); - if (commentMatcher.matches()) - { - listener.receiveCommentLine(commentMatcher.group(1)); - continue; - } - - final Matcher configMatcher = CONFIG_PATTERN.matcher(line); - if (configMatcher.matches()) - { - config.put(configMatcher.group(1), configMatcher.group(2)); - continue; - } - - final Matcher vectorMatcher = VECTOR_PATTERN.matcher(line); - if (vectorMatcher.matches()) - { - vectors.put(vectorMatcher.group(1), vectorMatcher.group(2)); - startNewVector = false; - continue; - } - - final Matcher emptyMatcher = EMPTY_PATTERN.matcher(line); - if (emptyMatcher.matches()) - { - if (startNewVector) - { - continue; - } - - listener.receiveCAVPVectors(name, config, vectors); - vectors = new Properties(); - startNewVector = true; - } - } - - listener.tearDown(); - } - - static Mac createPRF(Properties config) - { - final Mac prf; - if (config.getProperty("PRF").matches("CMAC_AES\\d\\d\\d")) - { - BlockCipher blockCipher = new AESFastEngine(); - prf = new CMac(blockCipher); - } - else if (config.getProperty("PRF").matches("CMAC_TDES\\d")) - { - BlockCipher blockCipher = new DESedeEngine(); - prf = new CMac(blockCipher); - } - else if (config.getProperty("PRF").matches("HMAC_SHA1")) - { - Digest digest = new SHA1Digest(); - prf = new HMac(digest); - } - else if (config.getProperty("PRF").matches("HMAC_SHA224")) - { - Digest digest = new SHA224Digest(); - prf = new HMac(digest); - } - else if (config.getProperty("PRF").matches("HMAC_SHA256")) - { - Digest digest = new SHA256Digest(); - prf = new HMac(digest); - } - else if (config.getProperty("PRF").matches("HMAC_SHA384")) - { - Digest digest = new SHA384Digest(); - prf = new HMac(digest); - } - else if (config.getProperty("PRF").matches("HMAC_SHA512")) - { - Digest digest = new SHA512Digest(); - prf = new HMac(digest); - } - else - { - throw new IllegalStateException("Unknown Mac for PRF"); - } - return prf; - } - -} diff --git a/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFCounterTests.java b/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFCounterTests.java deleted file mode 100644 index 81f10824..00000000 --- a/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFCounterTests.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.bouncycastle.crypto.test.cavp; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Properties; -import java.util.regex.Matcher; - -import org.bouncycastle.crypto.Mac; -import org.bouncycastle.crypto.generators.KDFCounterBytesGenerator; -import org.bouncycastle.crypto.params.KDFCounterParameters; -import org.bouncycastle.util.Arrays; -import org.bouncycastle.util.encoders.Hex; -import org.bouncycastle.util.test.SimpleTestResult; -import org.bouncycastle.util.test.TestFailedException; - -public final class KDFCounterTests - implements CAVPListener -{ - private PrintWriter out; - - public void receiveCAVPVectors(String name, Properties config, - Properties vectors) - { - - // create Mac based PRF from PRF property, create the KDF - final Mac prf = CAVPReader.createPRF(config); - final KDFCounterBytesGenerator gen = new KDFCounterBytesGenerator(prf); - - - Matcher matcherForR = CAVPReader.PATTERN_FOR_R.matcher(config.getProperty("RLEN")); - if (!matcherForR.matches()) - { - throw new IllegalStateException("RLEN value should always match"); - } - final int r = Integer.parseInt(matcherForR.group(1)); - - final int count = Integer.parseInt(vectors.getProperty("COUNT")); - final int l = Integer.parseInt(vectors.getProperty("L")); - final byte[] ki = Hex.decode(vectors.getProperty("KI")); - - //Three variants of this KDF are possible, with the counter before the fixed data, after the fixed data, or in the middle of the fixed data. - if (config.getProperty("CTRLOCATION").matches("BEFORE_FIXED")) - { - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFCounterParameters params = new KDFCounterParameters(ki, null, fixedInputData, r); - gen.init(params); - } - else if (config.getProperty("CTRLOCATION").matches("AFTER_FIXED")) - { - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFCounterParameters params = new KDFCounterParameters(ki, fixedInputData, null, r); - gen.init(params); - } - else if (config.getProperty("CTRLOCATION").matches("MIDDLE_FIXED")) - { - final byte[] DataBeforeCtrData = Hex.decode(vectors.getProperty("DataBeforeCtrData")); - final byte[] DataAfterCtrData = Hex.decode(vectors.getProperty("DataAfterCtrData")); - final KDFCounterParameters params = new KDFCounterParameters(ki, DataBeforeCtrData, DataAfterCtrData, r); - gen.init(params); - } - else - { - return; // Unknown CTRLOCATION - } - - - final byte[] koGenerated = new byte[l / 8]; - gen.generateBytes(koGenerated, 0, koGenerated.length); - - final byte[] koVectors = Hex.decode(vectors.getProperty("KO")); - - compareKO(name, config, count, koGenerated, koVectors); - } - - private static void compareKO( - String name, Properties config, int test, byte[] calculatedOKM, byte[] testOKM) - { - - if (!Arrays.areEqual(calculatedOKM, testOKM)) - { - throw new TestFailedException(new SimpleTestResult( - false, name + " using " + config + " test " + test + " failed")); - - } - } - - public void receiveCommentLine(String commentLine) - { - // out.println("# " + commentLine); - } - - public void receiveStart(String name) - { - // do nothing - } - - public void receiveEnd() - { - out.println(" *** *** *** "); - } - - public void setup() - { - try - { - out = new PrintWriter(new FileWriter("KDFCTR.gen")); - } - catch (IOException e) - { - throw new IllegalStateException(e); - } - } - - public void tearDown() - { - out.close(); - } -}
\ No newline at end of file diff --git a/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineCounterTests.java b/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineCounterTests.java deleted file mode 100644 index 5b3df023..00000000 --- a/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineCounterTests.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.bouncycastle.crypto.test.cavp; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Properties; -import java.util.regex.Matcher; - -import org.bouncycastle.crypto.Mac; -import org.bouncycastle.crypto.generators.KDFDoublePipelineIterationBytesGenerator; -import org.bouncycastle.crypto.params.KDFDoublePipelineIterationParameters; -import org.bouncycastle.util.Arrays; -import org.bouncycastle.util.encoders.Hex; -import org.bouncycastle.util.test.SimpleTestResult; -import org.bouncycastle.util.test.TestFailedException; - -public final class KDFDoublePipelineCounterTests - implements CAVPListener -{ - private PrintWriter out; - - public void receiveCAVPVectors(String name, Properties config, - Properties vectors) - { - // out.println(" === " + name + " === "); - // out.println(" --- config --- "); - // out.println(config); - // out.println(" --- vectors --- "); - // out.println(vectors); - - // always skip AFTER_FIXED - if (!config.getProperty("CTRLOCATION").matches("AFTER_ITER")) - { - return; - } - - // create Mac based PRF from PRF property, create the KDF - final Mac prf = CAVPReader.createPRF(config); - final KDFDoublePipelineIterationBytesGenerator gen = new KDFDoublePipelineIterationBytesGenerator(prf); - - - Matcher matcherForR = CAVPReader.PATTERN_FOR_R.matcher(config.getProperty("RLEN")); - if (!matcherForR.matches()) - { - throw new IllegalStateException("RLEN value should always match"); - } - final int r = Integer.parseInt(matcherForR.group(1)); - - final int count = Integer.parseInt(vectors.getProperty("COUNT")); - final int l = Integer.parseInt(vectors.getProperty("L")); - final byte[] ki = Hex.decode(vectors.getProperty("KI")); - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFDoublePipelineIterationParameters params = KDFDoublePipelineIterationParameters.createWithCounter(ki, fixedInputData, r); - gen.init(params); - - final byte[] koGenerated = new byte[l / 8]; - gen.generateBytes(koGenerated, 0, koGenerated.length); - - final byte[] koVectors = Hex.decode(vectors.getProperty("KO")); - - compareKO(name, config, count, koGenerated, koVectors); - } - - private static void compareKO( - String name, Properties config, int test, byte[] calculatedOKM, byte[] testOKM) - { - - if (!Arrays.areEqual(calculatedOKM, testOKM)) - { - throw new TestFailedException(new SimpleTestResult( - false, name + " using " + config + " test " + test + " failed")); - - } - } - - public void receiveCommentLine(String commentLine) - { - // out.println("# " + commentLine); - } - - public void receiveStart(String name) - { - // do nothing - } - - public void receiveEnd() - { - out.println(" *** *** *** "); - } - - public void setup() - { - try - { - out = new PrintWriter(new FileWriter("KDFDblPipelineCounter.gen")); - } - catch (IOException e) - { - throw new IllegalStateException(e); - } - } - - public void tearDown() - { - out.close(); - } -}
\ No newline at end of file diff --git a/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineIterationNoCounterTests.java b/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineIterationNoCounterTests.java deleted file mode 100644 index 3923f9a1..00000000 --- a/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFDoublePipelineIterationNoCounterTests.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.bouncycastle.crypto.test.cavp; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Properties; - -import org.bouncycastle.crypto.Mac; -import org.bouncycastle.crypto.generators.KDFDoublePipelineIterationBytesGenerator; -import org.bouncycastle.crypto.params.KDFDoublePipelineIterationParameters; -import org.bouncycastle.util.Arrays; -import org.bouncycastle.util.encoders.Hex; -import org.bouncycastle.util.test.SimpleTestResult; -import org.bouncycastle.util.test.TestFailedException; - -public final class KDFDoublePipelineIterationNoCounterTests - implements CAVPListener -{ - private PrintWriter out; - - public void receiveCAVPVectors(String name, Properties config, - Properties vectors) - { - - - // create Mac based PRF from PRF property, create the KDF - final Mac prf = CAVPReader.createPRF(config); - final KDFDoublePipelineIterationBytesGenerator gen = new KDFDoublePipelineIterationBytesGenerator(prf); - - final int count = Integer.parseInt(vectors.getProperty("COUNT")); - final int l = Integer.parseInt(vectors.getProperty("L")); - final byte[] ki = Hex.decode(vectors.getProperty("KI")); - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFDoublePipelineIterationParameters params = KDFDoublePipelineIterationParameters.createWithoutCounter(ki, fixedInputData); - gen.init(params); - - final byte[] koGenerated = new byte[l / 8]; - gen.generateBytes(koGenerated, 0, koGenerated.length); - - final byte[] koVectors = Hex.decode(vectors.getProperty("KO")); - - compareKO(name, config, count, koGenerated, koVectors); - } - - private static void compareKO( - String name, Properties config, int test, byte[] calculatedOKM, byte[] testOKM) - { - - if (!Arrays.areEqual(calculatedOKM, testOKM)) - { - throw new TestFailedException(new SimpleTestResult( - false, name + " using " + config + " test " + test + " failed")); - - } - } - - public void receiveCommentLine(String commentLine) - { - // out.println("# " + commentLine); - } - - public void receiveStart(String name) - { - // do nothing - } - - public void receiveEnd() - { - out.println(" *** *** *** "); - } - - public void setup() - { - try - { - out = new PrintWriter(new FileWriter("KDFDblPipelineNoCounter.gen")); - } - catch (IOException e) - { - throw new IllegalStateException(e); - } - } - - public void tearDown() - { - out.close(); - } -}
\ No newline at end of file diff --git a/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFFeedbackCounterTests.java b/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFFeedbackCounterTests.java deleted file mode 100644 index 6f8a0fde..00000000 --- a/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFFeedbackCounterTests.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.bouncycastle.crypto.test.cavp; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Properties; -import java.util.regex.Matcher; - -import org.bouncycastle.crypto.Mac; -import org.bouncycastle.crypto.generators.KDFFeedbackBytesGenerator; -import org.bouncycastle.crypto.params.KDFFeedbackParameters; -import org.bouncycastle.util.Arrays; -import org.bouncycastle.util.encoders.Hex; -import org.bouncycastle.util.test.SimpleTestResult; -import org.bouncycastle.util.test.TestFailedException; - -public final class KDFFeedbackCounterTests - implements CAVPListener -{ - private PrintWriter out; - - public void receiveCAVPVectors(String name, Properties config, - Properties vectors) - { - // out.println(" === " + name + " === "); - // out.println(" --- config --- "); - // out.println(config); - // out.println(" --- vectors --- "); - // out.println(vectors); - - // always skip AFTER_FIXED - if (!config.getProperty("CTRLOCATION").matches("AFTER_ITER")) - { - return; - } - - // create Mac based PRF from PRF property, create the KDF - final Mac prf = CAVPReader.createPRF(config); - final KDFFeedbackBytesGenerator gen = new KDFFeedbackBytesGenerator(prf); - - - Matcher matcherForR = CAVPReader.PATTERN_FOR_R.matcher(config.getProperty("RLEN")); - if (!matcherForR.matches()) - { - throw new IllegalStateException("RLEN value should always match"); - } - final int r = Integer.parseInt(matcherForR.group(1)); - - final int count = Integer.parseInt(vectors.getProperty("COUNT")); - final int l = Integer.parseInt(vectors.getProperty("L")); - final byte[] ki = Hex.decode(vectors.getProperty("KI")); - final byte[] iv = Hex.decode(vectors.getProperty("IV")); - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFFeedbackParameters params = KDFFeedbackParameters.createWithCounter(ki, iv, fixedInputData, r); - gen.init(params); - - final byte[] koGenerated = new byte[l / 8]; - gen.generateBytes(koGenerated, 0, koGenerated.length); - - final byte[] koVectors = Hex.decode(vectors.getProperty("KO")); - - compareKO(name, config, count, koGenerated, koVectors); - } - - private static void compareKO( - String name, Properties config, int test, byte[] calculatedOKM, byte[] testOKM) - { - - if (!Arrays.areEqual(calculatedOKM, testOKM)) - { - throw new TestFailedException(new SimpleTestResult( - false, name + " using " + config + " test " + test + " failed")); - - } - } - - public void receiveCommentLine(String commentLine) - { - // out.println("# " + commentLine); - } - - public void receiveStart(String name) - { - // do nothing - } - - public void receiveEnd() - { - out.println(" *** *** *** "); - } - - public void setup() - { - try - { - out = new PrintWriter(new FileWriter("KDFFeedbackCounter.gen")); - } - catch (IOException e) - { - throw new IllegalStateException(e); - } - } - - public void tearDown() - { - out.close(); - } -}
\ No newline at end of file diff --git a/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFFeedbackNoCounterTests.java b/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFFeedbackNoCounterTests.java deleted file mode 100644 index cd7d8b80..00000000 --- a/core/src/test/java/org/bouncycastle/crypto/test/cavp/KDFFeedbackNoCounterTests.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.bouncycastle.crypto.test.cavp; - -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Properties; - -import org.bouncycastle.crypto.Mac; -import org.bouncycastle.crypto.generators.KDFFeedbackBytesGenerator; -import org.bouncycastle.crypto.params.KDFFeedbackParameters; -import org.bouncycastle.util.Arrays; -import org.bouncycastle.util.encoders.Hex; -import org.bouncycastle.util.test.SimpleTestResult; -import org.bouncycastle.util.test.TestFailedException; - -public final class KDFFeedbackNoCounterTests - implements CAVPListener -{ - private PrintWriter out; - - public void receiveCAVPVectors(String name, Properties config, - Properties vectors) - { - - - // create Mac based PRF from PRF property, create the KDF - final Mac prf = CAVPReader.createPRF(config); - final KDFFeedbackBytesGenerator gen = new KDFFeedbackBytesGenerator(prf); - - final int count = Integer.parseInt(vectors.getProperty("COUNT")); - final int l = Integer.parseInt(vectors.getProperty("L")); - final byte[] ki = Hex.decode(vectors.getProperty("KI")); - final byte[] iv = Hex.decode(vectors.getProperty("IV")); - final byte[] fixedInputData = Hex.decode(vectors.getProperty("FixedInputData")); - final KDFFeedbackParameters params = KDFFeedbackParameters.createWithoutCounter(ki, iv, fixedInputData); - gen.init(params); - - final byte[] koGenerated = new byte[l / 8]; - gen.generateBytes(koGenerated, 0, koGenerated.length); - - final byte[] koVectors = Hex.decode(vectors.getProperty("KO")); - - compareKO(name, config, count, koGenerated, koVectors); - } - - private static void compareKO( - String name, Properties config, int test, byte[] calculatedOKM, byte[] testOKM) - { - - if (!Arrays.areEqual(calculatedOKM, testOKM)) - { - throw new TestFailedException(new SimpleTestResult( - false, name + " using " + config + " test " + test + " failed")); - - } - } - - public void receiveCommentLine(String commentLine) - { -// out.println("# " + commentLine); - } - - public void receiveStart(String name) - { - // do nothing - } - - public void receiveEnd() - { - out.println(" *** *** *** "); - } - - public void setup() - { - try - { - out = new PrintWriter(new FileWriter("KDFFeedbackNoCounter.gen")); - } - catch (IOException e) - { - throw new IllegalStateException(e); - } - } - - public void tearDown() - { - out.close(); - } -}
\ No newline at end of file |