Theory Pairing

theory Pairing 

imports  "CryptHOL.CryptHOL" "CryptHOL.Cyclic_Group" Berlekamp_Zassenhaus.Finite_Field
  "Sigma_Commit_Crypto.Cyclic_Group_Ext" "HOL-Number_Theory.Cong"
begin

section ‹Pairings›

hide_const Polynomial.order

text‹We formalize symmetric pairings for cryptography following the textbook
``A Graduate Course in Applied Cryptography'' by Boneh and Shoup citeBonehShoup.›

locale pairing =
Gp : cyclic_group Gp + GT : cyclic_group GT 
for Gp :: "('a, 'b) cyclic_group_scheme" (structure) 
and GT:: "('c, 'd) cyclic_group_scheme"  (structure) 
+
fixes p::int
  and e
assumes
p_prime : "prime p" and
CARD_Gp: "int (order Gp) = p" and
CARD_GT: "int (order GT) = p" and
e_symmetric: "e  carrier Gp  carrier Gp  carrier GT" and 
e_bilinearity[simp]: "a b::int . P Q. P  carrier Gp  Q  carrier Gp  
   e (P [^]Gpa) (Q [^]Gpb) 
= (e P Q) [^]GT(a*b)" and 
e_non_degeneracy[simp]: "¬(P Q. P  carrier Gp  Q  carrier Gp  e P Q = 𝟭GT)"
begin

text ‹The pairing function e is linear in the first component›
lemma e_linear_in_fst: 
  assumes "P  carrier Gp  Q  carrier Gp"
  shows "e (P [^]Gp(a::int)) Q = (e P Q) [^]GTa"
proof -
  have "e (P [^]Gpa) Q = e (P [^]Gpa) (Q [^]Gp(1::int))" using assms by simp
  also have "... = (e P Q) [^]GT(a*(1::int))" using assms e_bilinearity by fast
  also have "=(e P Q) [^]GTa" by simp
  finally show "e (P [^]Gpa) Q = (e P Q) [^]GTa" .
qed

text ‹The pairing function e is linear in the second component›
lemma e_linear_in_snd: 
  assumes "P  carrier Gp  Q  carrier Gp"
  shows "e P (Q [^]Gp(a::int)) = (e P Q) [^]GTa"
proof -
  have "e P (Q  [^]Gpa) = e (P [^]Gp(1::int)) (Q [^]Gpa)" using assms by simp
  also have "... = (e P Q) [^]GT((1::int)*a)" using assms e_bilinearity by fast
  also have "=(e P Q) [^]GTa" by simp
  finally show "e P (Q [^]Gpa) = (e P Q) [^]GTa" .
qed

lemma addition_in_exponents_on_e[simp]: 
  assumes "x  carrier Gp  y  carrier Gp "
  shows "(e x y) [^]GT(a::int) GT(e x y) [^]GT(b::int) = (e x y) [^]GT(a+b)"
  by (metis GT.int_pow_mult assms PiE e_symmetric)

text ‹this follows from non-degeneracy›
lemma e_from_generators_ne_1: "e gGpgGp 𝟭GT⇙"
proof 
  assume asm: "e gGpgGp= 𝟭GT⇙"
  have "P Q. P  carrier Gp  Q  carrier Gp  e P Q = 𝟭GT⇙" 
  proof(intro allI)
    fix P Q
    show "P  carrier Gp  Q  carrier Gp  e P Q = 𝟭GT⇙ "
    proof 
      assume "P  carrier Gp  Q  carrier Gp"
      then obtain p q::int where "gGp[^]Gpp = P  gGp[^]Gpq = Q"
        by (metis Gp.generatorE int_pow_int)
      then have "e P Q = e (gGp[^]Gpp) (gGp[^]Gpq)"
        by blast
      also have " = e gGpgGp[^]GT(p*q)"
        by force
      also have " =  𝟭GT[^]GT(p*q)"
        using asm by argo
      also have " =  𝟭GT⇙"
        by fastforce
      finally show "e P Q = 𝟭GT⇙" .
    qed
  qed
  then show "False" using e_non_degeneracy by blast
qed

lemma e_g_g_in_carrier_GT[simp]: "e gGpgGp carrier GT"
  using e_symmetric by fast

text ‹mod relations on the exponent (typically useful for cryptographic proofs)›

lemma pow_on_eq_card_GT[simp]: "(gGT[^]GT(x::int) = gGT[^]GT(y::int)) = ([x= y] (mod p))"
 by (metis (no_types, lifting) CARD_GT GT.finite_carrier GT.gen_power_0 GT.generator_closed GT.int_pow_eq GT.ord_ge_1 GT.ord_le_group_order GT.pow_ord_eq_1 One_nat_def add_diff_inverse_nat arith_extra_simps(6) cong_iff_dvd_diff diff_is_0_eq' less_eq_Suc_le
      zero_order(5))

lemma pow_on_eq_card_GT_carrier_ext'[simp]: 
  "((e gGpgGp)) [^]GTx = ((e gGpgGp)) [^]GTy  [x= y] (mod p)"
  by (metis CARD_GT GT.finite_carrier GT.int_pow_eq GT.ord_dvd_group_order GT.ord_eq_1 GT.ord_id GT.pow_ord_eq_ord_iff GT.pow_order_eq_1 cong_iff_dvd_diff dvd_antisym e_from_generators_ne_1 e_g_g_in_carrier_GT p_prime prime_imp_coprime prime_nat_int_transfer)

end

end