View Javadoc
1   package civitas.crypto.parameters;
2   
3   import org.springframework.beans.factory.annotation.Autowired;
4   import org.springframework.stereotype.Controller;
5   
6   import civitas.crypto.Constants;
7   import civitas.util.CivitasBigInteger;
8   
9   @Controller
10  public class GenerateElGamalParameters implements Constants {
11  
12  	@Autowired
13  	GenerateSafePrime generateSafePrime;
14  
15  	@Autowired
16  	GenerateSchnorrPrime generateSchnorrPrime;
17  
18  	@Autowired
19  	FindGeneratorService findGenerator;
20  
21  	public ElGamalParameters apply(final int keyLength, final int groupLength) {
22  		PrimePair sp;
23  		if (groupLength == keyLength + 1) {
24  			sp = generateSafePrime.apply(keyLength);
25  		} else {
26  			sp = generateSchnorrPrime.apply(keyLength, groupLength);
27  		}
28  		CivitasBigInteger g = findGenerator.apply(sp);
29  		return new ElGamalParameters(sp.p, sp.q, g);
30  	}
31  
32  	public ElGamalParameters apply() {
33  		return apply(EL_GAMAL_KEY_LENGTH, EL_GAMAL_GROUP_LENGTH);
34  	}
35  }