Tor  0.4.7.0-alpha-dev
binascii.h
Go to the documentation of this file.
1 /* Copyright (c) 2001, Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * \file binascii.h
9  *
10  * \brief Header for binascii.c
11  **/
12 
13 #ifndef TOR_BINASCII_H
14 #define TOR_BINASCII_H
15 
16 #include "orconfig.h"
17 #include <stddef.h>
19 #include "lib/cc/torint.h"
20 
21 const char *hex_str(const char *from, size_t fromlen);
22 
23 /** @{ */
24 /** These macros don't check for overflow. Use them only for constant inputs
25  * (like array declarations). The *_LEN macros are the raw encoding lengths
26  * (without terminating NUL), while the *_BUFSIZE macros count the terminating
27  * NUL. */
28 #define BASE64_LEN(n) (CEIL_DIV((n), 3) * 4)
29 #define BASE32_LEN(n) (CEIL_DIV((n), 5) * 8)
30 #define BASE16_LEN(n) ((n) * 2)
31 
32 #define BASE64_BUFSIZE(n) (BASE64_LEN(n) + 1)
33 #define BASE32_BUFSIZE(n) (BASE32_LEN(n) + 1)
34 #define BASE16_BUFSIZE(n) (BASE16_LEN(n) + 1)
35 
36 #define BASE64_NOPAD_LEN(n) (CEIL_DIV((n) * 4, 3))
37 #define BASE32_NOPAD_LEN(n) (CEIL_DIV((n) * 8, 5))
38 
39 #define BASE64_NOPAD_BUFSIZE(n) (BASE64_NOPAD_LEN(n) + 1)
40 #define BASE32_NOPAD_BUFSIZE(n) (BASE32_NOPAD_LEN(n) + 1)
41 /** @} */
42 
43 #define BASE64_ENCODE_MULTILINE 1
44 size_t base64_encode_size(size_t srclen, int flags);
45 size_t base64_decode_maxsize(size_t srclen);
46 int base64_encode(char *dest, size_t destlen, const char *src, size_t srclen,
47  int flags);
48 int base64_decode(char *dest, size_t destlen, const char *src, size_t srclen);
49 int base64_encode_nopad(char *dest, size_t destlen,
50  const uint8_t *src, size_t srclen);
51 
52 /** Characters that can appear (case-insensitively) in a base32 encoding. */
53 #define BASE32_CHARS "abcdefghijklmnopqrstuvwxyz234567"
54 void base32_encode(char *dest, size_t destlen, const char *src, size_t srclen);
55 int base32_decode(char *dest, size_t destlen, const char *src, size_t srclen);
56 size_t base32_encoded_size(size_t srclen);
57 
58 void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen);
59 int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen);
60 
61 #endif /* !defined(TOR_BINASCII_H) */
int base32_decode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:90
const char * hex_str(const char *from, size_t fromlen)
Definition: binascii.c:34
int base64_decode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:396
int base64_encode(char *dest, size_t destlen, const char *src, size_t srclen, int flags)
Definition: binascii.c:215
int base64_encode_nopad(char *dest, size_t destlen, const uint8_t *src, size_t srclen)
Definition: binascii.c:329
int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:506
size_t base64_decode_maxsize(size_t srclen)
Definition: binascii.c:187
size_t base64_encode_size(size_t srclen, int flags)
Definition: binascii.c:166
void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:478
void base32_encode(char *dest, size_t destlen, const char *src, size_t srclen)
Definition: binascii.c:60
Macros to implement mocking and selective exposure for the test code.
Integer definitions used throughout Tor.