Hashed ElGamal is IND-CPA under DDH and entropy smoothing #
(EasyCrypt examples/hashed_elgamal_std.ec)
EC's file, declaration by declaration and script line by line; all five lemmas are proven.
Translation (as Examples/ElGamal.lean):
op k : { int | 0 < k } as gt0_kis the classParams;clone import BitWord as Bits with op n <- k … rename "word" as "bits" "dunifin" as "dbits"is the abbreviationsbits,dbitsofLib/EC/BitWord.leanatk.- The theory
EntropySmoothingis declared in the file and imported, not cloned: a namespace, itstype hkey,op dhkey,op hashthe classEntropySmoothing.Params group hkey. EC'shint exact random : dhkey_llisattribute [ec_random]. module type AdvES = { proc guess(_: hkey * bits) : bool }takes one pair, which EC identifies with two parameters (ESAdv(A).guess (hk, h)declares two,A.guess(hk,h)passes two): two parameters here.- EC's type abbreviations
pkey,skey,ptxt,ctxtare written out in the clone ofPKE_CPA;declare axioms are section hypotheses;Gbtakes the section'sAas its parameter.
Gap list (the examples' infrastructure batch; numbers as in Examples/ElGamal.lean where the
gap is the same):
- GAP 1:
inlinewrites a call's parameters as one tuple assignment, EC as one per parameter:stmt_split_paramsafterstmt_inline*. - GAP 2:
swap{1} 1 1moves the first statement of an inlined body later:inlineleaves areset_varsof the callee's locals before it, which EC's count attaches to that statement, and the reset does not commute with the next statement (it resets its variable). Written with our position,stmt_swap_raw{1} 2 1, which moves the sampling alone. (Moving earlier past a reset works.) - GAP 3: in
Gb_halfEC callsAg_llandAc_llby hand (call Ag_ll; auto. call Ac_ll; auto=> />; rewrite dhkey_ll dt_ll dbits_ll);phoare_callfollowed byphoare_autocomputes through the code before the call and leaves an expectation, so the lossless part is oneislossless. - EC's
rnd f(an involution) isequiv_rnd f f.
op k: the length of a plaintext.
Instances For
clone import BitWord as Bits with op n <- k proof gt0_n by exact/gt0_k rename "word" as "bits" "dunifin" as "dbits"
Assumption: entropy smoothing #
EC's type hkey, op dhkey : { hkey distr | is_lossless dhkey } as dhkey_ll and
op hash : hkey -> group -> bits.
- dhkey : SubProbability hkey
- dhkey_ll : EC.is_lossless dhkey
- hash : hkey → group → bits
Instances
The ModuleTypeRep underlying AdvES, the module type declared by moduletype AdvES: the right-nested product of its 1 field types, in declaration order.
AdvES is by definition Module AdvES.typeRep.
Equations
Instances For
@[simp]: reading the field guess back off a module built from a record — AdvES.guess (AdvES.mk r) = r.guess.
It is what carries the right-hand side of an X.apply_simp (which is an AdvES.mk) on to the field the caller actually asked for, so that simp chains X.apply_simp into X.guess.apply_simp.
The field guess of a module of type AdvES: the projection onto component 0 of the right-nested tuple AdvES.typeRep, as a chain of Module.fst'/Module.snd'. Tagged @[module_accessor].
AdvES.guess.mk_simp reads this field back off a module built by AdvES.mk; AdvES.guess.utilities has the accessor as a module, and the lemmas about it.
Its parameters are named hk, h, in that order (recorded in @[gaudiProcParamNames], a ProcedureSignature holding only their types).
Instances For
The record of a module's fields: AdvES.structure m is AdvES.Structure.mk applied to AdvES.guess of m.
Inverse of AdvES.mk (AdvES.mk_destruct, AdvES.destruct_mk).
Instances For
The IsModule AdvES instance: AdvES is a module type, with representation AdvES.typeRep.
It is what lets the name AdvES stand where a module type is expected — in Module.Arr/Module.Prod (→ₘ/×ₘ), say — which the underlying Module AdvES.typeRep would do on its own but AdvES, a plain (non-reducible) def, would not.
Equations
- GaudisCrypt.Examples.HashedElGamal.EntropySmoothing.instIsModuleAdvES = { moduleTypeRep := GaudisCrypt.Examples.HashedElGamal.EntropySmoothing.AdvES.typeRep, isModule := ⋯ }
@[simp]: AdvES.structure (AdvES.mk r) = r — destructing a module built from a record gives that record back.
The module type declared by moduletype AdvES, with fields guess: the type Module AdvES.typeRep of modules that are a right-nested tuple of the field types.
Build one from a record of its fields with AdvES.mk, read a single field off one with the accessors AdvES.guess, and get the whole record back with AdvES.structure.
Equations
Instances For
Builds a module of type AdvES from the record AdvES.Structure of its fields, as a right-nested Module.pair'. @[reducible].
Inverse of AdvES.structure (AdvES.mk_destruct, AdvES.destruct_mk); a single field of a module built this way is read back by the @[simp] lemmas AdvES.guess.mk_simp.
Equations
- GaudisCrypt.Examples.HashedElGamal.EntropySmoothing.AdvES.mk theRecord✝ = theRecord✝.guess
Instances For
@[simp]: AdvES.mk (AdvES.structure m) = m — rebuilding a module from its own fields gives that module back.
What is derivable about the accessor AdvES.guess, bundled into one ModuleTypeUtilities (one name per field in the namespace, rather than one per fact):
AdvES.guess.utilities.accessorModule : AdvES →ₘ …— the accessor as a module, a projection being a module morphism;AdvES.guess.utilities.apply_simp—Module.app AdvES.guess.utilities.accessorModule m = AdvES.guess m: applying that module is the accessor;AdvES.guess.utilities.expression_eq— the same at the level of expressions:(AdvES.guess m).expression = (AdvES.guess.utilities.proj m.expression).reduce.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The record of the fields of a module of type AdvES: the fields guess, one per moduletype field, each of that field's own module type.
AdvES.mk turns such a record into a AdvES, AdvES.structure turns a AdvES back into one.
Instances For
Instantiating the holes of ES0.main.procedure with a tuple holeArgs of procedures: the body of proc main as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [ES0.main.procedure.apply_simp]).
@[simp]: applying ES0.main to the parameters proc main uses (A) is Module.proc (ES0.main.procedure.instantiate …) — the procedure with its holes filled by the callees they were made from, each written as it was in the body (with the arguments in place of the module parameters) and turned into a Procedure by Module.Proc.procedure.
@[simp]: applying ES0 to a tuple of its single parameter A — the record of its procedures ES0.main, each applied to the parameters it uses.
This is the lemma that unfolds a module use: simp rewrites with it, then with the field lemmas of the module type (N.f.mk_simp) to get at the one procedure the goal is about, and then with ES0.main.apply_simp to fill that procedure's holes.
The body of proc main of module ES0, as a procedure of its own: the one call it makes to a module parameter (A) is its single hole.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see ES0.main.procedure.apply_simp) rather than run. Use ES0.main for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The module declared by module ES0, abstracted over its single parameter A, which it takes as one right-nested tuple: Module.Arr (T₁ ×ₘ (… ×ₘ Tₙ)) M, with M the anonymous product of the procedures' own types, the declaration naming no module type.
Applied to such a tuple it is the record of its procedures ES0.main, each applied to the parameters that procedure itself uses — which is what the @[simp] lemma ES0.apply_simp says.
Equations
- One or more equations did not get rendered due to their size.
Instances For
proc main of module ES0 as a module, abstracted over the module parameters it uses (A, in declaration order): Module.Arr … (Module.Proc (procsig …)).
Apply it with the @[simp] lemma ES0.main.apply_simp, which fills the holes of ES0.main.procedure with the callees the body called.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The module declared by module ES1, abstracted over its single parameter A, which it takes as one right-nested tuple: Module.Arr (T₁ ×ₘ (… ×ₘ Tₙ)) M, with M the anonymous product of the procedures' own types, the declaration naming no module type.
Applied to such a tuple it is the record of its procedures ES1.main, each applied to the parameters that procedure itself uses — which is what the @[simp] lemma ES1.apply_simp says.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[simp]: applying ES1.main to the parameters proc main uses (A) is Module.proc (ES1.main.procedure.instantiate …) — the procedure with its holes filled by the callees they were made from, each written as it was in the body (with the arguments in place of the module parameters) and turned into a Procedure by Module.Proc.procedure.
Instantiating the holes of ES1.main.procedure with a tuple holeArgs of procedures: the body of proc main as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [ES1.main.procedure.apply_simp]).
The body of proc main of module ES1, as a procedure of its own: the one call it makes to a module parameter (A) is its single hole.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see ES1.main.procedure.apply_simp) rather than run. Use ES1.main for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
proc main of module ES1 as a module, abstracted over the module parameters it uses (A, in declaration order): Module.Arr … (Module.Proc (procsig …)).
Apply it with the @[simp] lemma ES1.main.apply_simp, which fills the holes of ES1.main.procedure with the callees the body called.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[simp]: applying ES1 to a tuple of its single parameter A — the record of its procedures ES1.main, each applied to the parameters it uses.
This is the lemma that unfolds a module use: simp rewrites with it, then with the field lemmas of the module type (N.f.mk_simp) to get at the one procedure the goal is about, and then with ES1.main.apply_simp to fill that procedure's holes.
Instantiating the holes of Hashed_ElGamal.kg.procedure with a tuple holeArgs of procedures: the body of proc kg as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [Hashed_ElGamal.kg.procedure.apply_simp]).
proc kg of module Hashed_ElGamal as a module: Module.proc Hashed_ElGamal.kg.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — Hashed_ElGamal.kg.apply_simp says exactly that.
Equations
Instances For
proc enc of module Hashed_ElGamal as a module: Module.proc Hashed_ElGamal.enc.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — Hashed_ElGamal.enc.apply_simp says exactly that.
Equations
Instances For
The body of proc enc of module Hashed_ElGamal, as a procedure of its own: it calls no module parameter, so it has no holes.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see Hashed_ElGamal.enc.procedure.apply_simp) rather than run. Use Hashed_ElGamal.enc for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instantiating the holes of Hashed_ElGamal.dec.procedure with a tuple holeArgs of procedures: the body of proc dec as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [Hashed_ElGamal.dec.procedure.apply_simp]).
@[simp]: Hashed_ElGamal.enc = Module.proc Hashed_ElGamal.enc.procedure — true by definition, proc enc using no module parameter and so having no holes to fill.
The body of proc dec of module Hashed_ElGamal, as a procedure of its own: it calls no module parameter, so it has no holes.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see Hashed_ElGamal.dec.procedure.apply_simp) rather than run. Use Hashed_ElGamal.dec for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instantiating the holes of Hashed_ElGamal.enc.procedure with a tuple holeArgs of procedures: the body of proc enc as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [Hashed_ElGamal.enc.procedure.apply_simp]).
The body of proc kg of module Hashed_ElGamal, as a procedure of its own: it calls no module parameter, so it has no holes.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see Hashed_ElGamal.kg.procedure.apply_simp) rather than run. Use Hashed_ElGamal.kg for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[simp]: Hashed_ElGamal.dec = Module.proc Hashed_ElGamal.dec.procedure — true by definition, proc dec using no module parameter and so having no holes to fill.
proc dec of module Hashed_ElGamal as a module: Module.proc Hashed_ElGamal.dec.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — Hashed_ElGamal.dec.apply_simp says exactly that.
Equations
Instances For
@[simp]: Hashed_ElGamal.kg = Module.proc Hashed_ElGamal.kg.procedure — true by definition, proc kg using no module parameter and so having no holes to fill.
The module declared by module Hashed_ElGamal: the record of its procedures Hashed_ElGamal.kg, Hashed_ElGamal.enc.
The declaration has no parameter list, so no procedure of it can call one either and the module is not a function — it is the plain record itself, and there is no Hashed_ElGamal.apply_simp to apply it with.
Equations
Instances For
The body of proc guess of module DDHAdv, as a procedure of its own: the 2 calls it makes to module parameters (A) are its holes, in the order the body makes them.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see DDHAdv.guess.procedure.apply_simp) rather than run. Use DDHAdv.guess for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[simp]: applying DDHAdv to a tuple of its single parameter A — the record of its procedures DDHAdv.guess, each applied to the parameters it uses.
This is the lemma that unfolds a module use: simp rewrites with it, then with the field lemmas of the module type (N.f.mk_simp) to get at the one procedure the goal is about, and then with DDHAdv.guess.apply_simp to fill that procedure's holes.
The module declared by module DDHAdv, abstracted over its single parameter A, which it takes as one right-nested tuple: Module.Arr (T₁ ×ₘ (… ×ₘ Tₙ)) M, with M the anonymous product of the procedures' own types, the declaration naming no module type.
Applied to such a tuple it is the record of its procedures DDHAdv.guess, each applied to the parameters that procedure itself uses — which is what the @[simp] lemma DDHAdv.apply_simp says.
Equations
Instances For
proc guess of module DDHAdv as a module, abstracted over the module parameters it uses (A, in declaration order): Module.Arr … (Module.Proc (procsig …)).
Apply it with the @[simp] lemma DDHAdv.guess.apply_simp, which fills the holes of DDHAdv.guess.procedure with the callees the body called.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[simp]: applying DDHAdv.guess to the parameters proc guess uses (A) is Module.proc (DDHAdv.guess.procedure.instantiate …) — the procedure with its holes filled by the callees they were made from, each written as it was in the body (with the arguments in place of the module parameters) and turned into a Procedure by Module.Proc.procedure.
Instantiating the holes of DDHAdv.guess.procedure with a tuple holeArgs of procedures: the body of proc guess as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [DDHAdv.guess.procedure.apply_simp]).
proc guess of module ESAdv as a module, abstracted over the module parameters it uses (A, in declaration order): Module.Arr … (Module.Proc (procsig …)).
Apply it with the @[simp] lemma ESAdv.guess.apply_simp, which fills the holes of ESAdv.guess.procedure with the callees the body called.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[simp]: applying ESAdv.guess to the parameters proc guess uses (A) is Module.proc (ESAdv.guess.procedure.instantiate …) — the procedure with its holes filled by the callees they were made from, each written as it was in the body (with the arguments in place of the module parameters) and turned into a Procedure by Module.Proc.procedure.
Instantiating the holes of ESAdv.guess.procedure with a tuple holeArgs of procedures: the body of proc guess as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [ESAdv.guess.procedure.apply_simp]).
@[simp]: applying ESAdv to a tuple of its single parameter A — the record of its procedures ESAdv.guess, each applied to the parameters it uses.
This is the lemma that unfolds a module use: simp rewrites with it, then with the field lemmas of the module type (N.f.mk_simp) to get at the one procedure the goal is about, and then with ESAdv.guess.apply_simp to fill that procedure's holes.
The module declared by module ESAdv, abstracted over its single parameter A, which it takes as one right-nested tuple: Module.Arr (T₁ ×ₘ (… ×ₘ Tₙ)) M, with M the anonymous product of the procedures' own types, the declaration naming no module type.
Applied to such a tuple it is the record of its procedures ESAdv.guess, each applied to the parameters that procedure itself uses — which is what the @[simp] lemma ESAdv.apply_simp says.
Equations
Instances For
The body of proc guess of module ESAdv, as a procedure of its own: the 2 calls it makes to module parameters (A) are its holes, in the order the body makes them.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see ESAdv.guess.procedure.apply_simp) rather than run. Use ESAdv.guess for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[simp]: applying Gb to a tuple of its single parameter A — the record of its procedures Gb.main, each applied to the parameters it uses.
This is the lemma that unfolds a module use: simp rewrites with it, then with the field lemmas of the module type (N.f.mk_simp) to get at the one procedure the goal is about, and then with Gb.main.apply_simp to fill that procedure's holes.
proc main of module Gb as a module, abstracted over the module parameters it uses (A, in declaration order): Module.Arr … (Module.Proc (procsig …)).
Apply it with the @[simp] lemma Gb.main.apply_simp, which fills the holes of Gb.main.procedure with the callees the body called.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The body of proc main of module Gb, as a procedure of its own: the 2 calls it makes to module parameters (A) are its holes, in the order the body makes them.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see Gb.main.procedure.apply_simp) rather than run. Use Gb.main for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instantiating the holes of Gb.main.procedure with a tuple holeArgs of procedures: the body of proc main as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [Gb.main.procedure.apply_simp]).
The module declared by module Gb, abstracted over its single parameter A, which it takes as one right-nested tuple: Module.Arr (T₁ ×ₘ (… ×ₘ Tₙ)) M, with M the anonymous product of the procedures' own types, the declaration naming no module type.
Applied to such a tuple it is the record of its procedures Gb.main, each applied to the parameters that procedure itself uses — which is what the @[simp] lemma Gb.apply_simp says.
Equations
Instances For
@[simp]: applying Gb.main to the parameters proc main uses (A) is Module.proc (Gb.main.procedure.instantiate …) — the procedure with its holes filled by the callees they were made from, each written as it was in the body (with the arguments in place of the module parameters) and turned into a Procedure by Module.Proc.procedure.
EC's local lemma cpa_ddh0 &m: Pr[CPA(Hashed_ElGamal,A).main() @ &m : res] = Pr[DDH0(DDHAdv(A)).main() @ &m : res].
EC's local lemma ddh1_es1 &m: Pr[DDH1(DDHAdv(A)).main() @ &m : res] = Pr[ES1(ESAdv(A)).main() @ &m : res].
EC's local lemma es0_Gb &m: Pr[ES0(ESAdv(A)).main() @ &m : res] = Pr[Gb.main()@ &m : res].
EC's local lemma Gb_half &m: Pr[Gb.main()@ &m : res] = 1%r/2%r.
EC's lemma conclusion &m : | Pr[CPA(Hashed_ElGamal,A).main() @ &m : res] - 1%r/2%r | <=
| Pr[DDH0(DDHAdv(A)).main() @ &m : res] - Pr[DDH1(DDHAdv(A)).main() @ &m : res] | + | Pr[ES0(ESAdv(A)).main() @ &m : res] - Pr[ES1(ESAdv(A)).main() @ &m : res]|`.