Skip to content

libsrtp in WebAssembly/WebCrypto: a quick experiment #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pbodilis opened this issue Apr 4, 2025 · 0 comments
Open

libsrtp in WebAssembly/WebCrypto: a quick experiment #752

pbodilis opened this issue Apr 4, 2025 · 0 comments

Comments

@pbodilis
Copy link
Contributor

pbodilis commented Apr 4, 2025

Hi,

Not an actual issue, but not sure where to share this.
For some project, I run libsrtp in WebAssembly (as-is or using openssl as backend), and I wanted to see if we could use WebCrypto (https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) for the AES ciphering.

Main problem is that WebCrypto is asynchronous, so requires the use of await and ASINCIFY, which produces significant overhead + context switching. For 10000 protect/unprotect of packets with random size between 40 and 60, with a 256 bits key, running in node):

  • built_in: ~1600ms
  • webcrypto: ~1600ms (so yeah, pretty much on par with built_in)
  • openssl: ~400ms (4 times faster, pretty much a no brainer)

Results are more or less the same in Firefox or chrome, openssl is 4 to 5 times faster. Science demanded to test, and even if this nothing but a fun experiment, I though this could interest other people.

https://github.com/pbodilis/libsrtp/tree/webcrypto
Most of the "interesting" code is in aes_icm_webcrypto.cc

emscripten version: 4.0.5 (53b38d0c6f9fce1b62c55a8012bc6477f7a42711)

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

No branches or pull requests

1 participant