# A Few Thoughts on Cryptographic Engineering

semantic security refers to the concept that an attacker who sees a ciphertext should learn no more ( or very little more ) data than an attacker who does not see the ciphertext at all. This should hold even when the set of possible plaintexts is minor, potentially even chosen by the attacker himself .
Because it ’ sulfur unmanageable to formalize the definition above, we typically use a different definition that ’ mho known to be equivalent. This definition is called “ Indistinguishability under Chosen Plaintext Attack ”, or just “ IND-CPA ” for short .
The definition is formalized as a game between an adversary and some honest “ Challenger ”. For the subject of populace identify encoding the plot looks like this :

1. First the challenger generates an encryption keypair, and sends the public key $pk$ to the adversary. (It keeps the secret key.)
2. Next, the adversary selects a pair of messages $M_0, M_1$ (of equal length) and sends them to the challenger.
3. The challenger picks a random bit $b \in \{0,1\}$ and encrypts one of the two messages as $C^* \leftarrow {\sf Encrypt}(pk, M_b)$. It sends back $C^*$ to the adversary.
4. Finally, the adversary outputs a guess $b'$. We say the adversary “wins” if it guesses correctly: that is, if $b' = b$.

As mentioned in early articles, the adversary can always win with probability 1/2, precisely by guessing randomly in step ( 4 ). So we ’ re not interested in whether the adversary wins at all. alternatively we ’ re concern in the adversary ’ randomness advantage, which is to say : how much better he does than he would if he good guessed randomly.

We can express this advantage as | Probability Adversary Wins – 1/2|. ( This probability is taken over many runs of the experiment and all the randomness used — it ’ s not just the adversary ’ s success after one plot. ) An attacker who wins with probability precisely 1/2 will have “ zero ” advantage in the IND-CPA game. In general for a scheme to be IND-CPA dependable it must hold that for all possible ( time-bounded ) adversaries, the adversary ’ s advantage will be negligibly small .
One obvious bill about the IND-CPA game is that the attacker has the public key. ( Recall that he gets it in footstep [ 1 ] ). So sometimes people, upon seeing this definition for the inaugural time, propose the following strategy for winning the game :

1. The adversary picks two messages and then encrypts both of them using the public key.
2. When the adversary receives the ciphertext in step (3), he just compares that ciphertext to the two he generated himself.
3. Voila, the adversary can always figure out which message was encrypted!

If the encoding scheme is not randomized — mean that every prison term you encrypt a message using a given public winder, you get the same accurate ciphertext — this attack works perfectly. In fact it works therefore well that an attacker who uses this scheme will constantly win the IND-CPA plot, meaning that such a system can not possibly satisfy the IND-CPA security definition .
The implication therefore, is that in order to satisfy the IND-CPA definition, any public-key encoding outline must be randomized. That is, it must take in some random bits as region of the encoding algorithm — and it must use these bits in generating a ciphertext. Another way to think about this is that for every possible public key and message $(pk, M)$ there are many possible ciphertexts that the encoding algorithm can output, all of which are valid encryptions of $M$.

We see this practice of randomization in many real-world encoding schemes. For example, most RSA encoding is done using some sort of “ encoding padding ” schema, like OAEP or ( the identical unwrap ) PKCS # 1v1.5. Algorithms like Elgamal ( and derivatives like ECIES ) besides use randomness in their encoding .
The authoritative takeaway here is that this use of randomness in the encoding algorithm international relations and security network ’ triiodothyronine just for playfulness : it ’ randomness required in order to get semantic security .
The case of symmetric encryption. As a annotate, it ’ mho besides worth mentioning that IND-CPA can be applied to symmetrical encoding. The major differences in that definition are ( A ) that in step ( 1 ) there is no populace key to give to the adversary, and ( B ) to replace this lost functionality, the rival must provide an “ encoding ” oracle to the adversary. specifically, that means that the rival must, when requested, code messages of the adversary ’ mho choice using its clandestine key. This can happen at any decimal point in the game.

The caveats about deterministic encoding besides enforce in the symmetrical font, and for basically the lapp reason. In short : ciphertexts must be diversified in some room so that two different encryptions of the same plaintext do not produce the lapp ciphertext. If this was not the shell, then the adversary could easily win the game .
The only major remainder is that in the symmetrical jell, this diversification doesn ’ metric ton always need to be done with randomness. Some schemes use “ express ”. For exercise, it ’ s possible to build an encoding outline where the rival keeps a elementary counter between messages, and uses this buffet in place of “ true ” randomness. ( A good model of this is CTR mode encoding, where the attacker ensures that initial counters [ IVs ] never recur. ) This obviously merely works in settings where there is a individual encryptor, or all encryptors are guaranteed to not repeat unlike counters .