Skip to content

[cryptolib] generalize PRF definitions, PRP<->PRF#1028

Draft
fdupress wants to merge 1 commit into
mainfrom
prf-generalise
Draft

[cryptolib] generalize PRF definitions, PRP<->PRF#1028
fdupress wants to merge 1 commit into
mainfrom
prf-generalise

Conversation

@fdupress

@fdupress fdupress commented Jun 3, 2026

Copy link
Copy Markdown
Member

This generalises the definition of PRFs to not require keygen to sample from a distribution, and to not require a deterministic PRF. This (standard but relatively) specialist definition can be recovered when instantiating with a concrete PRF.

This is a breaking change.

@fdupress fdupress self-assigned this Jun 3, 2026
@fdupress fdupress force-pushed the prf-generalise branch 3 times, most recently from ed8d40e to 39abad4 Compare June 19, 2026 17:41
This takes a swipe at cleaning up the PRF and PRP theories, as well as
the associated switching lemmas. This should bring them more in line
with modern EasyCrypt practice while also making them better examples of
modern EasyCrypt development themselves—perhaps serving as advanced
tutorials.
Comment on lines +173 to +189
(* FIXME: lift out and share with Strong RP RF *)
local lemma notin_supportIP (P : 'a -> bool) (d : 'a distr):
(exists a, support d a /\ !P a) <=> mu d P < mu d predT.
proof.
rewrite (mu_split _ predT P) /predI /predT /predC /=.
rewrite (exists_eq (fun a => support d a /\ !P a) (fun a => !P a /\ a \in d)) /=.
+ by move=> a /=; rewrite andbC.
by rewrite -(witness_support (predC P)) -/(predC _) /#.
qed.

local lemma excepted_lossless (m:(D,D) fmap):
(exists x, x \notin m) =>
mu (dD \ (rng m)) predT = 1%r.
proof.
move=> /endo_dom_rng [x h]; rewrite dexcepted_ll // 1:dD_ll.
by rewrite -dD_ll; apply: notin_supportIP; exists x; rewrite dD_fu.
qed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lift these out to a reasonable place. The first seems OK in distribution or in conditional. The second is specialised to endomaps... Perhaps sitting alongside the random permutation definition? (The lemma is key to proving losslessness.)

Comment on lines 241 to 256
@@ -130,447 +249,181 @@ qed.

lemma excepted_lossless (m:(D,D) fmap):
(exists x, x \notin m) =>
mu (uD \ (rng m)) predT = 1%r.
mu (dD \ (rng m)) predT = 1%r.
proof.
move=> /endo_dom_rng [x h]; rewrite dexcepted_ll //.
+ smt(uD_uf_fu).
have [?[<- @/is_full Hsupp]]:= uD_uf_fu.
apply/notin_supportIP;exists x => />;apply Hsupp.
move=> /endo_dom_rng [x h]; rewrite dexcepted_ll // 1:dD_ll.
by rewrite -dD_ll; apply: notin_supportIP; exists x; rewrite dD_fu.
qed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

Comment on lines +258 to 270
local lemma rng_set_subset_rngU1 (m : ('a, 'b) fmap) (x : 'a) y:
forall z, rng m.[x <- y] z => predU (rng m) (pred1 y) z.
proof.
proc; seq 1: (exists x, support uD x /\ !X x)=> //=.
+ by rnd (predT); skip; smt(uD_uf_fu).
if=> //=.
+ rnd (predT); skip.
move=> /> &0; rewrite dexceptedE predTI mu_not.
move=> x x_in_uD x_notin_X r_in_X.
apply/mulrV/ltr0_neq0/subr_gt0/notin_supportIP.
by exists x.
by hoare; rnd=> //=; skip=> &hr ->.
move=> z; rewrite /predU /pred1 /= (rngE m.[_ <- _])=> /= - [] x0.
rewrite get_setE; case: (x0 = x)=> |> _ m_x0; left; rewrite rngE /=.
by exists x0.
qed.

lemma PRPi'_Indirect_f_ll: islossless PRPi'(Indirect).f.
local lemma frng_set_subset_rngU1 (m : ('a, 'b) fmap) (x : 'a) y:
frng m.[x <- y] \subset frng m `|` fset1 y.
proof.
proc; if=> //=; auto; call Indirect_ll.
skip=> /> &hr x_notin_m.
have [x0] x0_notinr_m := endo_dom_rng PRPi.m{hr} _; first by exists x{hr}.
by exists x0; rewrite x0_notinr_m /=; smt(uD_uf_fu).
by move=> z; rewrite in_fsetU1 !mem_frng=> /rng_set_subset_rngU1.
qed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look like they could belong in FMap.

@fdupress

Copy link
Copy Markdown
Member Author

@ahuelsing and @mbbarbosa does this change (also to the PRP-PRF switching lemma and its weak version) look like it's going in the right direction, in terms of making the libraries more usable in a broader variety of contexts?

  • PRP and PRF definitions do not assume a distribution over keys, or that the PRF/PRP is deterministic and stateless;
  • the switching lemmas no longer require the number of queries to be bounded at cloning time, and no longer require the user to bound the number of queries. (See the fix for the SHA3 proof, for example.)

I think I should also generalise over the input type of the distinguisher. (Generalising over the distringuisher's output type then also requires generalising over the event, and that degrades usability again, I think.)

Once the API is firmed up, I'll clear up any leftover internal gunk, add docgen strings and make a formatting pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant