Hi Андрей,
The behavior you describe is a bug. But there isn't enough information
to tell whether the bug is in Mbed TLS, in asio-standalone, in some
other third-party code, or in your application.
Some things to consider:
* Are you using blocking or non-blocking I/O?
* Are you using TLS or DTLS? What protocol version, what cipher suite
and what extensions are negotiated?
* Does your application call mbedtls_ssl_write() and mbedtls_ssl_read()
again with the same buffer if they return MBEDTLS_ERR_SSL_WANT_READ or
MBEDTLS_ERR_SSL_WANT_WRITE?
* Do you close the TLS connection if mbedtls_ssl_xxx() returns an error
other than WANT_XXX (or XXX_IN_PROGRESS if you use these features)?
* What is the value of MBEDTLS_SSL_MAX_CONTENT_LEN (or
MBEDTLS_SSL_OUT_CONTENT_LEN if it's defined)?
* What operating system are you using?
* Is this a client or a server? What TLS stack does the other side run?
You'll give others the most chance to help you if you post small,
complete code to reproduce the problem. I realize this may be difficult.
A good intermediate way to see what is going on would be to post debug
logs. To get debug logs, make sure that MBEDTLS_DEBUG_C is enabled and
call these functions before opening the TLS connection:
mbedtls_ssl_conf_dbg(&ssl_conf, my_debug, stdout);
mbedtls_debug_set_threshold(2);
See https://tls.mbed.org/kb/how-to/mbedtls-tutorial for a sample version
of my_debug().
Calls to bio_send() are shown in the logs as
=> flush output
message length: %d, out_left: %d
ssl->f_send() returned %d
<= flush output
If they don't show expected numbers, the rest of the logs should give a
clue as to why.
Hope this helps,
--
Gilles Peskine
Mbed TLS developer
On 09/12/2020 22:17, Сысоев Андрей via mbed-tls wrote:
> Hello.
>
> I need a little help with mbedtls 2.16.3.
> I'm using it under x86-64 with asio-standalone.
>
> Here's a standard situation:
> - I call mbedtls_ssl_write() to write let's say 8192 bytes of payload
> - it calls my own bio_send() with (8192+21) bytes as len parameter
> - bio_send() returns len=(8192+21), indicating transport data
> correctly written
> - mbedtls_ssl_write() returns 8192, indicating payload send
> GOOD: next I use this value to shift application buffer (erase first
> 8192 bytes), then send next chunk
>
> BUT after some time of running this situation happens:
> - once again, a call to mbedtls_ssl_write() to write let's say 8192
> bytes of payload
> - it calls bio_send() with smaller number, about 5500 bytes as len
> parameter (?? but OK)
> - bio_send() returns len=5500, indicating transport data correctly
> written
> - mbedtls_ssl_write() returns 8192 (??? why not 5500 ???), indicating
> payload send
> BAD: next I use this value to shift application buffer (erase first
> 8192 bytes), this leads to data loss of (8192-5500)=2692 bytes and
> ruins protocol
>
> As you can see, mbedtls_ssl_write() incorrectly reports about sent
> application data (8192 instead of 5500) - is this a bug? How can such
> situation happen under normal operation?
>
> Thanks in advance.
>
Hello.
I need a little help with mbedtls 2.16.3.
I'm using it under x86-64 with asio-standalone.
Here's a standard situation:
- I call mbedtls_ssl_write() to write let's say 8192 bytes of payload
- it calls my own bio_send() with (8192+21) bytes as len parameter
- bio_send() returns len=(8192+21), indicating transport data correctly
written
- mbedtls_ssl_write() returns 8192, indicating payload send
GOOD: next I use this value to shift application buffer (erase first
8192 bytes), then send next chunk
BUT after some time of running this situation happens:
- once again, a call to mbedtls_ssl_write() to write let's say 8192
bytes of payload
- it calls bio_send() with smaller number, about 5500 bytes as len
parameter (?? but OK)
- bio_send() returns len=5500, indicating transport data correctly written
- mbedtls_ssl_write() returns 8192 (??? why not 5500 ???), indicating
payload send
BAD: next I use this value to shift application buffer (erase first 8192
bytes), this leads to data loss of (8192-5500)=2692 bytes and ruins protocol
As you can see, mbedtls_ssl_write() incorrectly reports about sent
application data (8192 instead of 5500) - is this a bug? How can such
situation happen under normal operation?
Thanks in advance.
Hi Farhad,
Mbed TLS currently supports hardware acceleration through alternative
implementations of the corresponding modules or functions. See
https://tls.mbed.org/kb/development/hw_acc_guidelines . This mechanism
is available for symmetric cryptography and partially for RSA and ECC.
There is some work in progress on a new mechanism for hardware
acceleration through the psa_xxx() API, which will be available for all
algorithms. You can follow the work in progress on the “Unified driver
interface: API design and prototype” epic at
https://github.com/ARMmbed/mbedtls/projects/2#column-8543266 .
Hope this helps,
--
Gilles Peskine
Mbed TLS developer
On 04/12/2020 11:20, saghili via mbed-tls wrote:
> Dear Sir/Madam,
>
> Our platform is a quad core Cortex A53 running PetaLinux.
> In our hardware, "AF_ALG" module has performance accelerations
> available through the Linux crypto drivers.
> Is it possible that we have "AF_ALG" for offloading crypto operations?
>
> Best regards,
> Farhad
Dear Sir/Madam,
Our platform is a quad core Cortex A53 running PetaLinux.
In our hardware, "AF_ALG" module has performance accelerations available
through the Linux crypto drivers.
Is it possible that we have "AF_ALG" for offloading crypto operations?
Best regards,
Farhad