Skip to content

feat(Protocols): Key exchange protocols and Diffie-Hellman#473

Open
ChristianoBraga wants to merge 1 commit intoleanprover:mainfrom
Beneficial-AI-Foundation:key_exchange_pr
Open

feat(Protocols): Key exchange protocols and Diffie-Hellman#473
ChristianoBraga wants to merge 1 commit intoleanprover:mainfrom
Beneficial-AI-Foundation:key_exchange_pr

Conversation

@ChristianoBraga
Copy link
Copy Markdown

Summary

  • Add a KeyExchangeProtocol class capturing the structure of key exchange with pub, sharedSecret, and an agreement property ensuring both parties compute the same shared secret.
  • Add Diffie-Hellman key exchange as an instance over commutative groups, with helper lemmas pow_mod_q and secret_eq.

New files

  • Cslib/Systems/Distributed/Protocols/Cryptographic/KeyExchange/Basic.lean — Key exchange class
  • Cslib/Systems/Distributed/Protocols/Cryptographic/KeyExchange/Diffie-Hellman.lean — Diffie-Hellman instance

References

  • Boneh & Shoup, A Graduate Course in Applied Cryptography, Section 10.4

Test plan

  • lake build passes with no errors
  • CI workflow succeeds

Add KeyExchangeProtocol class with agreement property and
Diffie-Hellman as an instance over commutative groups.
@@ -0,0 +1,99 @@
/-
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This file doesn't build because Diffie-Hellman.lean isn't a valid module name.

Copy link
Copy Markdown
Contributor

@SamuelSchlesinger SamuelSchlesinger left a comment

Choose a reason for hiding this comment

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

Overall, it appears the author did not build this to ensure it worked locally, so there are several issues. I tried to give a thorough review despite this.

Let G := {gᵃ : a = 0, …, q − 1}, so that G is a subset of ℤₚ* of cardinality q. It is not hard
to see that G is closed under multiplication and inversion; that is, for all u, v ∈ G,
we have u·v ∈ G and u⁻¹ ∈ G. Indeed, gᵃ · gᵇ = gᵃ⁺ᵇ = gᶜ with c := (a + b) mod q, and (gᵃ)⁻¹ = gᵈ
with d := (−a) mod q. In the language of algebra, G is called a subgroup of the group ℤₚ*.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The module documentation describes a specific cryptographic setup with primes p, q, and a subgroup of ℤₚ*, but this instance is for any CommGroup G, any g : G, and any q : ℕ. The documentation should say the formalization only models the agreement equation, not the full DH setup/security assumptions. It should also be as general as the definition.

agreement := by
intro α β
show (g ^ β.val) ^ α.val = (g ^ α.val) ^ β.val
rw [← pow_mul, ← pow_mul, mul_comm]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This proves the algebraic agreement equation for exponentiation in a commutative group, but it is
more general and weaker than the Diffie-Hellman setup described in the module documentation. The
instance does not encode that G is a cyclic subgroup of order q, that g has order q, that q is
prime, or that public values live in the subgroup generated by g. If this is intended as a
formalization of Diffie-Hellman, those parameters and invariants should be represented explicitly.
Otherwise, the documentation should describe this as the exponentiation-based key-agreement
skeleton rather than the Diffie-Hellman protocol.

Reference:

* [D. Boneh and V. Shoup,V., *A Graduate Course in Applied Cryptography*, One-time pad][BonehShoup],
Section 10.4.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is incorrect, referencing the one-time pad not DH.


Reference:

* [D. Boneh and V. Shoup,V., *A Graduate Course in Applied Cryptography*][BonehShoup],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This citation is missing from the references.bib.

Section 10.4.
-/

instance DiffieHellmanKE {G : Type u} [CommGroup G] (g : G) (q : ℕ) :
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should not be an instance. The instance is not actually synthesizable after I renamed it on my end. Just make it a struct and a def.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should also be in a namespace.


universe u v w

class KeyExchangeProtocol
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should define this in a namespace, not in the root. This is true across the whole file.

omit [Fact q.Prime] in
theorem secret_eq (α β : ZMod q) :
(g ^ β.val) ^ α.val = g ^ (α * β).val := by
rw [← pow_mul, ZMod.val_mul, mul_comm β.val α.val, pow_mod_q hG]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fact q.Prime appears to be dead code.

Copy link
Copy Markdown
Collaborator

@chenson2018 chenson2018 left a comment

Choose a reason for hiding this comment

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

Hi @ChristianoBraga, thanks for your interest in contributing! Can I ask that you disclose any AI usage in the PR description? There seem to be some patterns of AI usage based on the review that was just left.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants