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 cite‹BonehShoup›.›

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 [^]⇘Gp⇙ a) (Q [^]⇘Gp⇙ b) 
= (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) [^]⇘GT⇙ a"
proof -
  have "e (P [^]⇘Gp⇙ a) Q = e (P [^]⇘Gp⇙ a) (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) [^]⇘GT⇙ a" by simp
  finally show "e (P [^]⇘Gp⇙ a) Q = (e P Q) [^]⇘GT⇙ a" .
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) [^]⇘GT⇙ a"
proof -
  have "e P (Q  [^]⇘Gp⇙ a) = e (P [^]⇘Gp⇙ (1::int)) (Q [^]⇘Gp⇙ a)" using assms by simp
  also have "... = (e P Q) [^]⇘GT⇙ ((1::int)*a)" using assms e_bilinearity by fast
  also have "…=(e P Q) [^]⇘GT⇙ a" by simp
  finally show "e P (Q [^]⇘Gp⇙ a) = (e P Q) [^]⇘GT⇙ a" .
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 g⇘Gp⇙ g⇘Gp⇙ ≠ 𝟭⇘GT⇙"
proof 
  assume asm: "e g⇘Gp⇙ g⇘Gp⇙ = 𝟭⇘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 "g⇘Gp⇙ [^]⇘Gp⇙ p = P ∧ g⇘Gp⇙ [^]⇘Gp⇙ q = Q"
        by (metis Gp.generatorE int_pow_int)
      then have "e P Q = e (g⇘Gp⇙ [^]⇘Gp⇙ p) (g⇘Gp⇙ [^]⇘Gp⇙ q)"
        by blast
      also have "… = e g⇘Gp⇙ g⇘Gp⇙ [^]⇘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 g⇘Gp⇙ g⇘Gp⇙ ∈ 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]: "(g⇘GT⇙ [^]⇘GT⇙ (x::int) = g⇘GT⇙ [^]⇘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 g⇘Gp⇙ g⇘Gp⇙)) [^]⇘GT⇙ x = ((e g⇘Gp⇙ g⇘Gp⇙)) [^]⇘GT⇙ y ⟷ [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