[cryptolib] generalize PRF definitions, PRP<->PRF#1028
Conversation
ed8d40e to
39abad4
Compare
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.
| (* 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. |
There was a problem hiding this comment.
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.)
| @@ -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. | |||
| 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. |
There was a problem hiding this comment.
These look like they could belong in FMap.
|
@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?
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 |
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.