wolfSSL / wolfssl

The wolfSSL library is a small, fast, portable implementation of TLS/SSL for embedded devices to the cloud. wolfSSL supports up to TLS 1.3 and DTLS 1.3!
https://www.wolfssl.com
GNU General Public License v2.0
2.29k stars 818 forks source link

Problem with Base64_Decode() #7412

Open MarleenDev opened 5 months ago

MarleenDev commented 5 months ago

Version

latest

Description

When calling the Base64_Decode() function in wolfcrypt/src/coding.c to decode a short base64 encoded string, it returns BAD_FUNC_ARG. input:

At the start of Base64_Decode(), plainSz is calculated, which I guess is an estimate of the decoded size. Because of rounding, this becomes 19, which is then turned into (19*3+3)/4 which equals 15. This is of course greater than the outLen (15 > 13), so BAD_FUNC_ARG is returned.

The goal of this decoding is to copy the resulting bytes to a struct with a size of 13. De decoded size has 13 bytes, so I would expect it to work as-is. But because of the function requiring a 15 byte buffer, I am wondering whether I am doing something wrong, or if this is a bug. Please advise.

anhu commented 5 months ago

Hello @MarleenDev ,

Thank you for your interest in wolfSSL. Please see https://www.wolfssl.com/documentation/manuals/wolfssl/group__Base__Encoding.html#function-base64_decode .

In the example code for this API, the comment applies:

// requires at least (sizeof(encoded) * 3 + 3) / 4 room

Can you please let us know about yourself and your project that is using wolfSSL? Here at wolfSSL we love to know about how people are using our code. Some examples would be:

Any information you can provide would be greatly appreciated.

Warm regards, Anthony