xref: /freebsd/crypto/openssl/include/internal/to_hex.h (revision e7be843b4a162e68651d3911f0357ed464915629)
1*e7be843bSPierre Pronchery /*
2*e7be843bSPierre Pronchery  * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
3*e7be843bSPierre Pronchery  *
4*e7be843bSPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
5*e7be843bSPierre Pronchery  * this file except in compliance with the License.  You can obtain a copy
6*e7be843bSPierre Pronchery  * in the file LICENSE in the source distribution or at
7*e7be843bSPierre Pronchery  * https://www.openssl.org/source/license.html
8*e7be843bSPierre Pronchery  */
9*e7be843bSPierre Pronchery 
10*e7be843bSPierre Pronchery #ifndef OSSL_INTERNAL_TO_HEX_H
11*e7be843bSPierre Pronchery # define OSSL_INTERNAL_TO_HEX_H
12*e7be843bSPierre Pronchery # pragma once
13*e7be843bSPierre Pronchery 
to_hex(char * buf,uint8_t n,const char hexdig[17])14*e7be843bSPierre Pronchery static ossl_inline size_t to_hex(char *buf, uint8_t n, const char hexdig[17])
15*e7be843bSPierre Pronchery {
16*e7be843bSPierre Pronchery     *buf++ = hexdig[(n >> 4) & 0xf];
17*e7be843bSPierre Pronchery     *buf = hexdig[n & 0xf];
18*e7be843bSPierre Pronchery     return 2;
19*e7be843bSPierre Pronchery }
20*e7be843bSPierre Pronchery 
ossl_to_lowerhex(char * buf,uint8_t n)21*e7be843bSPierre Pronchery static ossl_inline size_t ossl_to_lowerhex(char *buf, uint8_t n)
22*e7be843bSPierre Pronchery {
23*e7be843bSPierre Pronchery     static const char hexdig[] = "0123456789abcdef";
24*e7be843bSPierre Pronchery 
25*e7be843bSPierre Pronchery     return to_hex(buf, n, hexdig);
26*e7be843bSPierre Pronchery }
27*e7be843bSPierre Pronchery #endif
28