Skip to content

Convert to Rust #564

@bifurcation

Description

@bifurcation

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:

  1. Replace the tests in crypto/test and test 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.
  2. 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
  3. 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.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions