Theory Diffie_Hellman

(* Title: Diffie_Hellman.thy
  Author: Andreas Lochbihler, ETH Zurich *)

section β€ΉSpecifying security using gamesβ€Ί

theory Diffie_Hellman imports
  CryptHOL.Cyclic_Group_SPMF
  CryptHOL.Computational_Model
begin

subsection β€ΉThe DDH gameβ€Ί

locale ddh =
  fixes 𝒒 :: "'grp cyclic_group" (structure)
begin

type_synonym 'grp' adversary = "'grp' β‡’ 'grp' β‡’ 'grp' β‡’ bool spmf"

definition ddh_0 :: "'grp adversary β‡’ bool spmf"
where "ddh_0 π’œ = do {
     x ← sample_uniform (order 𝒒);
     y ← sample_uniform (order 𝒒);
     π’œ (g [^] x) (g [^] y) (g [^] (x * y))
  }"

definition ddh_1 :: "'grp adversary β‡’ bool spmf"
where "ddh_1 π’œ = do {
     x ← sample_uniform (order 𝒒);
     y ← sample_uniform (order 𝒒);
     z ← sample_uniform (order 𝒒);
     π’œ (g [^] x) (g [^] y) (g [^] z)
  }"

definition advantage :: "'grp adversary β‡’ real"
where "advantage π’œ = Β¦spmf (ddh_0 π’œ) True - spmf (ddh_1 π’œ) TrueΒ¦"

definition lossless :: "'grp adversary β‡’ bool"
where "lossless π’œ ⟷ (βˆ€Ξ± Ξ² Ξ³. lossless_spmf (π’œ Ξ± Ξ² Ξ³))"

lemma lossless_ddh_0:
  "⟦ lossless π’œ; 0 < order 𝒒 ⟧
  ⟹ lossless_spmf (ddh_0 π’œ)"
by(auto simp add: lossless_def ddh_0_def split_def Let_def)

lemma lossless_ddh_1:
  "⟦ lossless π’œ; 0 < order 𝒒 ⟧
  ⟹ lossless_spmf (ddh_1 π’œ)"
by(auto simp add: lossless_def ddh_1_def split_def Let_def)

end

subsection β€ΉThe LCDH gameβ€Ί

locale lcdh =
  fixes 𝒒 :: "'grp cyclic_group" (structure)
begin

type_synonym 'grp' adversary = "'grp' β‡’ 'grp' β‡’ 'grp' set spmf"

definition lcdh :: "'grp adversary β‡’ bool spmf"
where "lcdh π’œ = do { 
     x ← sample_uniform (order 𝒒);
     y ← sample_uniform (order 𝒒);
     zs ← π’œ (g [^] x) (g [^] y);
     return_spmf (g [^] (x * y) ∈ zs)
  }"

definition advantage :: "'grp adversary β‡’ real"
where "advantage π’œ = spmf (lcdh π’œ) True"

definition lossless :: "'grp adversary β‡’ bool"
where "lossless π’œ ⟷ (βˆ€Ξ± Ξ². lossless_spmf (π’œ Ξ± Ξ²))"

lemma lossless_lcdh:
  "⟦ lossless π’œ; 0 < order 𝒒 ⟧
  ⟹ lossless_spmf (lcdh π’œ)"
by(auto simp add: lossless_def lcdh_def split_def Let_def)

end

end