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

ArrayEncoderTest.java « test « util « ntru « math « pqc « bouncycastle « org « java « test « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6dbdea34286cf0a6a7676670cdb9c3d3374079af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package org.bouncycastle.pqc.math.ntru.util.test;

import java.security.SecureRandom;
import java.util.Random;

import junit.framework.TestCase;
import org.bouncycastle.pqc.math.ntru.polynomial.DenseTernaryPolynomial;
import org.bouncycastle.pqc.math.ntru.polynomial.test.PolynomialGenerator;
import org.bouncycastle.pqc.math.ntru.util.ArrayEncoder;
import org.bouncycastle.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));
    }
}