to_hex.h 737 B

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