From: Shivani Bhardwaj Date: Thu, 3 Dec 2020 11:25:39 +0000 (+0530) Subject: util/crypt: Add macro for max base64encode len X-Git-Tag: suricata-6.0.1~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02942a123a525bb1ed97bba9242f1e08d54f0fb8;p=thirdparty%2Fsuricata.git util/crypt: Add macro for max base64encode len Maximum length of a base64 encoded string can be 33% over the actual length of the input string. The formula to best cover all the edge cases is mathematically (4 * (input_length + 2) / 3) + 1 Add a macro to calculate this for a given input length. --- diff --git a/src/util-crypt.h b/src/util-crypt.h index 0a1830a634..15e1656726 100644 --- a/src/util-crypt.h +++ b/src/util-crypt.h @@ -29,6 +29,12 @@ #include "suricata-common.h" +/* Ratio of output bytes to input bytes for Base64 Encoding is 4:3, hence the + * required output bytes are 4 * ceil(input_len / 3) and an additional byte + * for storing the NULL pointer. + * */ +#define BASE64_BUFFER_SIZE(x) ((4 * ((x) + 2) / 3) + 1) + typedef enum { SC_SHA_1_OK, SC_SHA_1_NOK,