1 package civitas.functionaltests; 2 3 import static org.junit.jupiter.api.Assertions.assertEquals; 4 import static org.junit.jupiter.api.Assertions.assertTrue; 5 6 import org.junit.jupiter.api.DisplayName; 7 import org.junit.jupiter.api.Tag; 8 import org.junit.jupiter.api.Test; 9 import org.junit.jupiter.api.extension.ExtendWith; 10 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.test.context.ContextConfiguration; 12 import org.springframework.test.context.junit.jupiter.SpringExtension; 13 14 import civitas.AppTestConfig; 15 import civitas.crypto.Constants; 16 import civitas.crypto.parameters.GenerateSchnorrPrime; 17 import civitas.crypto.parameters.PrimePair; 18 import civitas.crypto.privatekey.tests.ElGamalPrivateKeyTestData; 19 20 @Tag("functional") 21 @ExtendWith(SpringExtension.class) 22 @ContextConfiguration(classes = AppTestConfig.class) 23 class GenerateSchnorrPrimeFunctionalTest implements ElGamalPrivateKeyTestData, Constants { 24 25 @Autowired 26 GenerateSchnorrPrime generateSchnorrPrimeReal; 27 28 @Test 29 @DisplayName("making sure that we get a correct pair using the real random generator" 30 + "FIXME: uses random, should make a multirun verification test, but it takes a lot of time") 31 void schnorrPrimeTest() { 32 PrimePair sp = generateSchnorrPrimeReal.apply(EL_GAMAL_KEY_LENGTH, EL_GAMAL_GROUP_LENGTH); 33 assertTrue(sp.p.isProbablePrime(CERTAINTY)); 34 assertTrue(sp.q.isProbablePrime(CERTAINTY)); 35 assertEquals(ZERO, sp.p.subtract(ONE).mod(sp.q)); 36 assertEquals(EL_GAMAL_GROUP_LENGTH, sp.p.bitLength()); 37 assertEquals(EL_GAMAL_KEY_LENGTH, sp.q.bitLength()); 38 } 39 }