Cryptobox Scheme Definitions #
Abstract type definitions and scheme records for NaCl's Cryptobox construction. Cryptobox combines a Non-Interactive Key Exchange (NIKE, e.g., X25519) with a Nonce-Based Symmetric Encryption Scheme (NBSES, e.g., XSalsa20-Poly1305) to achieve Public-Key Authenticated Encryption (PKAE).
Main definitions #
NBSES— Nonce-based symmetric encryption scheme (enc/dec with shared key + nonce)NIKEScheme— Non-interactive key exchange (pkgen + deterministic shared key derivation)KeyInjection— Injection between NIKE and NBSES key spacesSID— Session identifier (canonical pair of public keys)sortSID— Canonical ordering for session IDs
Design choices #
Following the Rocq SSProve Cryptobox (nominal-ssprove), all key types (PK, SK,
SharedKey) are Fintype to enable uniform sampling. Messages and ciphertexts
are also Fintype for simplicity (the Rocq version uses choice_type which
allows infinite types, but Lean's SPComp.sample requires Fintype).
All scheme operations are pure SPComp computations (no state). State is
introduced only in the game definitions (PKEY, KEY, SAE, etc.).
References #
- Dupressoir et al., "Bringing SSP to EasyCrypt — A Security Proof for Cryptobox" (CSF 2022)
- Myssenburg et al., Rocq SSProve Cryptobox (nominal-ssprove)
- Bernstein, Lange, Schwabe, "NaCl: Networking and Cryptography library"
Abstract types #
These are parameters throughout the Cryptobox formalization. Each file will declare the necessary variables.
Abstract type bundle for Cryptobox. All types are finite (for uniform sampling) and have decidable equality (for map lookups and equality checks in games).
- PK : Type
- SK : Type
- Nonce : Type
- M : Type
- C : Type
- decPK : DecidableEq PK
- decSK : DecidableEq SK
- decNonce : DecidableEq Nonce
- decM : DecidableEq M
- decC : DecidableEq C
Instances
Nonce-Based Symmetric Encryption Scheme (NBSES) #
Corresponds to Rocq's NBSES_scheme. In NaCl, this is XSalsa20-Poly1305.
All operations are pure SPComp (no state, no oracle access).
Nonce-Based Symmetric Encryption Scheme.
Parameterized by a CryptoTypes instance providing the abstract types.
Probabilistic encryption: key → message → nonce → ciphertext
- dec : CryptoTypes.SharedKey → CryptoTypes.C → CryptoTypes.Nonce → Core.SPComp (Option CryptoTypes.M)
Decryption: key → ciphertext → nonce → message (may fail for AEAD)
Instances For
Non-Interactive Key Exchange (NIKE) #
Corresponds to Rocq's NIKE_scheme. In NaCl, this is X25519.
The shared key computation is deterministic (pure function).
Non-Interactive Key Exchange scheme.
- pkgen : Core.SPComp (CryptoTypes.PK × CryptoTypes.SK)
Key pair generation (probabilistic)
Instances For
Key Injection #
Corresponds to Rocq's inj record. Maps between NIKE shared keys and
NBSES shared keys. In practice, this is often the identity or a hash.
Injection between key spaces (NIKE shared keys ↔ NBSES shared keys). Allows composing NIKE and NBSES even if their key types differ abstractly.
- encode : CryptoTypes.SharedKey → CryptoTypes.SharedKey
Encode a NIKE shared key for use as an NBSES key
- decode : CryptoTypes.SharedKey → CryptoTypes.SharedKey
Decode back
Round-trip: decode ∘ encode = id
Instances For
Session Identifiers (SID) #
A session ID is a canonical pair of public keys identifying a communication session between two parties. The canonical ordering ensures both parties compute the same SID regardless of who is sender/receiver.
Session identifier: a pair of public keys.
Equations
Instances For
Canonical sort for session IDs.
Ensures sortSID pk_a pk_b = sortSID pk_b pk_a.
Instances For
sortSID is symmetric: the order of arguments doesn't matter.
NIKE Commutativity #
The key property for Cryptobox: the shared key is the same regardless of which party acts as sender/receiver. This is stated as a property of (NIKEScheme, pkgen output) pairs rather than as a field of NIKEScheme, following the Rocq approach.
Nonce-Based Public-key Encryption Scheme (NBPES/PKAE) #
The target construction: public-key authenticated encryption.
Corresponds to Rocq's NBPES_scheme.
Nonce-Based Public-key Encryption Scheme (PKAE target).
- pkgen : Core.SPComp (CryptoTypes.PK × CryptoTypes.SK)
Key pair generation
- enc : CryptoTypes.SK → CryptoTypes.PK → CryptoTypes.M → CryptoTypes.Nonce → Core.SPComp CryptoTypes.C
Encryption: sender's SK, receiver's PK, message, nonce → ciphertext
- dec : CryptoTypes.SK → CryptoTypes.PK → CryptoTypes.C → CryptoTypes.Nonce → Core.SPComp (Option CryptoTypes.M)
Decryption: receiver's SK, sender's PK, ciphertext, nonce → message
Instances For
Cryptobox Construction #
The main construction: combine NIKE + NBSES into a PKAE scheme.
Construct a PKAE scheme from NIKE + NBSES + key injection. This is the Cryptobox construction:
- pkgen = NIKE.pkgen
- enc(sk_s, pk_r, m, n) = NBSES.enc(inj(NIKE.sharedkey(pk_r, sk_s)), m, n)
- dec(sk_r, pk_s, c, n) = NBSES.dec(inj(NIKE.sharedkey(pk_s, sk_r)), c, n)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Operation identifiers #
Fixed natural number identifiers for each oracle operation. These correspond to the Rocq operation IDs and are used for interface matching in the package system.
Operation ID for key generation
Equations
Instances For
Operation ID for corrupt set public key
Equations
Instances For
Operation ID for get secret key
Equations
Instances For
Operation ID for check honest public key
Equations
Instances For
Operation ID for NIKE shared key computation
Equations
Instances For
Operation ID for honest key set
Equations
Instances For
Operation ID for corrupt key set
Equations
Instances For
Operation ID for key get
Equations
Instances For
Operation ID for honesty check
Equations
Instances For
Operation ID for encryption
Equations
Instances For
Operation ID for decryption