diff options
author | Jack Sangdahl <[email protected]> | 2024-06-15 22:27:25 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2024-06-15 22:27:25 -0600 |
commit | a59a5d144cc31cc8386e60dcc97be45a0dfd5256 (patch) | |
tree | 076d0adc9bc53538e7283e0248adef57ce2a9a51 /util/base64.h | |
download | cryptopals-master.tar.gz cryptopals-master.zip |
Diffstat (limited to 'util/base64.h')
-rw-r--r-- | util/base64.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/util/base64.h b/util/base64.h new file mode 100644 index 0000000..85279de --- /dev/null +++ b/util/base64.h @@ -0,0 +1,25 @@ +#include <stdint.h> +#include <stddef.h> + +typedef uint8_t sextet; +static size_t base64_encoded_length(size_t bytes_len); +static char encode_char(sextet s); +static void encode_1byte(uint8_t byte1, char *encoded); +static void encode_2byte(uint8_t byte1, uint8_t byte2, char *encoded); +static void encode_3byte(uint8_t byte1, uint8_t byte2, uint8_t byte3, char *encoded); +/* + * encodes to BASE64, returns pointer to newly allocated + * zero-terminated string or NULL if error. + * make sure to free() string!! + */ +char *base64_encode(uint8_t *from, size_t len); +static uint8_t decode_char(char c); +static void decode_1byte(char *from, uint8_t *to); +static void decode_2byte(char *from, uint8_t *to); +static void decode_3byte(char *from, uint8_t *to); +/* + * accept a NULL-terminated string, decode it as BASE64, + * returns a pointer to newly allocated byte array or NULL + * if error. writes the size of array to *len. + */ +uint8_t *base64_decode(char *from, size_t *len); |