Skip to content

Conversation

@boorad
Copy link
Collaborator

@boorad boorad commented Feb 2, 2026

Summary

Adds XChaCha20-Poly1305 and XSalsa20-Poly1305 AEAD cipher support via libsodium. These are extended-nonce variants (24 bytes vs 12 bytes) that enable safe random nonce generation for high-volume encryption scenarios.

Changes

New Ciphers

  • xchacha20-poly1305 - AEAD with 24-byte nonce and AAD support
  • xsalsa20-poly1305 - Authenticated encryption (NaCl secretbox style, no AAD)

C++ Implementation

  • XChaCha20Poly1305Cipher.cpp/.hpp - Full AEAD implementation using libsodium
  • XSalsa20Poly1305Cipher.cpp/.hpp - Secretbox-style authenticated encryption
  • Secure memory handling with sodium_memzero() for keys, nonces, tags, and buffers
  • Proper error handling with memory cleanup on failure paths

Tests

  • IETF draft-irtf-cfrg-xchacha test vector (Appendix A.3.1)
  • Round-trip tests for various input sizes (empty, single byte, large)
  • Error case tests (wrong key/nonce size, tag mismatch, AAD rejection)

Documentation

  • Updated cipher.mdx with algorithm tables and usage examples
  • Updated implementation-coverage.md with new cipher support

Requirements

These ciphers require SODIUM_ENABLED=1 on both iOS and Android.

Testing

Tests are included in the example app test suite:

  • xchacha20_poly1305_tests.ts
  • xsalsa20_poly1305_tests.ts

Closes #885

- Add XChaCha20Poly1305Cipher C++ implementation using OpenSSL EVP API
- Add XSalsa20Poly1305Cipher C++ implementation using OpenSSL EVP API
- Register new ciphers in HybridCipherFactory
- Update Android CMakeLists.txt with new source files
- Add comprehensive test suites for both ciphers
- Update documentation with usage examples
- Update implementation coverage documentation
- Add sodium_memzero on error paths before delete[] (4 locations)
- Zero data_buffer_ in destructors before clearing
- Override setAutoPadding to throw 'not supported'
- Standardize preprocessor guards to #ifdef/#ifndef
- Fix test vector type to avoid non-null assertion
- Revert unrelated diffieHellman marking change
@boorad boorad self-assigned this Feb 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

🤖 End-to-End Test Results - Android

Status: ✅ Passed
Platform: Android
Run: 21598058115

📸 Final Test Screenshot

Maestro Test Results - android

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

🤖 End-to-End Test Results - iOS

Status: ✅ Passed
Platform: iOS
Run: 21598058088

📸 Final Test Screenshot

Maestro Test Results - ios

Screenshot automatically captured from End-to-End tests and will expire in 30 days


This comment is automatically updated on each test run.

@boorad boorad merged commit a0453cf into main Feb 2, 2026
6 checks passed
@boorad boorad deleted the feat/885-xchacha20-poly1305 branch February 2, 2026 16:35
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.

✨ XChaCha20-Poly1305 encryption and decryption

2 participants