xref: /freebsd/crypto/openssl/doc/man3/OPENSSL_hexchar2int.pod (revision 66fd12cf4896eb08ad8e7a2627537f84ead84dd3)
1=pod
2
3=head1 NAME
4
5OPENSSL_hexchar2int,
6OPENSSL_hexstr2buf_ex, OPENSSL_hexstr2buf,
7OPENSSL_buf2hexstr_ex, OPENSSL_buf2hexstr
8- Hex encoding and decoding functions
9
10=head1 SYNOPSIS
11
12 #include <openssl/crypto.h>
13
14 int OPENSSL_hexchar2int(unsigned char c);
15 int OPENSSL_hexstr2buf_ex(unsigned char *buf, size_t buf_n, long *buflen,
16                           const char *str, const char sep);
17 unsigned char *OPENSSL_hexstr2buf(const char *str, long *len);
18 int OPENSSL_buf2hexstr_ex(char *str, size_t str_n, size_t *strlength,
19                           const unsigned char *buf, long buflen,
20                           const char sep);
21 char *OPENSSL_buf2hexstr(const unsigned char *buf, long buflen);
22
23=head1 DESCRIPTION
24
25OPENSSL_hexchar2int() converts a hexadecimal character to its numeric
26equivalent.
27
28OPENSSL_hexstr2buf_ex() decodes the hex string B<str> and places the
29resulting string of bytes in the given I<buf>.
30The character I<sep> is the separator between the bytes, setting this to '\0'
31means that there is no separator.
32I<buf_n> gives the size of the buffer.
33If I<buflen> is not NULL, it is filled in with the result length.
34To find out how large the result will be, call this function with NULL
35for I<buf>.
36Colons between two-character hex "bytes" are accepted and ignored.
37An odd number of hex digits is an error.
38
39OPENSSL_hexstr2buf() does the same thing as OPENSSL_hexstr2buf_ex(),
40but allocates the space for the result, and returns the result. It uses a
41default separator of ':'.
42The memory is allocated by calling OPENSSL_malloc() and should be
43released by calling OPENSSL_free().
44
45OPENSSL_buf2hexstr_ex() encodes the contents of the given I<buf> with
46length I<buflen> and places the resulting hexadecimal character string
47in the given I<str>.
48The character I<sep> is the separator between the bytes, setting this to '\0'
49means that there is no separator.
50I<str_n> gives the size of the of the string buffer.
51If I<strlength> is not NULL, it is filled in with the result length.
52To find out how large the result will be, call this function with NULL
53for I<str>.
54
55OPENSSL_buf2hexstr() does the same thing as OPENSSL_buf2hexstr_ex(),
56but allocates the space for the result, and returns the result. It uses a
57default separator of ':'.
58The memory is allocated by calling OPENSSL_malloc() and should be
59released by calling OPENSSL_free().
60
61=head1 RETURN VALUES
62
63OPENSSL_hexchar2int returns the value of a decoded hex character,
64or -1 on error.
65
66OPENSSL_buf2hexstr() and OPENSSL_hexstr2buf()
67return a pointer to allocated memory, or NULL on error.
68
69OPENSSL_buf2hexstr_ex() and OPENSSL_hexstr2buf_ex() return 1 on
70success, or 0 on error.
71
72=head1 COPYRIGHT
73
74Copyright 2016-2022 The OpenSSL Project Authors. All Rights Reserved.
75
76Licensed under the Apache License 2.0 (the "License").  You may not use
77this file except in compliance with the License.  You can obtain a copy
78in the file LICENSE in the source distribution or at
79L<https://www.openssl.org/source/license.html>.
80
81=cut
82