-
Notifications
You must be signed in to change notification settings - Fork 13.3k
BearSSL takes more than twice as long for handshake as axTLS #5110
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
Comments
@marcelstoer we can change your local BearSSL to only use the ciphermodes supported by axtls. In Replace the long list with just the following to match the very limited scope of axTLS:
And you can re-compile and run on your same configuration and hardware to get the numbers, w/o any changes to your own test code. |
CC @llongeri |
@earlephilhower thanks for the valuable information. I tested what you proposed and the effect is quite striking: lwIP v2 lower memory, 80 MHz: ~420ms -> still 15% more than with axTLS lwIP v2 lower memory, 160 MHz: ~310ms I just wish we could configure such fundamentals in the sketch rather than tinkering with the core's CC @squix78 |
@marcelstoer, appreciate the concrete testing numbers! If you're power constrained than I suggest you look at 160MHz operation. My gut tells me you're not going to use much more current than 80MHz, but will need to run for ~40% less time so it will have lower total power. But that's orthogonal to BearSSL/axTLS. Adding a call to allow you to select the cipher list (or pass in a list) is not a big deal, and I think it would cover you here. The more secure ones can end up taking more CPU, so it's a trade off here where the BearSSL chosen default is security over performance. Another option would be to support multiple configurations in the GUI, like w/LWIP. For example, I'm compiling with a setting which minimizes RAM usage (I think 1-2KB RAM saved, so it's not trivial) but causes, potentially, slower operation in the main SSL loop. Turning off that switch would trade RAM for performance. |
I would argue that this configuration belongs to the application and should be store there. The cipher suites you select are dependent on the needs of the application and the remote resources it talks to. |
Agree with you, I think I was unclear. The I was suggesting providing a "BearSSL Low Memory" and a "BearSSL High Performance" version of the library that's compiled differently. Like LWIP is done today, it's a link-time option. The "High Performance" will have the same codepaths as the low-mem, but use different GCC switches which will reduce time spent doing some of the SSL operations (but use RAM). |
@marcelstoer since you've got a good testing infrastructure already, could you unzip the file below and replace the libbearssl.a in |
@earlephilhower <https://github.com/earlephilhower>
right. I thought it would be twice power consumption at 160Mhz operation
but tested power consumption is nearly the same as 80Mhz, so it is the way
we can reduce ssl handshake time dramatically.
…On Mon, Sep 17, 2018 at 6:49 PM Earle F. Philhower, III < ***@***.***> wrote:
@marcelstoer <https://github.com/marcelstoer>, appreciate the concrete
testing numbers!
If you're power constrained than I suggest you look at 160MHz operation.
My gut tells me you're not going to use much more current than 80MHz, but
will need to run for ~40% less time so it will have lower total power. But
that's orthogonal to BearSSL/axTLS.
Adding a call to allow you to select the cipher list (or pass in a list)
is not a big deal, and I think it would cover you here. The more secure
ones can end up taking more CPU, so it's a trade off here where the BearSSL
chosen default is security over performance.
Another option would be to support multiple configurations in the GUI,
like w/LWIP. For example, I'm compiling with a setting which minimizes RAM
usage (I think 1-2KB RAM saved, so it's not trivial) but causes,
potentially, slower operation in the main SSL loop. Turning off that switch
would trade RAM for performance.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5110 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGV_3Y4Hhi_vhwhAXoGK_u82X1iMKqSBks5ub8SEgaJpZM4Wbqae>
.
|
@earlephilhower will do
Did you time this? My test results (see above) show that CPU frequency has only negligible impact on the actual handshake time. |
With default BearSSL configuration it has great impact on timings. I will
find the numbers and post them here.
I think that was your numbers in another thread:
1. axTLS: median 368ms, average 390ms
2. BearSSL 80MHz: 888ms, 891ms -> over 500ms increase (140% extra)
3. BearSSL 160MHz: 568ms, 538ms -> 50% extra
…On Tue, Sep 18, 2018 at 9:59 AM Marcel Stör ***@***.***> wrote:
@earlephilhower <https://github.com/earlephilhower> will do
160Mhz operation but tested power consumption is nearly the same as 80Mhz,
so it is the way
we can reduce ssl handshake time dramatically
Did you time this? *My* test results (see above) show that CPU frequency
has only negligible impact on the actual *handshake* time.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5110 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGV_3SI59i9jQ-UteVbyCNy6EwYWTV8yks5ucJmygaJpZM4Wbqae>
.
|
@marcelstoer For CPU-bound stuff, it should increase performance (up to the point when the slow flash interface limits it). @artua's numbers (maybe yours?) are actually comparing EC vs. RSA handshakes, so they're not a good comparison between axtls and BearSSL. However, the (2) BearSSL and (3) BearSSL numbers can be compared (they're both EC handshakes) and it's a significant speedup. RSA handshake, I don't know yet, it could be RTT limited over the network. If you get a few minutes, I'd appreciate testing the ZIPped library from a couple back with your RSA-hacked BearSSL core. That's got a different compile option which may speed it up... |
Why I’m switching to BearSSL is the modern ciphers used by Cloudflare.
axTLS didn’t support that. I need to use their cdn proxies for my
application, so BearSSL is the only way to connect...
Their current configuration is:
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ecdh_curve X25519:P-256:P-384:P-224:P-521;
ssl_ciphers
'[ECDHE-ECDSA-AES128-GCM-SHA256|ECDHE-ECDSA-CHACHA20-POLY1305|ECDHE-RSA-AES128-GCM-SHA256|ECDHE-RSA-CHACHA20-POLY1305]:ECDHE+AES128:RSA+AES128:ECDHE+AES256:RSA+AES256:ECDHE+3DES:RSA+3DES';
ssl_prefer_server_ciphers on;
I think we should try chacha20 or poly for the best results?
…On Tue, Sep 18, 2018 at 6:37 PM Earle F. Philhower, III < ***@***.***> wrote:
@marcelstoer <https://github.com/marcelstoer> For CPU-bound stuff, it
should increase performance (up to the point when the slow flash interface
limits it). @artua <https://github.com/artua>'s numbers (maybe yours?)
are actually comparing EC vs. RSA handshakes, so they're not a good
comparison between axtls and BearSSL. However, the (2) BearSSL and (3)
BearSSL numbers can be compared (they're both EC handshakes) and it's a
significant speedup. RSA handshake, I don't know yet, it could be RTT
limited over the network.
If you get a few minutes, I'd appreciate testing the ZIPped library from a
couple back with your RSA-hacked BearSSL core. That's got a different
compile option which may speed it up...
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5110 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGV_3TpAiE0SiXq4nqj8lFX4Ulxwma00ks5ucRMngaJpZM4Wbqae>
.
|
@earlephilhower The verdict is in... In #5110 (comment) I added the 160MHz numbers for the original "minimal ciphers" test case. I would say that ~300ms is satisfactorily low. Then I tried your new What I observed in many test runs are two "anomalies":
Conclusion for my battery powered project
|
Thanks for the update, @marcelstoer . Given that, I don't see any reason to offer two versions of the BearSSL library (mem vs speed). I still see the need for a "use these ciphers" and an axtls_ciphers constant default. That's a pretty trivial addition and will let you use faster, less secure ones while @artua can then choose only to use the newer (possibly slower and more secure) ones. |
BearSSL has many more ciphers than axTLS, but they are more compute intensive and slower. Add an option to use only the same, limited security, axTLS ciphers as well as allow users to specify any suite of ciphers they want using standard BearSSL formats. Fixes esp8266#5110
* Allow cipher specification for BearSSL BearSSL has many more ciphers than axTLS, but they are more compute intensive and slower. Add an option to use only the same, limited security, axTLS ciphers as well as allow users to specify any suite of ciphers they want using standard BearSSL formats. Fixes #5110 * Rename methods to avoid axtls references. * Allow std::vector to set a list of allowed ciphers For C++ afficionados, allow std::vectors to be passed in to the setCipher() routine. The BearSSL object will now keep a copy of any set ciphers and free on object destruction. These custom lists should normally only be 1-4 entries long, so it is not expected to be a memory hog having this extra copy.
@marcelstoer #5151 was merged, which autoclosed this. In the interest of moving forward, I'm leaving it closed for now. If you think further changes are needed, please provide details in a new issue. |
@marcelstoer , check out my latest PR, #5160. Using SSL sessions makes reconnection times 80% faster or so! |
This is a follow-up to #4738 (comment)
Claim
I observed that BearSSL in standard configuration takes more than twice as long for a handshake as axTLS.
Basic Infos
Platform
Sample sketch
The below sketch is inspired by what @artua presented at #4738 but it's much simpler. I feel that when just starting out measuring / comparing performance you shouldn't collect too much data at once as you might not see the wood for the trees. Once you identify a suspect you then adjust the rig accordingly and collect more data around the suspected culprit.
The program establishes a connection to a SSL/TLS protected host 50 times with a delay of 1.5s. For every attempt it reports total failure/success count, accumulated handshake time, average handshake time and free heap at the end. No server certificates or fingerprints are verified!
Around line 40 you define whether to use BearSSL (with
setInsecure()
) or axTLS.Test results
I ran the above sketch with all combinations of BearSSL/axTLS, lwIP v2 lower memory/higher bandwidth and 80/160MHz on core 2.4.2. So, this makes 2^3 * 50 samples.
The summary is as follows:
0 connection failures. That's remarkable as this whole endeavour started out with this issue https://stackoverflow.com/q/52143894.
BearSSL
axTLS
-> BearSSL takes more than twice as long
-> As expected higher bandwidth has close to zero impact as only a socket connection with handshake was established. No resources were loaded from the host.
The detailed result is in the below PDF.
BearSSL-vs-axTLS.pdf
Over at #4738 @earlephilhower stated that
I would first have to look into that. Not familiar with SSL config yet.
The text was updated successfully, but these errors were encountered: