3 Hex encoding and decoding, following spki conventions (i.e.
4 allowing whitespace between digits).
6 Copyright (C) 2002 Niels Möller
8 This file is part of GNU Nettle.
10 GNU Nettle is free software: you can redistribute it and/or
11 modify it under the terms of either:
13 * the GNU Lesser General Public License as published by the Free
14 Software Foundation; either version 3 of the License, or (at your
15 option) any later version.
19 * the GNU General Public License as published by the Free
20 Software Foundation; either version 2 of the License, or (at your
21 option) any later version.
23 or both in parallel, as here.
25 GNU Nettle is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 General Public License for more details.
30 You should have received copies of the GNU General Public License and
31 the GNU Lesser General Public License along with this program. If
32 not, see http://www.gnu.org/licenses/.
35 #ifndef NETTLE_BASE16_H_INCLUDED
36 #define NETTLE_BASE16_H_INCLUDED
38 #include "nettle-types.h"
45 #define base16_encode_single nettle_base16_encode_single
46 #define base16_encode_update nettle_base16_encode_update
47 #define base16_decode_init nettle_base16_decode_init
48 #define base16_decode_single nettle_base16_decode_single
49 #define base16_decode_update nettle_base16_decode_update
50 #define base16_decode_final nettle_base16_decode_final
54 /* Maximum length of output for base16_encode_update. */
55 #define BASE16_ENCODE_LENGTH(length) ((length) * 2)
57 /* Encodes a single byte. Always stores two digits in dst[0] and dst[1]. */
59 base16_encode_single(char *dst,
62 /* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
64 base16_encode_update(char *dst,
71 /* Maximum length of output for base16_decode_update. */
72 /* We have at most 4 buffered bits, and a total of (length + 1) * 4 bits. */
73 #define BASE16_DECODE_LENGTH(length) (((length) + 1) / 2)
75 struct base16_decode_ctx
77 unsigned char word; /* Leftover bits */
78 unsigned char bits; /* Number buffered bits */
82 base16_decode_init(struct base16_decode_ctx *ctx);
84 /* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
87 base16_decode_single(struct base16_decode_ctx *ctx,
91 /* Returns 1 on success, 0 on error. DST should point to an area of
92 * size at least BASE16_DECODE_LENGTH(length). The amount of data
93 * generated is returned in *DST_LENGTH. */
96 base16_decode_update(struct base16_decode_ctx *ctx,
102 /* Returns 1 on success. */
104 base16_decode_final(struct base16_decode_ctx *ctx);
110 #endif /* NETTLE_BASE16_H_INCLUDED */