diff options
Diffstat (limited to 'libraries/spongycastle/core/src/test/java/org/spongycastle/crypto/test/BlockCipherVectorTest.java')
-rw-r--r-- | libraries/spongycastle/core/src/test/java/org/spongycastle/crypto/test/BlockCipherVectorTest.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libraries/spongycastle/core/src/test/java/org/spongycastle/crypto/test/BlockCipherVectorTest.java b/libraries/spongycastle/core/src/test/java/org/spongycastle/crypto/test/BlockCipherVectorTest.java new file mode 100644 index 000000000..322a580df --- /dev/null +++ b/libraries/spongycastle/core/src/test/java/org/spongycastle/crypto/test/BlockCipherVectorTest.java @@ -0,0 +1,71 @@ +package org.spongycastle.crypto.test; + +import org.spongycastle.crypto.BlockCipher; +import org.spongycastle.crypto.BufferedBlockCipher; +import org.spongycastle.crypto.CipherParameters; +import org.spongycastle.util.encoders.Hex; +import org.spongycastle.util.test.SimpleTest; + +/** + * a basic test that takes a cipher, key parameter, and an input + * and output string. This test wraps the engine in a buffered block + * cipher with padding disabled. + */ +public class BlockCipherVectorTest + extends SimpleTest +{ + int id; + BlockCipher engine; + CipherParameters param; + byte[] input; + byte[] output; + + public BlockCipherVectorTest( + int id, + BlockCipher engine, + CipherParameters param, + String input, + String output) + { + this.id = id; + this.engine = engine; + this.param = param; + this.input = Hex.decode(input); + this.output = Hex.decode(output); + } + + public String getName() + { + return engine.getAlgorithmName() + " Vector Test " + id; + } + + public void performTest() + throws Exception + { + BufferedBlockCipher cipher = new BufferedBlockCipher(engine); + + cipher.init(true, param); + + byte[] out = new byte[input.length]; + + int len1 = cipher.processBytes(input, 0, input.length, out, 0); + + cipher.doFinal(out, len1); + + if (!areEqual(out, output)) + { + fail("failed - " + "expected " + new String(Hex.encode(output)) + " got " + new String(Hex.encode(out))); + } + + cipher.init(false, param); + + int len2 = cipher.processBytes(output, 0, output.length, out, 0); + + cipher.doFinal(out, len2); + + if (!areEqual(input, out)) + { + fail("failed reversal got " + new String(Hex.encode(out))); + } + } +} |