https://github.com/EasyCrypt/easycrypt
Raw File
Tip revision: b08103598cc92f1e561bd6970599ab1b031fa370 authored by François Dupressoir on 17 January 2020, 11:01:47 UTC
Masking the default dletE lemma more meaningful
Tip revision: b081035
PKE_CPA.eca
(* --------------------------------------------------------------------
 * Copyright (c) - 2012--2016 - IMDEA Software Institute
 * Copyright (c) - 2012--2018 - Inria
 * Copyright (c) - 2012--2018 - Ecole Polytechnique
 *
 * Distributed under the terms of the CeCILL-B-V1 license
 * -------------------------------------------------------------------- *)

require import Bool Core Int List.
require import DBool.

type pkey, skey, ptxt, ctxt.

module type Scheme = {
  proc kg() : pkey * skey
  proc enc(pk:pkey, m:ptxt) : ctxt
}.

module type Adversary = {
  proc choose(pk:pkey) : ptxt * ptxt
  proc guess(c:ctxt)   : bool
}.

module CPA (S:Scheme) (A:Adversary) = {
  proc main() : bool = {
    var pk, sk, m0, m1, c, b, b';

    (pk, sk) = S.kg();
    (m0, m1) = A.choose(pk);
    b        = ${0,1};
    c        = S.enc(pk, b ? m1 : m0);
    b'       = A.guess(c);
    return (b' = b);
  }
}.
back to top