Kem.lean
Declarations on this page (33)
- class kemPk
- structure SubF
- instance L43
- instance L44
-
def SubF.
length - structure SubF
- instance L56
- instance L57
-
def SubF.
length - structure SubF
- instance L69
- instance L70
-
def SubF.
length - structure SubF
- instance L83
- instance L87
- instance L99
- instance L100
- instance L101
-
def SubF.
length - #combine L109
-
abbrev Pk.
SubF. pack -
abbrev Encap.
SubF. pack -
abbrev SharedSecret.
SubF. pack -
abbrev RejKey.
SubF. pack - instance L122
- def invertKemPublicKey
-
def kemPk.
attackerKnowledge -
def kemEncapCipher.
attackerKnowledge -
def kemEncapSS.
attackerKnowledge -
def kemDecap.
attackerKnowledge -
def kemRejKey.
attackerKnowledge - #combine L167
Post-Quantum KEM Equational Theory
DyLean term algebra and attacker deduction rules for Kyber-1024 / ML-KEM-1024. SharedSecret binds the target public key pk alongside entropy, kemDecap returns none on mismatch, and kemRejKey models Kyber-1024 round-3 secret-keyed implicit rejection.
namespace DY.PQKemclass kemPk
public
class CanPQKem.{u} (Bytes: Type u) where
kemPk: (sk: Bytes) → Bytes
kemEncap: (pk: Bytes) → (entropy: Bytes) → Bytes × Bytes
kemDecap: (sk: Bytes) → (cipher: Bytes) → Err Bytes
/-- Kyber-1024 implicit-rejection key derived from `sk` and `cipher`. -/
kemRejKey: (sk: Bytes) → (cipher: Bytes) → Bytesstructure SubF
1568-byte KEM public key kemPk sk.
public structure SubF (Bytes: Type) where
sk: Bytes
def SubF.
@[expose] public def SubF.length [BytesFunctor]: Bytes.PartialLength SubF := fun _ _ => 1568end Pknamespace Encapstructure SubF
1568-byte KEM ciphertext encapsulated to pk with randomness entropy.
public structure SubF (Bytes: Type) where
pk: Bytes
entropy: Bytesinstance
public instance: ALaCarte.FunctorSizeOf SubF := .binary SubF.pk SubF.entropyinstance
public instance: SubBytesFunctor SubF := .binary SubF.pk SubF.entropy SubF.mk
def SubF.
@[expose] public def SubF.length [BytesFunctor]: Bytes.PartialLength SubF := fun _ _ => 1568end Encapnamespace SharedSecretinstance
public instance: ALaCarte.FunctorSizeOf SubF := .binary SubF.pk SubF.entropyinstance
public instance: SubBytesFunctor SubF := .binary SubF.pk SubF.entropy SubF.mkend SharedSecretnamespace RejKeystructure SubF
32-byte Kyber-1024 implicit-rejection key derived from sk and cipher.
public
structure SubF (Bytes: Type) where
sk: Bytes
cipher: Bytesinstance
instance
public
instance: ALaCarte.Representable SubF where
CtorId := Unit
ctors | () => { Data := Unit, nRec := 2 }
toRepr | {sk, cipher} => { id := (), data := (), as := #v[sk, cipher] }
fromRepr
| {id, data, as} => { sk := as[0], cipher := as[1] }
from_to a✝:Typesk:a✝cipher:a✝⊢ (match
match { sk := sk, cipher := cipher } with
| { sk := sk, cipher := cipher } => { id := (), data := (), as := #v[sk, cipher] } with
| { id := id, data := data, as := as } => { sk := as[0], cipher := as[1] }) =
{ sk := sk, cipher := cipher } a✝:Typesk:a✝cipher:a✝⊢ (match
match { sk := sk, cipher := cipher } with
| { sk := sk, cipher := cipher } => { id := (), data := (), as := #v[sk, cipher] } with
| { id := id, data := data, as := as } => { sk := as[0], cipher := as[1] }) =
{ sk := sk, cipher := cipher } All goals completed! 🐙
to_from
a✝:Typeid:Unitdata:{ Data := Unit, nRec := 2 }.Dataas:Vector a✝ { Data := Unit, nRec := 2 }.nRec⊢ (match
match { id := id, data := data, as := as } with
| { id := id, data := data, as := as } => { sk := as[0], cipher := as[1] } with
| { sk := sk, cipher := cipher } => { id := (), data := (), as := #v[sk, cipher] }) =
{ id := id, data := data, as := as } a✝:Typeid:Unitdata:{ Data := Unit, nRec := 2 }.Dataas:Vector a✝ { Data := Unit, nRec := 2 }.nRec⊢ (match
match { id := id, data := data, as := as } with
| { id := id, data := data, as := as } => { sk := as[0], cipher := as[1] } with
| { sk := sk, cipher := cipher } => { id := (), data := (), as := #v[sk, cipher] }) =
{ id := id, data := data, as := as } a✝:Typeid:Unitdata:{ Data := Unit, nRec := 2 }.Dataas:Vector a✝ { Data := Unit, nRec := 2 }.nRec⊢ #[as[0], as[1]] = as.toArray a✝:Typeid:Unitdata:{ Data := Unit, nRec := 2 }.Dataas:Vector a✝ { Data := Unit, nRec := 2 }.nRec⊢ #[as[0], as[1]] = as.toArray All goals completed! 🐙
sizeOf_eq a✝:Typeinst✝:SizeOf a✝sk:a✝cipher:a✝⊢ ALaCarte.FunctorSizeOf.sizeOf { sk := sk, cipher := cipher } =
ALaCarte.FunctorSizeOf.sizeOf
(match { sk := sk, cipher := cipher } with
| { sk := sk, cipher := cipher } => { id := (), data := (), as := #v[sk, cipher] }) a✝:Typeinst✝:SizeOf a✝sk:a✝cipher:a✝⊢ ALaCarte.FunctorSizeOf.sizeOf { sk := sk, cipher := cipher } =
ALaCarte.FunctorSizeOf.sizeOf
(match { sk := sk, cipher := cipher } with
| { sk := sk, cipher := cipher } => { id := (), data := (), as := #v[sk, cipher] }) All goals completed! 🐙instance
public instance: ALaCarte.RepresentableDecidableEq SubF whereinstance
public instance: ALaCarte.RepresentableOrd SubF whereinstance
public instance: SubBytesFunctor SubF where
def SubF.
@[expose] public
def SubF.length [BytesFunctor]: Bytes.PartialLength SubF :=
fun _ _ => 32end RejKey#combine
#combine into BytesFunctor, BytesLength from
Pk,
Encap,
SharedSecret,
RejKey,variable [BytesFunctor] [BytesFunctor.Has SubF]
abbrev Pk.
public abbrev Pk.SubF.pack (x: Pk.SubF Bytes) := BytesView.pack x
abbrev Encap.
public abbrev Encap.SubF.pack (x: Encap.SubF Bytes) := BytesView.pack x
abbrev RejKey.
public abbrev RejKey.SubF.pack (x: RejKey.SubF Bytes) := BytesView.pack xinstance
public
instance: CanPQKem Bytes where
kemPk sk := ({sk}: Pk.SubF Bytes).pack
kemEncap pk entropy :=
(({pk, entropy}: Encap.SubF Bytes).pack, ({pk, entropy}: SharedSecret.SubF Bytes).pack)
kemDecap sk cipher :=
match cipher.view? Encap.SubF with
| some { pk, entropy } =>
match pk.view? Pk.SubF with
| some { sk := sk' } =>
if sk = sk' then some ({pk, entropy}: SharedSecret.SubF Bytes).pack else none
| none => none
| none => none
kemRejKey sk cipher := ({sk, cipher}: RejKey.SubF Bytes).packdef invertKemPublicKey
def kemPk.
@[expose] public
def kemPk.attackerKnowledge: SubAttackerKnowledge SubF where
pred p out := ∃ sk, out = kemPk sk ∧ p sk
def kemEncapCipher.
@[expose] public
def kemEncapCipher.attackerKnowledge: SubAttackerKnowledge SubF where
pred p out := ∃ pk entropy rhs, (out, rhs) = kemEncap pk entropy ∧ p pk ∧ p entropy
def kemEncapSS.
@[expose] public
def kemEncapSS.attackerKnowledge: SubAttackerKnowledge SubF where
pred p out := ∃ pk entropy lhs, (lhs, out) = kemEncap pk entropy ∧ p pk ∧ p entropy
def kemDecap.
@[expose] public
def kemDecap.attackerKnowledge: SubAttackerKnowledge SubF where
pred p out := ∃ sk cipher, some out = kemDecap sk cipher ∧ p sk ∧ p cipher
def kemRejKey.
@[expose] public
def kemRejKey.attackerKnowledge: SubAttackerKnowledge SubF where
pred p out := ∃ sk cipher, out = kemRejKey sk cipher ∧ p sk ∧ p cipher#combine
#combine [BytesFunctor.Has SubF] into attackerKnowledge' from
kemPk,
kemEncapCipher,
kemEncapSS,
kemDecap,
kemRejKey,end DY.PQKem