aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTaylor Yu <catalyst@torproject.org>2017-04-06 13:54:27 -0400
committerTaylor Yu <catalyst@torproject.org>2017-04-06 15:43:55 -0400
commite7f40baade042ced7b7c211cee4b8e1cbf3e230f (patch)
tree51c8ba8f5d4f4a7e14f50b06f66f911feeb2d437 /src
parentc5adab025852c68bc637c4fbfa34c44cde7397bb (diff)
downloadtor-e7f40baade042ced7b7c211cee4b8e1cbf3e230f.tar.gz
tor-e7f40baade042ced7b7c211cee4b8e1cbf3e230f.zip
Add macros for baseXX encoding lengths
Diffstat (limited to 'src')
-rw-r--r--src/common/util_format.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/common/util_format.h b/src/common/util_format.h
index 5fd82d6d99..c92805246f 100644
--- a/src/common/util_format.h
+++ b/src/common/util_format.h
@@ -10,6 +10,26 @@
#include "testsupport.h"
#include "torint.h"
+/** @{ */
+/** These macros don't check for overflow. Use them only for constant inputs
+ * (like array declarations). The *_LEN macros are the raw encoding lengths
+ * (without terminating NUL), while the *_BUFSIZE macros count the terminating
+ * NUL. */
+#define BASE64_LEN(n) (CEIL_DIV((n), 3) * 4)
+#define BASE32_LEN(n) (CEIL_DIV((n), 5) * 8)
+#define BASE16_LEN(n) ((n) * 2)
+
+#define BASE64_BUFSIZE(n) (BASE64_LEN(n) + 1)
+#define BASE32_BUFSIZE(n) (BASE32_LEN(n) + 1)
+#define BASE16_BUFSIZE(n) (BASE16_LEN(n) + 1)
+
+#define BASE64_NOPAD_LEN(n) (CEIL_DIV((n) * 4, 3)
+#define BASE32_NOPAD_LEN(n) (CEIL_DIV((n) * 8, 5)
+
+#define BASE64_NOPAD_BUFSIZE(n) (BASE64_NOPAD_LEN(n) + 1))
+#define BASE32_NOPAD_BUFSIZE(n) (BASE32_NOPAD_LEN(n) + 1))
+/** @} */
+
#define BASE64_ENCODE_MULTILINE 1
size_t base64_encode_size(size_t srclen, int flags);
int base64_encode(char *dest, size_t destlen, const char *src, size_t srclen,