Skip to content

libsrtp in WebAssembly/WebCrypto: a quick experiment #752

@pbodilis

Description

@pbodilis

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions