From 434b26827d54011cc599cfe4bff37f29969d6740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Sat, 19 Oct 2002 13:41:22 +0200 Subject: [PATCH] * base64.h (BASE64_ENCODE_LENGTH, BASE64_DECODE_LENGTH): Fixed and documented macros. Rev: src/nettle/base64.h:1.9 --- base64.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/base64.h b/base64.h index 58e2879e..78b0711a 100644 --- a/base64.h +++ b/base64.h @@ -35,9 +35,9 @@ /* 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 @@ -89,9 +89,9 @@ base64_encode_group(uint8_t *dst, uint32_t group); /* 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 { -- GitLab