package de.uni.trier.infsec.functionalities.pkenc.ideal;

import de.uni.trier.infsec.environment.crypto.CryptoLib;
import static de.uni.trier.infsec.utils.MessageTools.getZeroMessage;
import static de.uni.trier.infsec.utils.MessageTools.copyOf;

/**
 * Ideal functionality for public-key encryption: Encryptor
 */
public final class Encryptor {

	private MessagePairList log;
	private byte[] publKey;
	
	Encryptor(MessagePairList mpl, byte[] publicKey) { 
		log = mpl;		
		publKey = publicKey;
	}
		
	public byte[] getPublicKey() {
		return copyOf(publKey);
	}
	
	public byte[] encrypt(byte[] message) {
		byte[] messageCopy = copyOf(message);
		byte[] randomCipher = copyOf(CryptoLib.pke_encrypt(getZeroMessage(message.length), 
													   copyOf(publKey)));
		if( randomCipher == null ) return null;
		log.add(messageCopy, randomCipher);
		return copyOf(randomCipher);
	}
}

@@ -660,16 +660,183 @@
 Cipher =
+ null;%0A%09%09// keep asking the environment for the ciphertext, until a fresh one is given:%0A%09%09while( randomCipher==null %7C%7C log.contains(randomCipher) ) %7B%0A%09%09%09randomCipher =
  copyOf(
@@ -893,25 +893,8 @@
 h), 
-%0A%09%09%09%09%09%09%09%09%09%09%09%09%09   
 copy
@@ -914,47 +914,9 @@
 ;%0A%09%09
-if( randomCipher == null ) return null;
+%7D
 %0A%09%09l

change the ideal functionality for PKE to guarantee functional properties