One-time pad: perfect secrecy against any adversary #
The adversary picks a message m, sees a ciphertext and guesses a bit. In the real game the
ciphertext is m + k for a fresh uniform key k; in the ideal game it is uniform, independent
of m. The two games are equivalent for every adversary (real_ideal), so the adversary's
guess has the same distribution in both (real_ideal_Pr).
Not an EasyCrypt file; written as one would be:
type msg. (* a finite group, written additively *)
module type Adversary = {
proc choose() : msg
proc guess(c : msg) : bool
}.
module Real(A : Adversary) = {
proc main() : bool = {
var m, k, c, b;
m <@ A.choose();
k <$ dmsg;
c <- m + k;
b <@ A.guess(c);
return b;
}
}.
module Ideal(A : Adversary) = {
proc main() : bool = {
var m, c, b;
m <@ A.choose();
c <$ dmsg;
b <@ A.guess(c);
return b;
}
}.
section.
declare module A <: Adversary.
equiv real_ideal : Real(A).main ~ Ideal(A).main : ={glob A} ==> ={res, glob A}.
proof.
proc.
call (_ : true); wp.
rnd (fun k => m{1} + k) (fun c => c - m{1}).
call (_ : true).
by auto.
qed.
lemma real_ideal_Pr &m :
Pr[Real(A).main() @ &m : res] = Pr[Ideal(A).main() @ &m : res].
proof. by byequiv real_ideal. qed.
end section.
No assumption on the adversary: its procedures run on their own locals and globals, and the
games' variables that differ (k, c) are local to main.
The theory's type: the messages (and keys and ciphertexts), a finite group.
Instances
The uniform distribution on messages.
Instances For
The ModuleTypeRep underlying Adversary, the module type declared by moduletype Adversary: the right-nested product of its 2 field types, in declaration order.
Adversary is by definition Module Adversary.typeRep.
Equations
Instances For
The record of a module's fields: Adversary.structure m is Adversary.Structure.mk applied to Adversary.choose, Adversary.guess of m.
Inverse of Adversary.mk (Adversary.mk_destruct, Adversary.destruct_mk).
Instances For
The field guess of a module of type Adversary: the projection onto component 1 of the right-nested tuple Adversary.typeRep, as a chain of Module.fst'/Module.snd'. Tagged @[module_accessor].
Adversary.guess.mk_simp reads this field back off a module built by Adversary.mk; Adversary.guess.utilities has the accessor as a module, and the lemmas about it.
Its parameters are named c, in that order (recorded in @[gaudiProcParamNames], a ProcedureSignature holding only their types).
Equations
- theModule✝.guess = GaudisCrypt.Module.snd' theModule✝
Instances For
The module type declared by moduletype Adversary, with fields choose, guess: the type Module Adversary.typeRep of modules that are a right-nested tuple of the field types.
Build one from a record of its fields with Adversary.mk, read a single field off one with the accessors Adversary.choose, Adversary.guess, and get the whole record back with Adversary.structure.
Equations
Instances For
Builds a module of type Adversary from the record Adversary.Structure of its fields, as a right-nested Module.pair'. @[reducible].
Inverse of Adversary.structure (Adversary.mk_destruct, Adversary.destruct_mk); a single field of a module built this way is read back by the @[simp] lemmas Adversary.choose.mk_simp, Adversary.guess.mk_simp.
Equations
- GaudisCrypt.Examples.OTP.Adversary.mk theRecord✝ = GaudisCrypt.Module.pair' theRecord✝.choose theRecord✝.guess
Instances For
@[simp]: Adversary.structure (Adversary.mk r) = r — destructing a module built from a record gives that record back.
The IsModule Adversary instance: Adversary is a module type, with representation Adversary.typeRep.
It is what lets the name Adversary stand where a module type is expected — in Module.Arr/Module.Prod (→ₘ/×ₘ), say — which the underlying Module Adversary.typeRep would do on its own but Adversary, a plain (non-reducible) def, would not.
Equations
- GaudisCrypt.Examples.OTP.instIsModuleAdversary = { moduleTypeRep := GaudisCrypt.Examples.OTP.Adversary.typeRep, isModule := ⋯ }
What is derivable about the accessor Adversary.choose, bundled into one ModuleTypeUtilities (one name per field in the namespace, rather than one per fact):
Adversary.choose.utilities.accessorModule : Adversary →ₘ …— the accessor as a module, a projection being a module morphism;Adversary.choose.utilities.apply_simp—Module.app Adversary.choose.utilities.accessorModule m = Adversary.choose m: applying that module is the accessor;Adversary.choose.utilities.expression_eq— the same at the level of expressions:(Adversary.choose m).expression = (Adversary.choose.utilities.proj m.expression).reduce.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The field choose of a module of type Adversary: the projection onto component 0 of the right-nested tuple Adversary.typeRep, as a chain of Module.fst'/Module.snd'. Tagged @[module_accessor].
Adversary.choose.mk_simp reads this field back off a module built by Adversary.mk; Adversary.choose.utilities has the accessor as a module, and the lemmas about it.
It takes no parameters (recorded in @[gaudiProcParamNames]).
Equations
- theModule✝.choose = GaudisCrypt.Module.fst' theModule✝
Instances For
What is derivable about the accessor Adversary.guess, bundled into one ModuleTypeUtilities (one name per field in the namespace, rather than one per fact):
Adversary.guess.utilities.accessorModule : Adversary →ₘ …— the accessor as a module, a projection being a module morphism;Adversary.guess.utilities.apply_simp—Module.app Adversary.guess.utilities.accessorModule m = Adversary.guess m: applying that module is the accessor;Adversary.guess.utilities.expression_eq— the same at the level of expressions:(Adversary.guess m).expression = (Adversary.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 Adversary: the fields choose, guess, one per moduletype field, each of that field's own module type.
Adversary.mk turns such a record into a Adversary, Adversary.structure turns a Adversary back into one.
Instances For
@[simp]: reading the field guess back off a module built from a record — Adversary.guess (Adversary.mk r) = r.guess.
It is what carries the right-hand side of an X.apply_simp (which is an Adversary.mk) on to the field the caller actually asked for, so that simp chains X.apply_simp into X.guess.apply_simp.
@[simp]: Adversary.mk (Adversary.structure m) = m — rebuilding a module from its own fields gives that module back.
@[simp]: reading the field choose back off a module built from a record — Adversary.choose (Adversary.mk r) = r.choose.
It is what carries the right-hand side of an X.apply_simp (which is an Adversary.mk) on to the field the caller actually asked for, so that simp chains X.apply_simp into X.choose.apply_simp.
@[simp]: applying Real.main to the parameters proc main uses (A) is Module.proc (Real.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.
The body of proc main of module Real, 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 Real.main.procedure.apply_simp) rather than run. Use Real.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 Real, 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 Real.main, each applied to the parameters that procedure itself uses — which is what the @[simp] lemma Real.apply_simp says.
Equations
Instances For
proc main of module Real 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 Real.main.apply_simp, which fills the holes of Real.main.procedure with the callees the body called.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instantiating the holes of Real.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 [Real.main.procedure.apply_simp]).
@[simp]: applying Real to a tuple of its single parameter A — the record of its procedures Real.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 Real.main.apply_simp to fill that procedure's holes.
Instantiating the holes of Ideal.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 [Ideal.main.procedure.apply_simp]).
The module declared by module Ideal, 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 Ideal.main, each applied to the parameters that procedure itself uses — which is what the @[simp] lemma Ideal.apply_simp says.
Equations
Instances For
The body of proc main of module Ideal, 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 Ideal.main.procedure.apply_simp) rather than run. Use Ideal.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 Ideal 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 Ideal.main.apply_simp, which fills the holes of Ideal.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 Ideal.main to the parameters proc main uses (A) is Module.proc (Ideal.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 Ideal to a tuple of its single parameter A — the record of its procedures Ideal.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 Ideal.main.apply_simp to fill that procedure's holes.
Perfect secrecy: the real and the ideal game are equivalent, for every adversary.
Perfect secrecy, as probabilities: the guess has the same distribution in the two games.