]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util/crypt: Add macro for max base64encode len
authorShivani Bhardwaj <shivanib134@gmail.com>
Thu, 3 Dec 2020 11:25:39 +0000 (16:55 +0530)
committerVictor Julien <victor@inliniac.net>
Thu, 3 Dec 2020 14:17:38 +0000 (15:17 +0100)
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.

src/util-crypt.h

index 0a1830a634b2120648440e6d672bdbb64cf0528a..15e165672648dce9207b68d068b3a6b4235e7bf0 100644 (file)
 
 #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,