1 package civitas.crypto.signature;
2
3 import static org.junit.jupiter.api.Assertions.assertFalse;
4 import static org.junit.jupiter.api.Assertions.assertTrue;
5
6 import org.junit.jupiter.api.DisplayName;
7 import org.junit.jupiter.api.Test;
8 import org.mockito.InjectMocks;
9
10 import civitas.common.ballotdesign.BallotDesignTestData;
11 import civitas.crypto.signedciphertext.ElGamalSignedCiphertextTestData;
12 import io.github.magwas.testing.TestBase;
13
14 class VerifyElGamalSignatureTest extends TestBase implements ElGamalSignedCiphertextTestData, BallotDesignTestData {
15 @InjectMocks
16 VerifyElGamalSignature verifyElGamalSignature;
17
18 @Test
19 @DisplayName("elGamalVerify works as expected: "
20 + "c == hash(g^d * a^(-c), a, b, env) %q, where c and d are used mod q, others mod p")
21 void elGamalVerifyTest() {
22
23 assertTrue(verifyElGamalSignature.apply(
24 EL_GAMAL_PARAMETERS,
25 SIGNED_CIPHERTEXT_OF_MESSAGE_WITH_FACTOR_RANDOM0_ADDITIONALENV,
26 ADDITIONALENV_BYTES));
27 }
28
29 @Test
30 @DisplayName("if the verification fails, false is returned")
31 void test() {
32
33 assertFalse(verifyElGamalSignature.apply(
34 EL_GAMAL_PARAMETERS,
35 SIGNED_CIPHERTEXT_OF_MESSAGE_WITH_FACTOR_RANDOM0_ADDITIONALENV_BAD,
36 ADDITIONALENV_BYTES));
37 }
38
39 @Test
40 @DisplayName("the version without env does the same without including env in the hash")
41 void elGamalVerifyTest1() {
42 assertTrue(verifyElGamalSignature.apply(EL_GAMAL_PARAMETERS, SIGNED_CIPHERTEXT_OF_MESSAGE_WITH_FACTOR_RANDOM0));
43 }
44
45 @Test
46 @DisplayName("when the version without env fails false returned")
47 void t1() {
48 assertFalse(verifyElGamalSignature.apply(
49 EL_GAMAL_PARAMETERS, SIGNED_CIPHERTEXT_OF_MESSAGE_WITH_FACTOR_RANDOM0_BAD));
50 }
51 }