1 package civitas.crypto.parameters;
2
3 import civitas.crypto.Constants;
4 import civitas.crypto.CryptoError;
5
6 public class CheckGroup implements Constants {
7
8 public void apply(final ElGamalParameters that) {
9 if (!that.p.isProbablePrime(CERTAINTY)) {
10 throw new CryptoError("p is not prime");
11 }
12 if (!that.q.isProbablePrime(CERTAINTY)) {
13 throw new CryptoError("q is not prime");
14 }
15 if (!ZERO.equals(that.p.subtract(ONE).mod(that.q))) {
16 throw new CryptoError("q does not divide p-1");
17 }
18 if (!ONE.equals(that.g.modPow(that.q, that.p))) {
19 throw new CryptoError("g is not order q");
20 }
21 }
22 }