View Javadoc
1   package civitas.crypto.proof1ofl;
2   
3   import org.springframework.beans.factory.annotation.Autowired;
4   import org.springframework.stereotype.Controller;
5   
6   import civitas.crypto.Constants;
7   import civitas.crypto.CryptoException;
8   import civitas.crypto.ciphertext.ElGamalCiphertext;
9   import civitas.crypto.ciphertext.ElGamalEncrypt;
10  import civitas.crypto.ciphertextlist.CiphertextList;
11  import civitas.crypto.msg.ElGamalMsg;
12  import civitas.crypto.msg.EncodeMessage;
13  import civitas.crypto.parameters.ElGamalParameters;
14  import civitas.crypto.publickey.ElGamalPublicKey;
15  import civitas.crypto.reencryptfactor.ElGamalReencryptFactor;
16  import civitas.util.CivitasBigInteger;
17  
18  @Controller
19  public class ConstructWellKnownCiphertexts implements Constants {
20  
21  	@Autowired
22  	ElGamalEncrypt elGamalEncrypt;
23  
24  	@Autowired
25  	EncodeMessage encodeMessage;
26  
27  	public CiphertextList apply(final ElGamalPublicKey key, final int count) throws CryptoException {
28  		if (count < 1 || key == null) {
29  			throw new CryptoException("bad parameters for constructWellKnownCiphertexts");
30  		}
31  		CiphertextList cs = new CiphertextList();
32  
33  		ElGamalReencryptFactor factor = new ElGamalReencryptFactor(ZERO);
34  		ElGamalParameters params = key.params;
35  		for (int i = 0; i < count; i++) {
36  			CivitasBigInteger encodedMessage = encodeMessage.apply(i + 1, params);
37  			ElGamalCiphertext encrypted = elGamalEncrypt.apply(key, new ElGamalMsg(encodedMessage), factor);
38  			cs.add(encrypted);
39  		}
40  		return cs;
41  	}
42  }