aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2014-09-16 12:36:01 -0400
committerDavid Howells <dhowells@redhat.com>2014-09-16 12:36:01 -0400
commit53d91c5ce0cb8945b55e8bb54e551cabc51eb28d (patch)
treea5b0bd8059a4b2c7a564b8eb1aa6c50c9f1996fd
parent1c9c115ccc76d313f1a9232ffb903de325b64943 (diff)
Provide a binary to hex conversion function
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>
-rw-r--r--include/linux/kernel.h1
-rw-r--r--lib/hexdump.c16
2 files changed, 17 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 4c52907a6d8b..89a0b8e5a952 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -500,6 +500,7 @@ static inline char * __deprecated pack_hex_byte(char *buf, u8 byte)
500 500
501extern int hex_to_bin(char ch); 501extern int hex_to_bin(char ch);
502extern int __must_check hex2bin(u8 *dst, const char *src, size_t count); 502extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
503extern char *bin2hex(char *dst, const void *src, size_t count);
503 504
504int mac_pton(const char *s, u8 *mac); 505int mac_pton(const char *s, u8 *mac);
505 506
diff --git a/lib/hexdump.c b/lib/hexdump.c
index 8499c810909a..270773b91923 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -59,6 +59,22 @@ int hex2bin(u8 *dst, const char *src, size_t count)
59EXPORT_SYMBOL(hex2bin); 59EXPORT_SYMBOL(hex2bin);
60 60
61/** 61/**
62 * bin2hex - convert binary data to an ascii hexadecimal string
63 * @dst: ascii hexadecimal result
64 * @src: binary data
65 * @count: binary data length
66 */
67char *bin2hex(char *dst, const void *src, size_t count)
68{
69 const unsigned char *_src = src;
70
71 while (count--)
72 dst = hex_byte_pack(dst, *_src++);
73 return dst;
74}
75EXPORT_SYMBOL(bin2hex);
76
77/**
62 * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory 78 * hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
63 * @buf: data blob to dump 79 * @buf: data blob to dump
64 * @len: number of bytes in the @buf 80 * @len: number of bytes in the @buf