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