From: David Howells <dhowells@redhat.com>
Date: Tue, 16 Sep 2014 17:36:01 +0100
Subject: Provide a binary to hex conversion function
Git-commit: 53d91c5ce0cb8945b55e8bb54e551cabc51eb28d
Patch-mainline: v3.18-rc1
References: bsc#1107829 CVE-2018-14633

Provide a function to convert a buffer of binary data into an unterminated
ascii hex string representation of that data.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Acked-by: Lee Duncan <lduncan@suse.com>
---
 include/linux/kernel.h |    1 +
 lib/hexdump.c          |   16 ++++++++++++++++
 2 files changed, 17 insertions(+)

--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -414,6 +414,7 @@ static inline char * __deprecated pack_h
 extern int hex_to_bin(char ch);
 extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
 extern int __must_check _hex2bin(u8 *dst, const char *src, size_t count);
+extern char *bin2hex(char *dst, const void *src, size_t count);
 
 /*
  * General tracing related utility functions - trace_printk(),
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -80,6 +80,22 @@ int _hex2bin(u8 *dst, const char *src, s
 EXPORT_SYMBOL(_hex2bin);
 
 /**
+ * bin2hex - convert binary data to an ascii hexadecimal string
+ * @dst: ascii hexadecimal result
+ * @src: binary data
+ * @count: binary data length
+ */
+char *bin2hex(char *dst, const void *src, size_t count)
+{
+	const unsigned char *_src = src;
+
+	while (count--)
+		dst = pack_hex_byte(dst, *_src++);
+	return dst;
+}
+EXPORT_SYMBOL(bin2hex);
+
+/**
  * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
  * @buf: data blob to dump
  * @len: number of bytes in the @buf
