diff options
Diffstat (limited to 'core/src/test/java/org/spongycastle/pqc/math/ntru/util/test')
-rw-r--r-- | core/src/test/java/org/spongycastle/pqc/math/ntru/util/test/AllTests.java | 23 | ||||
-rw-r--r-- | core/src/test/java/org/spongycastle/pqc/math/ntru/util/test/ArrayEncoderTest.java | 42 |
2 files changed, 65 insertions, 0 deletions
diff --git a/core/src/test/java/org/spongycastle/pqc/math/ntru/util/test/AllTests.java b/core/src/test/java/org/spongycastle/pqc/math/ntru/util/test/AllTests.java new file mode 100644 index 00000000..ff675a73 --- /dev/null +++ b/core/src/test/java/org/spongycastle/pqc/math/ntru/util/test/AllTests.java @@ -0,0 +1,23 @@ +package org.spongycastle.pqc.math.ntru.util.test; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class AllTests + extends TestCase +{ + public static void main (String[] args) + { + junit.textui.TestRunner.run(suite()); + } + + public static Test suite() + { + TestSuite suite = new TestSuite("NTRU ArrayEncoder Tests"); + + suite.addTestSuite(ArrayEncoderTest.class); + + return suite; + } +} diff --git a/core/src/test/java/org/spongycastle/pqc/math/ntru/util/test/ArrayEncoderTest.java b/core/src/test/java/org/spongycastle/pqc/math/ntru/util/test/ArrayEncoderTest.java new file mode 100644 index 00000000..ebd96d1c --- /dev/null +++ b/core/src/test/java/org/spongycastle/pqc/math/ntru/util/test/ArrayEncoderTest.java @@ -0,0 +1,42 @@ +package org.spongycastle.pqc.math.ntru.util.test; + +import java.security.SecureRandom; +import java.util.Random; + +import junit.framework.TestCase; +import org.spongycastle.pqc.math.ntru.polynomial.DenseTernaryPolynomial; +import org.spongycastle.pqc.math.ntru.polynomial.test.PolynomialGenerator; +import org.spongycastle.pqc.math.ntru.util.ArrayEncoder; +import org.spongycastle.util.Arrays; + +public class ArrayEncoderTest + extends TestCase +{ + public void testEncodeDecodeModQ() + { + int[] coeffs = PolynomialGenerator.generateRandom(1000, 2048).coeffs; + byte[] data = ArrayEncoder.encodeModQ(coeffs, 2048); + int[] coeffs2 = ArrayEncoder.decodeModQ(data, 1000, 2048); + assertTrue(Arrays.areEqual(coeffs, coeffs2)); + } + + public void testEncodeDecodeMod3Sves() + { + Random rng = new Random(); + byte[] data = new byte[180]; + rng.nextBytes(data); + int[] coeffs = ArrayEncoder.decodeMod3Sves(data, 960); + byte[] data2 = ArrayEncoder.encodeMod3Sves(coeffs); + assertTrue(Arrays.areEqual(data, data2)); + } + + public void testEncodeDecodeMod3Tight() + { + SecureRandom random = new SecureRandom(); + + int[] coeffs = DenseTernaryPolynomial.generateRandom(1000, random).coeffs; + byte[] data = ArrayEncoder.encodeMod3Tight(coeffs); + int[] coeffs2 = ArrayEncoder.decodeMod3Tight(data, 1000); + assertTrue(Arrays.areEqual(coeffs, coeffs2)); + } +}
\ No newline at end of file |