/* Base64 encoding */
/* Maximum length of output for base64_encode_update. NOTE: Doesn't
- * include any padding that base64_encode_final may add. */
-/* FIXME: Rewrite to only evaluate LENGTH once. */
-#define BASE64_ENCODE_LENGTH(length) ((length) + ((length) + 2)/3)
+ * include any padding that base64_encode_final may add. */
+/* We have at most 4 buffered bits, and a total of (4 + length * 8) bits. */
+#define BASE64_ENCODE_LENGTH(length) (((length) * 8 + 4)/6)
/* Maximum lengbth of output generated by base64_encode_final. */
#define BASE64_ENCODE_FINAL_LENGTH 3
/* Base64 decoding */
-/* FIXME: Think more about this definition. */
-#define BASE64_DECODE_LENGTH(length) \
- ((length) * BASE64_BINARY_BLOCK_SIZE / BASE64_TEXT_BLOCK_SIZE)
+/* Maximum length of output for base64_decode_update. */
+/* We have at most 6 buffered bits, and a total of (length + 1) * 6 bits. */
+#define BASE64_DECODE_LENGTH(length) ((((length) + 1) * 6) / 8)
struct base64_decode_ctx
{