Skip to main content

Cryptographic Foundations

This chapter establishes the mathematical foundations upon which every security guarantee in Zentalk rests. We specify the cryptographic primitives, explain the design decisions behind each choice, and state the security properties that subsequent chapters depend on. Readers already familiar with these primitives may proceed to Chapter 3.

Finite Field Arithmetic

Zentachain's cryptographic operations are performed over two finite fields: GF(225519)\text{GF}(2^{255} - 19) for elliptic curve operations (chosen for efficient constant-time reduction and 128-bit security [Bernstein, 2006]) and GF(28)\text{GF}(2^8) for Reed-Solomon erasure coding. The mathematical properties of finite fields -- closure, associativity, and the existence of inverses -- guarantee that all cryptographic operations are well-defined and reversible where required.

Prime Field for Curve25519

Zentalk's primary key agreement and signature schemes operate over the prime field GF(p)\text{GF}(p) where:

p=225519p = 2^{255} - 19

This prime was chosen by Bernstein [8] for several specific properties:

Efficient Reduction
Since $p = 2^{255} - 19$ is close to a power of 2, modular reduction requires only a single multiplication by 19 — no expensive general-purpose reduction.
Constant-Time Arithmetic
The field fits in 256 bits, enabling constant-time operations on 64-bit processors. This prevents timing side-channel attacks.
Security Margin
Approximately 128 bits of security against the best known classical algorithms (Pollard's rho), the standard target for symmetric-equivalent strength.

Extension Field for Reed-Solomon

Zentalk's erasure coding operates over the extension field GF(28)\text{GF}(2^8), which consists of 256 elements -- each mapping directly to a single byte. Addition in GF(28)\text{GF}(2^8) is bitwise XOR, and multiplication is polynomial multiplication modulo the irreducible polynomial g(x)=x8+x4+x3+x+1g(x) = x^8 + x^4 + x^3 + x + 1. The key property for erasure coding: every nonzero element has a multiplicative inverse, so systems of linear equations can be solved exactly, enabling the Reed-Solomon decoder to reconstruct missing data shards from surviving shards (see Chapter 5).

Elliptic Curve Cryptography

ECDLP

An elliptic curve over a field FF is the set of points (x,y)(x, y) satisfying a defining equation, together with a point at infinity O\mathcal{O} that serves as the identity element. Points on an elliptic curve form an abelian group under a geometric addition operation. This group structure enables scalar multiplication Q=nPQ = nP -- the foundation of elliptic curve cryptography -- which can be computed efficiently in O(logn)O(\log n) steps but cannot be reversed without solving the Elliptic Curve Discrete Logarithm Problem (ECDLP).

Given: P,  Q=nP on an elliptic curve. Find n.\text{Given: } P, \; Q = nP \text{ on an elliptic curve. Find } n.

Best known classical algorithm: Pollard's rho. Complexity: O(q)O(\sqrt{q}) where qq is the order of the group. For a 256-bit curve: O(2128)O(2^{128}) operations.

ECDLP Security Guarantee

The security of all elliptic curve cryptography rests on this asymmetry: scalar multiplication is efficient (O(logn)O(\log n) operations), while the reverse -- recovering the scalar from the result -- is computationally infeasible (O(2128)O(2^{128}) operations for a 256-bit curve). No sub-exponential classical algorithm for ECDLP is known.

Curve Comparison

Zentalk employs two curve representations, each optimized for a specific purpose. The following table compares their properties:

PropertyWeierstrass (short form)Montgomery (Curve25519)Twisted Edwards (Ed25519)
Equationy2=x3+ax+by^2 = x^3 + ax + bBy2=x3+Ax2+xBy^2 = x^3 + Ax^2 + xx2+y2=1+dx2y2-x^2 + y^2 = 1 + dx^2y^2
Addition formulaRequires special casesx-coordinate only (ladder)Complete (no special cases)
Field multiplications per add125 (differential)10
Constant-time by designNo (requires careful impl.)Yes (Montgomery ladder)Yes (complete formula)
Primary use in Zentalk--X25519 key agreementEd25519 signatures
Security levelCurve-dependent128-bit classical128-bit classical

Curve25519

Zentalk uses Curve25519, defined by Bernstein in 2006 [8]. Curve25519 uses the Montgomery form:

By2=x3+Ax2+xBy^2 = x^3 + Ax^2 + x

where A=486662A = 486662, B=1B = 1, and the field is GF(225519)\text{GF}(2^{255} - 19).

The Montgomery form has several advantages for cryptographic implementation:

I. Montgomery ladder. The x-coordinate-only scalar multiplication algorithm processes each bit in constant time, naturally preventing timing side-channel attacks.

II. No need for y-coordinate. For Diffie-Hellman key agreement, only the x-coordinate is needed. X25519 takes a 32-byte scalar and x-coordinate as input and produces a 32-byte x-coordinate as output.

III. Clamping. The scalar is "clamped" before use to ensure correct bit structure:

scalar[0] &= 248 // Clear the three lowest bits
scalar[31] &= 127 // Clear the highest bit
scalar[31] |= 64 // Set the second-highest bit

This clears cofactor issues, prevents small-subgroup attacks, and guarantees constant-time execution.

Base point. The standard base point has x-coordinate 9: G=(9,computed y-coordinate)G = (9, \langle\text{computed } y\text{-coordinate}\rangle).

X25519 function:

X25519(scalar,u)=x-coordinate of (scalarpoint with x=u)\text{X25519}(\text{scalar}, u) = \text{x-coordinate of } (\text{scalar} \cdot \text{point with } x = u) Public key generation:Apub=X25519(apriv,9)Key agreement:shared=X25519(apriv,Bpub)=X25519(bpriv,Apub)\begin{aligned} \text{Public key generation:} \quad & A_{\text{pub}} = \text{X25519}(a_{\text{priv}}, 9) \\ \text{Key agreement:} \quad & \text{shared} = \text{X25519}(a_{\text{priv}}, B_{\text{pub}}) = \text{X25519}(b_{\text{priv}}, A_{\text{pub}}) \end{aligned}

The last equality follows from the commutativity of scalar multiplication:

a(bG)=b(aG)=(ab)Ga \cdot (b \cdot G) = b \cdot (a \cdot G) = (a \cdot b) \cdot G

Ed25519

For digital signatures, Zentalk uses Ed25519, which is birationally equivalent to Curve25519 but expressed in twisted Edwards form:

x2+y2=1+dx2y2-x^2 + y^2 = 1 + dx^2y^2

where d=121665121666d = -\frac{121665}{121666} in GF(225519)\text{GF}(2^{255} - 19).

Zentalk uses Ed25519 [Bernstein et al., 2012] for digital signatures. Ed25519 uses deterministic nonce generation, eliminating the catastrophic failure mode of ECDSA where nonce reuse reveals the private key. Signatures are 64 bytes, verification requires one scalar multiplication, and the security level is approximately 21282^{128} operations.

Deterministic Nonces Prevent Catastrophic Failure

Unlike ECDSA, where a single reused or biased random nonce leaks the private key (as occurred in the 2010 PlayStation 3 signing key extraction), Ed25519 derives nonces deterministically from the private key and message. The same inputs always produce the same signature, and no external randomness is required. This eliminates an entire class of implementation vulnerabilities.

Security properties:

  • Existential unforgeability under chosen-message attack (EU-CMA) under the ECDLP assumption
  • Resilience against fault attacks (deterministic nonce)
  • 128-bit security level (group order approximately 22522^{252})

AES-256-GCM

AES-256

The Advanced Encryption Standard (AES) is a symmetric block cipher that encrypts 128-bit blocks using a key of 128, 192, or 256 bits. Zentalk exclusively uses AES-256 (256-bit key) for maximum security margin.

AES-256 applies 14 rounds of substitution and permutation to 128-bit blocks using a 256-bit key. The best known attack (biclique, Bogdanov et al. 2011) reduces complexity to 2254.42^{254.4}, which remains computationally infeasible. AES hardware acceleration (AES-NI) enables encryption at memory bandwidth speeds on modern processors.

GCM Mode

AES-GCM is an Authenticated Encryption with Associated Data (AEAD) scheme that simultaneously provides confidentiality, integrity, and authenticity. GCM combines AES in counter mode (for confidentiality) with a Galois field authentication function (for integrity), producing an authentication tag that detects any modification to the ciphertext or associated data. The critical requirement is nonce uniqueness: reusing a nonce with the same key completely breaks GCM's security guarantees -- the authentication tag becomes predictable and ciphertext becomes malleable.

Parameters in Zentalk:

ParameterValueJustification
Key length256 bits (32 bytes)Maximum AES security; 128-bit quantum resistance
Nonce (IV) length96 bits (12 bytes)NIST SP 800-38D recommended for GCM
Authentication tag128 bits (16 bytes)Full GCM tag length; forgery probability 21282^{-128}
Block size128 bits (16 bytes)AES fixed block size
Critical: AES-GCM Nonce Uniqueness

If the same nonce is ever reused with the same key, AES-GCM's security completely collapses: an attacker can recover the XOR of both plaintexts and forge arbitrary authentication tags. Nonce uniqueness is not a recommendation -- it is an absolute requirement for correctness.

Zentalk prevents nonce reuse through:

  1. Random nonce generation: crypto.getRandomValues(new Uint8Array(12)) for each encryption operation
  2. IV tracking: Used IVs are recorded in memory and IndexedDB with a 7-day TTL
  3. Constant-time comparison: IV uniqueness checks use constant-time comparison to prevent timing side-channels

Hashing and Key Derivation

SHA Family

PropertySHA-256SHA-512
Output size256 bits (32 bytes)512 bits (64 bytes)
Block size512 bits (64 bytes)1024 bits (128 bytes)
Rounds6480
Word size32-bit64-bit
Preimage resistanceO(2256)O(2^{256})O(2512)O(2^{512})
Collision resistanceO(2128)O(2^{128}) (birthday bound)O(2256)O(2^{256}) (birthday bound)
Performance on 64-bit CPUsBaselineFaster (native 64-bit ops)
Usage in ZentalkAddress hashing, HKDF, HMACSafety numbers, Ed25519 internal

Zentalk uses SHA-256 and SHA-512 from the SHA-2 family (FIPS 180-4). Both are cryptographic hash functions that produce fixed-length outputs from arbitrary-length inputs, providing preimage resistance, second preimage resistance, and collision resistance at the security levels listed above. SHA-512 is used where Ed25519 requires it internally and where 256-bit collision resistance is needed (safety numbers); SHA-256 is used for all general-purpose hashing and as the basis for HMAC and HKDF.

HMAC-SHA256

HMAC (Hash-based Message Authentication Code) constructs a keyed pseudorandom function from SHA-256, enabling message authentication and key derivation. HMAC-SHA256 is a PRF under the assumption that SHA-256's compression function is a PRF -- a stronger assumption than collision resistance that has held under decades of cryptanalytic scrutiny.

Zentalk uses HMAC-SHA256 in two critical contexts:

Chain Key Derivation
In the Double Ratchet: $\text{MK} = \text{HMAC}(\text{CK}, \texttt{0x01})$, $\text{CK}' = \text{HMAC}(\text{CK}, \texttt{0x02})$
Session Integrity
HMAC over serialized session state to detect tampering.

HKDF

HMAC-based Key Derivation Function (HKDF) converts arbitrary input key material into one or more cryptographically strong keys. It operates in two phases: Extract concentrates unevenly distributed entropy from input key material into a fixed-length pseudorandom key using a salt as domain separator; Expand generates output key material of arbitrary length using an info parameter for context binding -- different info strings ensure keys derived for one purpose cannot be used for another.

Usage in Zentalk:

ContextIKMSaltInfoOutput Length
X3DH shared secretDH1DH2DH3[DH4]\text{DH1} \| \text{DH2} \| \text{DH3} [\| \text{DH4}]X3DH_SALT (32 bytes)"Zentalk X3DH Key Agreement"32 bytes
DH ratchet stepX25519(dhpriv,dhpeer)\text{X25519}(dh_{\text{priv}}, dh_{\text{peer}})Previous root key (RK)"Zentalk Double Ratchet Root"64 bytes (split: 32 RK + 32 CK)
Hybrid X3DHclassical_secretkyber_secret\text{classical\_secret} \| \text{kyber\_secret}HYBRID_X3DH_SALT"zentalk.hybrid-x3dh.v1"64 bytes
Sealed sender keyECDH shared secret32 zero bytes"zentalk.sealed-sender.v1"32 bytes (AES-256 key)
Backup encryptionSHA-256(dhPrivate)\text{SHA-256}(dh_{\text{Private}})Random 16-byte salt"zentalk-mesh-backup"32 bytes (AES-256 key)
Group message keyOwner identity key seed"group:{id}:messages
"
"Zentalk Group Messages v1"32 bytes

PBKDF2

For deriving keys from potentially low-entropy inputs (passwords, wallet signatures), Zentalk uses PBKDF2 with SHA-256. PBKDF2 applies HMAC-SHA256 iteratively to make brute-force attacks computationally expensive -- each guess requires the full iteration count to verify.

Iteration counts in Zentalk:

ContextIterationsJustification
Mesh backup encryption600,000OWASP 2023 recommendation for PBKDF2-SHA256
Phone auth key derivation600,000Same standard, protects low-entropy passwords
Phone hash (v1, legacy)100,000Legacy accounts, backward compatibility
Phone hash (v2, current)310,000Upgraded for new accounts
IndexedDB master key600,000Protects stored E2EE sessions

The 600,000 iteration count provides approximately 200ms of computation on modern hardware (2024 MacBook Pro), which is imperceptible to users but makes brute-force attacks requiring billions of attempts computationally prohibitive.

Scrypt

Key Stretching: PBKDF2 vs Scrypt

PBKDF2 is CPU-bound: its cost scales linearly with iteration count but requires negligible memory, making it vulnerable to massively parallel GPU/ASIC attacks. Scrypt is memory-hard: it requires both CPU time and a large block of RAM (32 MB in Zentalk's configuration), making hardware-accelerated brute-force attacks orders of magnitude more expensive per guess.

PropertyPBKDF2-SHA256Scrypt
Hardness typeCPU-bound (iterative)Memory-hard
Memory requirementNegligible (~256 bytes)Nr128N \cdot r \cdot 128 bytes (32 MB)
GPU attack resistanceLow (highly parallelizable)High (memory bottleneck)
ASIC attack resistanceLowModerate-High
Configuration in Zentalk600,000 iterationsN=215N=2^{15}, r=8r=8, p=1p=1
Approximate time (2024 hardware)~200 ms~100 ms
Use case in ZentalkGeneral key derivationE2EE key backup envelope

For the most security-critical key derivation -- the E2EE key backup envelope that protects the user's identity keys -- Zentalk uses Scrypt with memory-hard parameters: N=215=32,768N = 2^{15} = 32{,}768 (CPU/memory cost), r=8r = 8 (block size), p=1p = 1 (parallelization), dkLen=32\text{dkLen} = 32 bytes. The computation requires approximately 32 MB of memory, making GPU and ASIC-based brute-force attacks significantly more expensive than for PBKDF2.

Security Levels

The following table maps each cryptographic primitive used in Zentalk to its key size, the classical security level (bits of security against the best known classical attack), and the post-quantum security level where applicable.

PrimitiveKey / Parameter SizeClassical SecurityPost-Quantum SecurityBest Known Attack
X25519256-bit scalar128-bit~64-bit (Grover + Shor)Pollard's rho: O(2128)O(2^{128})
Ed25519256-bit scalar128-bit~64-bit (Grover + Shor)Pollard's rho: O(2128)O(2^{128})
AES-256-GCM256-bit key256-bit128-bit (Grover)Biclique: O(2254.4)O(2^{254.4})
SHA-256256-bit output128-bit (collision)85-bit (Grover for collision)Birthday: O(2128)O(2^{128})
SHA-512512-bit output256-bit (collision)170-bit (Grover for collision)Birthday: O(2256)O(2^{256})
Kyber-768 (ML-KEM)2400-byte public key~183-bit~161-bit quantumModule-LWE lattice attacks
Dilithium3 (ML-DSA)1952-byte public key~183-bit~161-bit quantumModule-LWE/SIS lattice attacks
Post-Quantum Readiness

Zentalk's classical primitives (X25519, Ed25519) provide 128-bit security against today's computers but would be vulnerable to a sufficiently large quantum computer running Shor's algorithm. The hybrid X3DH protocol (Chapter 3) combines classical X25519 with post-quantum Kyber-768, ensuring that messages remain confidential even if quantum computers become practical -- an attacker must break both the classical and post-quantum schemes simultaneously.

Summary

PrimitiveAlgorithmSecurity LevelUsage in Zentalk
Key AgreementX25519 (Curve25519)128-bit classicalDH in X3DH and Double Ratchet
Digital SignaturesEd25519128-bit classicalPrekey signing, message signing
Symmetric EncryptionAES-256-GCM256-bit / 128-bit quantumMessage and chunk encryption
Hash FunctionSHA-256128-bit collision resistanceAddress hashing, checksums
Hash FunctionSHA-512256-bit collision resistanceSafety numbers, Ed25519 internal
Key DerivationHKDF-SHA256PRF securityX3DH, Double Ratchet, sealed sender
Key StretchingPBKDF2-SHA256600K iterationsPasswords, backup encryption
Memory-Hard KDFScryptN=215N=2^{15}, r=8r=8V3 key backup envelope
Post-Quantum KEMKyber-768 (ML-KEM)NIST Level 3 (~183-bit classical)Hybrid X3DH
Post-Quantum SigDilithium3 (ML-DSA)NIST Level 3 (~183-bit classical)Hybrid authentication
Erasure CodingReed-Solomon over GF(28)\text{GF}(2^8)10+5 MDSMesh data redundancy