View Javadoc
1   package civitas.crypto.parameters;
2   
3   import org.springframework.beans.factory.annotation.Autowired;
4   import org.springframework.stereotype.Service;
5   
6   import civitas.crypto.Constants;
7   import civitas.crypto.CryptoBase;
8   import civitas.util.CivitasBigInteger;
9   
10  @Service
11  public class FindGeneratorService implements Constants {
12  	@Autowired
13  	CryptoBase cryptoBase;
14  
15  	public CivitasBigInteger apply(final PrimePair sp) {
16  		CivitasBigInteger g = null;
17  		boolean reject = false;
18  		CivitasBigInteger p = sp.p;
19  		CivitasBigInteger negONE = p.subtract(ONE);
20  		CivitasBigInteger twoK = p.subtract(ONE).divide(sp.q);
21  		do {
22  			g = cryptoBase.generateRandomElement(p);
23  			g = g.modPow(twoK, p);
24  			reject = ONE.equals(g) || g.equals(negONE);
25  		} while (reject);
26  
27  		return g;
28  	}
29  }