Skip to main content

Appendix B: Implementation Notes

Draft

This section is under construction. Full details of all 19 bugs will be documented.

B.1 SimpleX-specific AES-GCM (16-byte IV)

SimpleX uses 16-byte IVs for AES-256-GCM instead of the standard 12 bytes. Most cryptographic libraries default to 12-byte IVs. Implementers MUST ensure their AES-GCM implementation supports non-standard IV sizes.

The 16-byte IV is processed internally by GCM using GHASH, which changes the computation compared to 12-byte IVs.

B.2 Custom XSalsa20 in cbEncrypt/cbDecrypt

SimpleX's cbEncrypt/cbDecrypt functions use XSalsa20-Poly1305 (NaCl crypto_box) but with a non-standard nonce handling: zeros are used instead of nonce prefixes in certain contexts.

B.3 Empty Salt in Chain KDF

The Chain KDF (for deriving message keys) uses an empty salt ("", zero-length), not 32 or 64 zero bytes. This is unusual for HKDF and was a source of bugs.

B.4 Contact Queue vs Reply Queue Key Differences

PropertyContact QueueReply Queue
Layer 2 E2ENone (skip)Fresh DH computation
Key sourcePre-shared from invitationEphemeral per-message
DH key in cmHeaderNot presentSPKI-encoded X25519

B.5 unPad Layer

Between crypto_box decryption and ClientMessage parsing, there is an unPad step:

  1. Read first 2 bytes as BE16 length
  2. Extract length bytes as the actual content
  3. Discard remaining padding bytes

B.6 Common Implementation Pitfalls

#BugImpactSession
17Using msgId instead of cmNonce for Layer 2Decryption failureS17
18Including length prefix in AADAuth tag mismatchS17
Wrong IV order in Chain KDF outputWrong message keyS19
Missing HSalsa20 step in crypto_boxKey derivation failureS14
Debug tests with production state side effectsState corruptionMultiple

Full list of all 19 bugs with before/after analysis will be added.

B.7 Library Requirements

RequirementWhy
X448/Curve448 supportDouble Ratchet DH operations
AES-GCM with 16-byte IVNon-standard IV size in ratchet
HKDF-SHA512Key derivation (NOT SHA256)
NaCl crypto_box (XSalsa20-Poly1305)Layers 2 and 3 encryption
Ed25519SMP command signing
Zstd decompression (optional)Compressed messages