mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: vgoyal@redhat.com
Cc: dhowells@redhat.com, keyrings@linux-nfs.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/9] Provide a binary to hex conversion function
Date: Fri, 12 Sep 2014 20:05:15 +0100	[thread overview]
Message-ID: <20140912190515.13239.89507.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20140912190510.13239.90409.stgit@warthog.procyon.org.uk>

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>
---

 include/linux/kernel.h |    1 +
 lib/hexdump.c          |   18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 95624bed87ef..7c0ad8e38510 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -496,6 +496,7 @@ static inline char *hex_byte_pack_upper(char *buf, u8 byte)
 
 extern int hex_to_bin(char ch);
 extern int __must_check hex2bin(u8 *dst, const char *src, size_t count);
+extern char *bin2hex(char *dst, const void *src, size_t count);
 
 bool mac_pton(const char *s, u8 *mac);
 
diff --git a/lib/hexdump.c b/lib/hexdump.c
index 8499c810909a..6daf254dddfa 100644
--- a/lib/hexdump.c
+++ b/lib/hexdump.c
@@ -59,6 +59,24 @@ int hex2bin(u8 *dst, const char *src, size_t count)
 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)
+{
+	while (count--) {
+		unsigned char ch = *(const unsigned char *)src;
+		*dst++ = hex_asc[ch >> 4];
+		*dst++ = hex_asc[ch & 0xf];
+		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


  reply	other threads:[~2014-09-12 19:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-12 19:05 [PATCH 0/9] KEYS: Improve asymmetric key and PKCS#7 handling David Howells
2014-09-12 19:05 ` David Howells [this message]
2014-09-12 20:11   ` [Keyrings] [PATCH 1/9] Provide a binary to hex conversion function Mimi Zohar
2014-09-12 20:30   ` David Howells
2014-09-12 20:47     ` Joe Perches
2014-09-12 20:53     ` David Howells
2014-09-12 20:53     ` Mimi Zohar
2014-09-12 21:14     ` David Howells
2014-09-12 19:05 ` [PATCH 2/9] KEYS: Preparse match data David Howells
2014-09-12 19:05 ` [PATCH 3/9] KEYS: Remove key_type::def_lookup_type David Howells
2014-09-12 19:05 ` [PATCH 4/9] KEYS: Remove key_type::match in favour of overriding default by match_preparse David Howells
2014-09-12 19:05 ` [PATCH 5/9] KEYS: Make the key matching functions return bool David Howells
2014-09-12 19:05 ` [PATCH 6/9] KEYS: Implement binary asymmetric key ID handling David Howells
2014-09-12 19:05 ` [PATCH 7/9] KEYS: Overhaul key identification when searching for asymmetric keys David Howells
2014-09-12 19:05 ` [PATCH 8/9] PKCS#7: Better handling of unsupported crypto David Howells
2014-09-12 19:05 ` [PATCH 9/9] PKCS#7: Handle PKCS#7 messages that contain no X.509 certs David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140912190515.13239.89507.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=keyrings@linux-nfs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vgoyal@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®