[INCLUDE]
[reactos.git] / reactos / include / reactos / libs / gnutls / nettle / base16.h
1 /* base16.h
2 *
3 * Hex encoding and decoding, following spki conventions (i.e.
4 * allowing whitespace between digits).
5 */
6
7 /* nettle, low-level cryptographics library
8 *
9 * Copyright (C) 2002 Niels Möller
10 *
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.
15 *
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.
20 *
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.
25 */
26
27 #ifndef NETTLE_BASE16_H_INCLUDED
28 #define NETTLE_BASE16_H_INCLUDED
29
30 #include "nettle-types.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
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
43
44 /* Base16 encoding */
45
46 /* Maximum length of output for base16_encode_update. */
47 #define BASE16_ENCODE_LENGTH(length) ((length) * 2)
48
49 /* Encodes a single byte. Always stores two digits in dst[0] and dst[1]. */
50 void
51 base16_encode_single(uint8_t * dst, uint8_t src);
52
53 /* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
54 void
55 base16_encode_update(uint8_t * dst,
56 unsigned length, const uint8_t * src);
57
58
59 /* Base16 decoding */
60
61 /* Maximum length of output for base16_decode_update. */
62 /* We have at most 4 buffered bits, and a total of (length + 1) * 4 bits. */
63 #define BASE16_DECODE_LENGTH(length) (((length) + 1) / 2)
64
65 struct base16_decode_ctx {
66 unsigned word; /* Leftover bits */
67 unsigned bits; /* Number buffered bits */
68 };
69
70 void
71 base16_decode_init(struct base16_decode_ctx *ctx);
72
73 /* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
74 * errors. */
75 int
76 base16_decode_single(struct base16_decode_ctx *ctx,
77 uint8_t * dst, uint8_t src);
78
79 /* Returns 1 on success, 0 on error. DST should point to an area of
80 * size at least BASE16_DECODE_LENGTH(length), and for sanity
81 * checking, *DST_LENGTH should be initialized to the size of that
82 * area before the call. *DST_LENGTH is updated to the amount of
83 * decoded output. */
84
85 /* Currently results in an assertion failure if *DST_LENGTH is
86 * too small. FIXME: Return some error instead? */
87 int
88 base16_decode_update(struct base16_decode_ctx *ctx,
89 unsigned *dst_length,
90 uint8_t * dst,
91 unsigned src_length, const uint8_t * src);
92
93 /* Returns 1 on success. */
94 int
95 base16_decode_final(struct base16_decode_ctx *ctx);
96
97 #ifdef __cplusplus
98 }
99 #endif
100 #endif /* NETTLE_BASE16_H_INCLUDED */