Skip to content

OpenSSL vs. BoringSSL vs. Go standard library crypto #1952

@marten-seemann

Description

@marten-seemann

Context

We're currently maintaining a fork of go-openssl which has created a lot of maintenance burden in the past, and I'm not optimistic that the situation will improve in the future. Also, I don't want to be maintain this library.

RSA used to be the standard key type in the early days of IPFS / libp2p, and we still have a minority of nodes in the network that use RSA keys. I just instrumented a kubo node, and 15 - 20% of nodes it connects to use RSA keys (the rest is almost exclusively Ed25519).

PL is running some nodes as a service to the network. Of those, bootstrap nodes handle a lot of short-lived connections, i.e. perform a lot of handshakes, during which we need to perform a signature verification.

Benchmarks

@Jorropo ran some benchmarks of signature verification using different key types a while back in #1686 (comment). However, there's currently a bug in our key generation code, rendering those results invalid. Benchmarks need to be run with https://github.com/libp2p/go-libp2p/tree/fix-crypto-benchmark due to #1951.

It looks like RSA signature verification is about 4x faster than the respective Go standard library code path.

  Go Standard Library OpenSSL BoringSSL
BenchmarkVerifyRSA1B-2 85.905 26.792 20.336
BenchmarkVerifyRSA10B-2 106.754 27.453 19.681
BenchmarkVerifyRSA100B-2 94.862 26.88 20.728
BenchmarkVerifyRSA1000B-2 101.62 28.35 19.747
BenchmarkVerifyRSA10000B-2 110.342 32.806 25.194
BenchmarkVerifyRSA100000B-2 170.742 100.674 80.228
BenchmarkVerifyEd255191B-2 76.216 82.31 80.681
BenchmarkVerifyEd2551910B-2 79.42 78.811 82.704
BenchmarkVerifyEd25519100B-2 78.767 81.161 89.527
BenchmarkVerifyEd255191000B-2 79.369 84.34 81.65
BenchmarkVerifyEd2551910000B-2 94.968 93.985 101.424
BenchmarkVerifyEd25519100000B-2 256.963 247.958 282.375

(all values in microseconds)

Conclusion

Go standard library signature verification is slightly (10%?) slower for RSA than for Ed25519. A significant speedup of the RSA code path can be achieved by using OpenSSL or BoringSSL, but it's questionable if that will have a big impact on the node's CPU load, given that RSA peers are just a small (and decreasing) fraction of the network. Furthermore, verifying host key signatures is not the only cost during the handshake (there's a regular TLS or Noise handshake as well). It also doesn't seem appropriate to introduce significant complexity to optimize the RSA code path, even though it's not significantly slower than the Ed25519 code path.

Am I missing something here? @vyzo @Stebalien @guseggert @lidel @p-shahi @Jorropo

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