1 .TH IPSEC_TTODATA 3 "12 March 2002"
2 .\" RCSID $Id: ttodata.3,v 1.4 2002/03/12 17:04:58 henry Exp $
4 ipsec ttodata, datatot \- convert binary data bytes from and to text formats
6 .B "#include <freeswan.h>"
8 .B "const char *ttodata(const char *src, size_t srclen,"
10 .B "int base, char *dst, size_t dstlen, size_t *lenp);"
12 .B "const char *ttodatav(const char *src, size_t srclen,"
14 .B "int base, char *dst, size_t dstlen, size_t *lenp,"
16 .B "char *errp, size_t errlen);"
18 .B "size_t datatot(const char *src, size_t srclen,"
20 .B "int format, char *dst, size_t dstlen);"
26 convert arbitrary binary data (e.g. encryption or authentication keys)
27 from and to more-or-less human-readable text formats.
29 Currently supported formats are hexadecimal, base64, and characters.
31 A hexadecimal text value begins with a
35 prefix and continues with two-digit groups
36 of hexadecimal digits (0-9, and a-f or A-F),
37 each group encoding the value of one binary byte, high-order digit first.
41 between consecutive groups is ignored, permitting punctuation to improve
42 readability; doing this every eight digits seems about right.
44 A base64 text value begins with a
49 and continues with four-digit groups of base64 digits (A-Z, a-z, 0-9, +, and /),
50 each group encoding the value of three binary bytes as described in
51 section 6.8 of RFC 2045.
52 Note that the last one or two digits of a base64 group can be
54 to indicate that fewer than three binary bytes are encoded.
56 A character text value begins with a
61 and continues with text characters, each being the value of one binary byte.
63 All these functions basically copy data from
65 (whose size is specified by
69 (whose size is specified by
71 doing the conversion en route.
72 If the result will not fit in
75 under no circumstances are more than
77 bytes of result written to
80 can be zero, in which case
82 need not be valid and no result bytes are written at all.
90 specifies what format the input is in;
93 to signify that this gets figured out from the prefix.
99 respectively signify hexadecimal, base64, and character-text formats
106 a single character used as a type code,
107 specifies which text format is wanted.
112 but a zero value) specifies a reasonable default.
113 Other currently-supported values are:
117 continuous lower-case hexadecimal with a
122 lower-case hexadecimal with a
129 lower-case hexadecimal with no prefix or
133 continuous base64 with a
138 continuous base64 with no prefix
141 The default format is currently
145 returns NULL for success and
146 a pointer to a string-literal error message for failure;
153 is set to the number of bytes required to contain the full untruncated result.
154 It is the caller's responsibility to check this against
156 to determine whether he has obtained a complete result.
159 value is correct even if
161 is zero, which offers a way to determine how much space would be needed
162 before having to allocate any.
167 except that in certain cases,
171 the buffer pointed to by
173 (whose length is given by
175 is used to hold a more detailed error message.
176 The return value is NULL for success,
179 or a pointer to a string literal for failure.
180 If the size of the error-message buffer is
181 inadequate for the desired message,
183 will fall back on returning a pointer to a literal string instead.
186 header file defines a constant
188 which is the size of a buffer large enough for worst-case results.
190 The normal return value of
192 is the number of bytes required
193 to contain the full untruncated result.
194 It is the caller's responsibility to check this against
196 to determine whether he has obtained a complete result.
197 The return value is correct even if
199 is zero, which offers a way to determine how much space would be needed
200 before having to allocate any.
203 signals a fatal error of some kind
218 must not include the terminating NUL.
223 the result supplied by
225 is always NUL-terminated,
226 and its needed-size return value includes space for the terminating NUL.
228 Several obsolete variants of these functions
234 are temporarily also supported.
236 sprintf(3), ipsec_atoaddr(3)
243 unknown characters in the input;
244 unknown or missing prefix;
246 incomplete digit group;
247 non-zero padding in a base64 less-than-three-bytes digit group;
256 Written for the FreeS/WAN project by Henry Spencer.
259 should have a format code to produce character-text output.
265 prefixes are the author's inventions and are not a standard
267 They have been chosen to avoid collisions with existing practice
268 (some C implementations use
271 and possible confusion with unprefixed hexadecimal.