All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.crypto.agreement.test.JPAKEPrimeOrderGroupTest Maven / Gradle / Ivy

Go to download

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.4.

There is a newer version: 1.78.1
Show newest version
package org.bouncycastle.crypto.agreement.test;

import java.math.BigInteger;

import junit.framework.TestCase;
import org.bouncycastle.crypto.CryptoException;
import org.bouncycastle.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));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy