Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / base16.h
blob5eae3325bf62546b22b4e76c20bcb911ed848415
1 /* base16.h
3 * Hex encoding and decoding, following spki conventions (i.e.
4 * allowing whitespace between digits).
5 */
7 /* nettle, low-level cryptographics library
9 * Copyright (C) 2002 Niels Möller
11 * The nettle library is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or (at your
14 * option) any later version.
16 * The nettle library is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 * License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with the nettle library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 * MA 02111-1301, USA.
27 #ifndef NETTLE_BASE16_H_INCLUDED
28 #define NETTLE_BASE16_H_INCLUDED
30 #include "nettle-types.h"
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
36 /* Name mangling */
37 #define base16_encode_single nettle_base16_encode_single
38 #define base16_encode_update nettle_base16_encode_update
39 #define base16_decode_init nettle_base16_decode_init
40 #define base16_decode_single nettle_base16_decode_single
41 #define base16_decode_update nettle_base16_decode_update
42 #define base16_decode_final nettle_base16_decode_final
44 /* Base16 encoding */
46 /* Maximum length of output for base16_encode_update. */
47 #define BASE16_ENCODE_LENGTH(length) ((length) * 2)
49 /* Encodes a single byte. Always stores two digits in dst[0] and dst[1]. */
50 void
51 base16_encode_single(uint8_t *dst,
52 uint8_t src);
54 /* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
55 void
56 base16_encode_update(uint8_t *dst,
57 unsigned length,
58 const uint8_t *src);
61 /* Base16 decoding */
63 /* Maximum length of output for base16_decode_update. */
64 /* We have at most 4 buffered bits, and a total of (length + 1) * 4 bits. */
65 #define BASE16_DECODE_LENGTH(length) (((length) + 1) / 2)
67 struct base16_decode_ctx
69 unsigned word; /* Leftover bits */
70 unsigned bits; /* Number buffered bits */
73 void
74 base16_decode_init(struct base16_decode_ctx *ctx);
76 /* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
77 * errors. */
78 int
79 base16_decode_single(struct base16_decode_ctx *ctx,
80 uint8_t *dst,
81 uint8_t src);
83 /* Returns 1 on success, 0 on error. DST should point to an area of
84 * size at least BASE16_DECODE_LENGTH(length), and for sanity
85 * checking, *DST_LENGTH should be initialized to the size of that
86 * area before the call. *DST_LENGTH is updated to the amount of
87 * decoded output. */
89 /* Currently results in an assertion failure if *DST_LENGTH is
90 * too small. FIXME: Return some error instead? */
91 int
92 base16_decode_update(struct base16_decode_ctx *ctx,
93 unsigned *dst_length,
94 uint8_t *dst,
95 unsigned src_length,
96 const uint8_t *src);
98 /* Returns 1 on success. */
99 int
100 base16_decode_final(struct base16_decode_ctx *ctx);
102 #ifdef __cplusplus
104 #endif
106 #endif /* NETTLE_BASE16_H_INCLUDED */