open import Type
open import Data.Bit
open import Data.Maybe
open import Data.Product
open import Data.Nat.NP
open import Explore.Core
open import Explore.Explorable
open import Explore.Product
open Operators
open import Control.Strategy renaming (run to runStrategy)
import Game.IND-CPA-utils
open import Relation.Binary.PropositionalEquality
module Game.IND-CCA2-dagger
(PubKey : ★)
(SecKey : ★)
(Message : ★)
(CipherText : ★)
(Rₑ Rₖ Rₐ : ★)
(KeyGen : Rₖ → PubKey × SecKey)
(Enc : PubKey → Message → Rₑ → CipherText)
(Dec : SecKey → CipherText → Message)
where
open Game.IND-CPA-utils Message CipherText
open CPAAdversary
Adversary : ★
Adversary = Rₐ → PubKey →
DecRound
(CPAAdversary
(CipherText →
DecRound Bit))
R : ★
R = Rₐ × Rₖ × Rₑ × Rₑ
Experiment : ★
Experiment = Adversary → R → Bit
EXP : Bit → Experiment
EXP b A (rₐ , rₖ , rₑ₀ , rₑ₁) with KeyGen rₖ
... | pk , sk = b′ where
decRound = runStrategy (Dec sk)
cpaA = decRound (A rₐ pk)
mb = proj (get-m cpaA)
c₀ = Enc pk (mb b) rₑ₀
c₁ = Enc pk (mb (not b)) rₑ₁
b′ = decRound (put-c cpaA c₀ c₁)
module Advantage
(μₑ : Explore₀ Rₑ)
(μₖ : Explore₀ Rₖ)
(μₐ : Explore₀ Rₐ)
where
μR : Explore₀ R
μR = μₐ ×ᵉ μₖ ×ᵉ μₑ ×ᵉ μₑ
module μR = FromExplore₀ μR
run : Bit → Adversary → ℕ
run b adv = μR.count (EXP b adv)