-
Notifications
You must be signed in to change notification settings - Fork 489
Description
We should convert libsrtp to Rust, in the interest of better memory safety.
We should be able to do this while maintaining the same C interface, so that consumers of binary library will simply have to re-link. I have done enough work in a branch to validate that this is possible; the re-implementation there links against the existing C tests and passes them. Consumers that rebuild the library (e.g., for packaging) will need to have a Rust toolchain.
This is obviously a large change with a risk of regressions (e.g., w.r.t. performance), so I would propose a multi-stage process to gradually develop and integrate Rust code:
- Replace the tests in
crypto/test
andtest
with equivalents in Rust (see this branch for a prototype). This will ensure that we have Rust support in the CI toolchain, and facilitate testing against Rust library code later. And it has minimal impact on consumers. - Add a parallel Rust implementation in several stages, following the modularity boundaries in the existing code
- Modules in roughly dependency / ease-of-implementation order:
- Key limits
- Replay DB
- Crypto algorithms
- Crypto kernel
- Packet parsing
- SRTP protocol logic
- At each stage:
- Re-implement the module in Rust and add a C FFI interface for it
- Have a switch in the build system that replaces the C modules with the corresponding Rust modules
- Use the test suite to verify the correctness and performance of the new module
- Modules in roughly dependency / ease-of-implementation order:
- Maintain parallel C and Rust implementations for some time while we build confidence in the Rust implementation. Any PRs in this period should maintain parity.
- Once the Rust implementation has had some deployment experience, remove the C implementation. Keep enough scaffolding to expose the C FFI interface.
(We may be able to do (4) at a per-module level, e.g., removing the C replay DB once the Rust one is validated and landed.)
If folks are in general agreement with this objective and high-level plan, we can then make some more precise issues/PRs.