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

JPAKEPrimeOrderGroupTest.java « test « agreement « crypto « spongycastle « org « java « test « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b02a8f6ce1fff5985b5ff45cdfe9253f60566bf8 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package org.spongycastle.crypto.agreement.test;

import java.math.BigInteger;

import junit.framework.TestCase;
import org.spongycastle.crypto.CryptoException;
import org.spongycastle.crypto.agreement.jpake.JPAKEPrimeOrderGroup;

public class JPAKEPrimeOrderGroupTest
    extends TestCase
{

    public void testConstruction()
        throws CryptoException
    {
        // p-1 not evenly divisible by q
        try
        {
            new JPAKEPrimeOrderGroup(BigInteger.valueOf(7), BigInteger.valueOf(5), BigInteger.valueOf(6));
            fail();
        }
        catch (IllegalArgumentException e)
        {
            // pass
        }

        // g < 2
        try
        {
            new JPAKEPrimeOrderGroup(BigInteger.valueOf(11), BigInteger.valueOf(5), BigInteger.valueOf(1));
            fail();
        }
        catch (IllegalArgumentException e)
        {
            // pass
        }

        // g > p-1
        try
        {
            new JPAKEPrimeOrderGroup(BigInteger.valueOf(11), BigInteger.valueOf(5), BigInteger.valueOf(11));
            fail();
        }
        catch (IllegalArgumentException e)
        {
            // pass
        }

        // g^q mod p not equal 1
        try
        {
            new JPAKEPrimeOrderGroup(BigInteger.valueOf(11), BigInteger.valueOf(5), BigInteger.valueOf(6));
            fail();
        }
        catch (IllegalArgumentException e)
        {
            // pass
        }

        // p not prime
        try
        {
            new JPAKEPrimeOrderGroup(BigInteger.valueOf(15), BigInteger.valueOf(2), BigInteger.valueOf(4));
            fail();
        }
        catch (IllegalArgumentException e)
        {
            // pass
        }

        // q not prime
        try
        {
            new JPAKEPrimeOrderGroup(BigInteger.valueOf(7), BigInteger.valueOf(6), BigInteger.valueOf(3));
            fail();
        }
        catch (IllegalArgumentException e)
        {
            // pass
        }

        // should succeed
        new JPAKEPrimeOrderGroup(BigInteger.valueOf(7), BigInteger.valueOf(3), BigInteger.valueOf(4));
    }
}