Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/nettle/base16.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* base16.h
0002    
0003    Hex encoding and decoding, following spki conventions (i.e.
0004    allowing whitespace between digits).
0005 
0006    Copyright (C) 2002 Niels Möller
0007 
0008    This file is part of GNU Nettle.
0009 
0010    GNU Nettle is free software: you can redistribute it and/or
0011    modify it under the terms of either:
0012 
0013      * the GNU Lesser General Public License as published by the Free
0014        Software Foundation; either version 3 of the License, or (at your
0015        option) any later version.
0016 
0017    or
0018 
0019      * the GNU General Public License as published by the Free
0020        Software Foundation; either version 2 of the License, or (at your
0021        option) any later version.
0022 
0023    or both in parallel, as here.
0024 
0025    GNU Nettle is distributed in the hope that it will be useful,
0026    but WITHOUT ANY WARRANTY; without even the implied warranty of
0027    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0028    General Public License for more details.
0029 
0030    You should have received copies of the GNU General Public License and
0031    the GNU Lesser General Public License along with this program.  If
0032    not, see http://www.gnu.org/licenses/.
0033 */
0034  
0035 #ifndef NETTLE_BASE16_H_INCLUDED
0036 #define NETTLE_BASE16_H_INCLUDED
0037 
0038 #include "nettle-types.h"
0039 
0040 #ifdef __cplusplus
0041 extern "C" {
0042 #endif
0043 
0044 /* Name mangling */
0045 #define base16_encode_single nettle_base16_encode_single
0046 #define base16_encode_update nettle_base16_encode_update
0047 #define base16_decode_init nettle_base16_decode_init
0048 #define base16_decode_single nettle_base16_decode_single
0049 #define base16_decode_update nettle_base16_decode_update
0050 #define base16_decode_final nettle_base16_decode_final
0051 
0052 /* Base16 encoding */
0053 
0054 /* Maximum length of output for base16_encode_update. */
0055 #define BASE16_ENCODE_LENGTH(length) ((length) * 2)
0056 
0057 /* Encodes a single byte. Always stores two digits in dst[0] and dst[1]. */
0058 void
0059 base16_encode_single(char *dst,
0060              uint8_t src);
0061 
0062 /* Always stores BASE16_ENCODE_LENGTH(length) digits in dst. */
0063 void
0064 base16_encode_update(char *dst,
0065              size_t length,
0066              const uint8_t *src);
0067 
0068 
0069 /* Base16 decoding */
0070 
0071 /* Maximum length of output for base16_decode_update. */
0072 /* We have at most 4 buffered bits, and a total of (length + 1) * 4 bits. */
0073 #define BASE16_DECODE_LENGTH(length) (((length) + 1) / 2)
0074 
0075 struct base16_decode_ctx
0076 {
0077   unsigned char word; /* Leftover bits */
0078   unsigned char bits; /* Number buffered bits */
0079 };
0080 
0081 void
0082 base16_decode_init(struct base16_decode_ctx *ctx);
0083 
0084 /* Decodes a single byte. Returns amount of output (0 or 1), or -1 on
0085  * errors. */
0086 int
0087 base16_decode_single(struct base16_decode_ctx *ctx,
0088              uint8_t *dst,
0089              char src);
0090 
0091 /* Returns 1 on success, 0 on error. DST should point to an area of
0092  * size at least BASE16_DECODE_LENGTH(length). The amount of data
0093  * generated is returned in *DST_LENGTH. */
0094 
0095 int
0096 base16_decode_update(struct base16_decode_ctx *ctx,
0097              size_t *dst_length,
0098              uint8_t *dst,
0099              size_t src_length,
0100              const char *src);
0101 
0102 /* Returns 1 on success. */
0103 int
0104 base16_decode_final(struct base16_decode_ctx *ctx);
0105 
0106 #ifdef __cplusplus
0107 }
0108 #endif
0109 
0110 #endif /* NETTLE_BASE16_H_INCLUDED */