Skip to content

Possible error in BEAR_SSL_CLIENT_IBUF_SIZE calculation #79

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

Closed
imatrisciano opened this issue Dec 28, 2023 · 1 comment · Fixed by #81
Closed

Possible error in BEAR_SSL_CLIENT_IBUF_SIZE calculation #79

imatrisciano opened this issue Dec 28, 2023 · 1 comment · Fixed by #81
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@imatrisciano
Copy link

imatrisciano commented Dec 28, 2023

In BearSSLClient.h line 40-45 the values for BEAR_SSL_CLIENT_OBUF_SIZE and BEAR_SSL_CLIENT_IBUF_SIZE are calculated.

#ifndef BEAR_SSL_CLIENT_OBUF_SIZE
#define BEAR_SSL_CLIENT_OBUF_SIZE 512 + 85
#endif
#ifndef BEAR_SSL_CLIENT_IBUF_SIZE
#define BEAR_SSL_CLIENT_IBUF_SIZE 8192 + 85 + 325 - BEAR_SSL_CLIENT_OBUF_SIZE
#endif

By writing so, BEAR_SSL_CLIENT_OBUF_SIZE will be computed to be 512+85 = 597.
I would expect BEAR_SSL_CLIENT_IBUF_SIZE to be 8192 + 85 + 325 - 597 = 8005
But by using defines the code for BEAR_SSL_CLIENT_IBUF_SIZE actually compiles to 8192 + 85 + 325 - 512 + 85 = 8175

I don't know if this is intended behaviour. If it's not, things can be fixed by just adding some parenthesis

#ifndef BEAR_SSL_CLIENT_OBUF_SIZE
#define BEAR_SSL_CLIENT_OBUF_SIZE (512 + 85)
#endif

#ifndef BEAR_SSL_CLIENT_IBUF_SIZE
#define BEAR_SSL_CLIENT_IBUF_SIZE (8192 + 85 + 325 - BEAR_SSL_CLIENT_OBUF_SIZE)
#endif
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Dec 28, 2023
@aentinger
Copy link
Contributor

Hi @imatrisciano ☕ 👋

Thank you for pointing this out. You are correct, this is a bug. I've looked up the required minimum buffer sizes for BearSSL from its API documentation and it definitely makes more sense with the parenthesis in place. It's noteworthy, that alltogether even a bigger buffer size is recommended (BR_SSL_BUFSIZE_INPUT should be 16709, BR_SSL_BUFSIZE_OUTPUT should be 16469), the current size is what it is due to this library initially targetting the ArduinoCore-samd platform, where the maximum available TOTAL memory is 32k - and you just can't spend already 32k on the BearSSL buffers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
3 participants