2015-07-31 17:21:34 +02:00
|
|
|
/* Copyright (c) 2001, Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2019-01-16 18:33:22 +01:00
|
|
|
* Copyright (c) 2007-2019, The Tor Project, Inc. */
|
2015-07-31 17:21:34 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
2018-07-02 02:22:55 +02:00
|
|
|
/**
|
|
|
|
* \file binascii.h
|
|
|
|
*
|
|
|
|
* \brief Header for binascii.c
|
|
|
|
**/
|
|
|
|
|
2018-06-27 21:59:07 +02:00
|
|
|
#ifndef TOR_BINASCII_H
|
|
|
|
#define TOR_BINASCII_H
|
2015-07-31 17:21:34 +02:00
|
|
|
|
2018-06-27 21:59:07 +02:00
|
|
|
#include "orconfig.h"
|
|
|
|
#include <stddef.h>
|
2018-06-21 19:12:23 +02:00
|
|
|
#include "lib/testsupport/testsupport.h"
|
2018-06-21 18:20:52 +02:00
|
|
|
#include "lib/cc/torint.h"
|
2015-07-31 17:21:34 +02:00
|
|
|
|
2018-06-27 22:21:55 +02:00
|
|
|
const char *hex_str(const char *from, size_t fromlen);
|
|
|
|
|
2017-04-06 19:54:27 +02:00
|
|
|
/** @{ */
|
|
|
|
/** 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)
|
|
|
|
|
2017-05-17 01:22:11 +02:00
|
|
|
#define BASE64_NOPAD_LEN(n) (CEIL_DIV((n) * 4, 3))
|
|
|
|
#define BASE32_NOPAD_LEN(n) (CEIL_DIV((n) * 8, 5))
|
2017-04-06 19:54:27 +02:00
|
|
|
|
2017-05-17 01:22:11 +02:00
|
|
|
#define BASE64_NOPAD_BUFSIZE(n) (BASE64_NOPAD_LEN(n) + 1)
|
|
|
|
#define BASE32_NOPAD_BUFSIZE(n) (BASE32_NOPAD_LEN(n) + 1)
|
2017-04-06 19:54:27 +02:00
|
|
|
/** @} */
|
|
|
|
|
2015-07-31 17:21:34 +02:00
|
|
|
#define BASE64_ENCODE_MULTILINE 1
|
|
|
|
size_t base64_encode_size(size_t srclen, int flags);
|
2018-12-14 19:07:55 +01:00
|
|
|
size_t base64_decode_maxsize(size_t srclen);
|
2015-07-31 17:21:34 +02:00
|
|
|
int base64_encode(char *dest, size_t destlen, const char *src, size_t srclen,
|
|
|
|
int flags);
|
|
|
|
int base64_decode(char *dest, size_t destlen, const char *src, size_t srclen);
|
|
|
|
int base64_encode_nopad(char *dest, size_t destlen,
|
|
|
|
const uint8_t *src, size_t srclen);
|
|
|
|
|
|
|
|
/** Characters that can appear (case-insensitively) in a base32 encoding. */
|
|
|
|
#define BASE32_CHARS "abcdefghijklmnopqrstuvwxyz234567"
|
|
|
|
void base32_encode(char *dest, size_t destlen, const char *src, size_t srclen);
|
|
|
|
int base32_decode(char *dest, size_t destlen, const char *src, size_t srclen);
|
2016-02-08 21:00:56 +01:00
|
|
|
size_t base32_encoded_size(size_t srclen);
|
2015-07-31 17:21:34 +02:00
|
|
|
|
|
|
|
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen);
|
|
|
|
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen);
|
|
|
|
|
2019-06-05 15:33:35 +02:00
|
|
|
#endif /* !defined(TOR_BINASCII_H) */
|