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

ProductFormPolynomialTest.java « test « polynomial « 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: 9fbbb981f45b9ed26b2a89c8c4a5db1ccf599e8b (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
43
44
45
46
47
package org.bouncycastle.pqc.math.ntru.polynomial.test;

import java.security.SecureRandom;

import junit.framework.TestCase;
import org.bouncycastle.pqc.crypto.ntru.NTRUEncryptionKeyGenerationParameters;
import org.bouncycastle.pqc.math.ntru.polynomial.IntegerPolynomial;
import org.bouncycastle.pqc.math.ntru.polynomial.ProductFormPolynomial;

public class ProductFormPolynomialTest
    extends TestCase
{
    private NTRUEncryptionKeyGenerationParameters params;
    private int N;
    private int df1;
    private int df2;
    private int df3;
    private int q;

    public void setUp()
    {
        params = NTRUEncryptionKeyGenerationParameters.APR2011_439_FAST;
        N = params.N;
        df1 = params.df1;
        df2 = params.df2;
        df3 = params.df3;
        q = params.q;
    }

    public void testFromToBinary()
        throws Exception
    {
        ProductFormPolynomial p1 = ProductFormPolynomial.generateRandom(N, df1, df2, df3, df3 - 1, new SecureRandom());
        byte[] bin1 = p1.toBinary();
        ProductFormPolynomial p2 = ProductFormPolynomial.fromBinary(bin1, N, df1, df2, df3, df3 - 1);
        assertEquals(p1, p2);
    }

    public void testMult()
    {
        ProductFormPolynomial p1 = ProductFormPolynomial.generateRandom(N, df1, df2, df3, df3 - 1, new SecureRandom());
        IntegerPolynomial p2 = PolynomialGenerator.generateRandom(N, q);
        IntegerPolynomial p3 = p1.mult(p2);
        IntegerPolynomial p4 = p1.toIntegerPolynomial().mult(p2);
        assertEquals(p3, p4);
    }
}