Skip to contentSkip to conversation

crypto test: use print_hex_dump from <linux/kernel.h>

PATCH Superseded Denis Cheng 5 participants 13 messages Nov 26, 2007 – Nov 30, 2007 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 crypto test: use print_hex_dump from <linux/kernel.h>

these utilities implemented in lib/hexdump.c are more handy, please use this.

---
 crypto/tcrypt.c |   21 +++++++--------------
 1 files changed, 7 insertions(+), 14 deletions(-)
crypto/tcrypt.c +7 -14
index 24141fb..8766023 100644
@@ -81,14 +81,6 @@ static char *check[] = {
 	"camellia", "seed", NULL
 };
 
-static void hexdump(unsigned char *buf, unsigned int len)
-{
-	while (len--)
-		printk("%02x", *buf++);
-
-	printk("\n");
-}
-
 static void tcrypt_complete(struct crypto_async_request *req, int err)
 {
 	struct tcrypt_result *res = req->data;
@@ -156,7 +148,8 @@ static void test_hash(char *algo, struct hash_testvec *template,
 			goto out;
 		}
 
-		hexdump(result, crypto_hash_digestsize(tfm));
+		print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 1, result, crypto_hash_digestsize(tfm), 1);
+
 		printk("%s\n",
 		       memcmp(result, hash_tv[i].digest,
 			      crypto_hash_digestsize(tfm)) ?
@@ -203,7 +196,7 @@ static void test_hash(char *algo, struct hash_testvec *template,
 				goto out;
 			}
 
-			hexdump(result, crypto_hash_digestsize(tfm));
+			print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 1, result, crypto_hash_digestsize(tfm), 1);
 			printk("%s\n",
 			       memcmp(result, hash_tv[i].digest,
 				      crypto_hash_digestsize(tfm)) ?
@@ -319,7 +312,7 @@ static void test_cipher(char *algo, int enc,
 			}
 
 			q = kmap(sg_page(&sg[0])) + sg[0].offset;
-			hexdump(q, cipher_tv[i].rlen);
+			print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 1, q, cipher_tv[i].rlen, 1);
 
 			printk("%s\n",
 			       memcmp(q, cipher_tv[i].result,
@@ -393,7 +386,7 @@ static void test_cipher(char *algo, int enc,
 			for (k = 0; k < cipher_tv[i].np; k++) {
 				printk("page %u\n", k);
 				q = kmap(sg_page(&sg[k])) + sg[k].offset;
-				hexdump(q, cipher_tv[i].tap[k]);
+				print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 1, q, cipher_tv[i].tap[k], 1);
 				printk("%s\n",
 					memcmp(q, cipher_tv[i].result + temp,
 						cipher_tv[i].tap[k]) ? "fail" :
@@ -839,7 +832,7 @@ static void test_deflate(void)
 			printk("fail: ret=%d\n", ret);
 			continue;
 		}
-		hexdump(result, dlen);
+		print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 1, result, dlen, 1);
 		printk("%s (ratio %d:%d)\n",
 		       memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
 		       ilen, dlen);
@@ -870,7 +863,7 @@ static void test_deflate(void)
 			printk("fail: ret=%d\n", ret);
 			continue;
 		}
-		hexdump(result, dlen);
+		print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 1, result, dlen, 1);
 		printk("%s (ratio %d:%d)\n",
 		       memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
 		       ilen, dlen);
Signature · 1 line
1.5.3.5
maintainer
#1 lore raw
Quoted 4 lines · Denis Cheng

these utilities implemented in lib/hexdump.c are more handy, please use this.

OK this is pretty nice. But you just missed out because the GCM patches that just went in added more hexdump uses :)

So could you please refresh your patch against the latest cryptodev tree? Please also clamp those long lines to 80 characters.

On an unrelated note, lib/hexdump.c should not print 8-bit text even though they pass the is_print test. They just turn up as crap on Unicode terminals.

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#2 lore raw

PATCH RESEND 1/1 crypto test: use print_hex_dump from <linux/kernel.h> instead

this patch is against cryptodev-2.6, and have passed scripts/checkpatch.pl

KERN_DEBUG is stripped out, this acts more like the original in tcrypto.c

and the last parameter "bool ascii" set to zero to disable ascii output, this could keep it happy on Unicode terminals.

---
 crypto/tcrypt.c |   30 ++++++++++++++++--------------
 1 files changed, 16 insertions(+), 14 deletions(-)
crypto/tcrypt.c +16 -14
index 24141fb..665aa87 100644
@@ -81,14 +81,6 @@ static char *check[] = {
 	"camellia", "seed", NULL
 };
 
-static void hexdump(unsigned char *buf, unsigned int len)
-{
-	while (len--)
-		printk("%02x", *buf++);
-
-	printk("\n");
-}
-
 static void tcrypt_complete(struct crypto_async_request *req, int err)
 {
 	struct tcrypt_result *res = req->data;
@@ -156,7 +148,9 @@ static void test_hash(char *algo, struct hash_testvec *template,
 			goto out;
 		}
 
-		hexdump(result, crypto_hash_digestsize(tfm));
+		print_hex_dump("", "", DUMP_PREFIX_OFFSET, 16, 1,
+				result, crypto_hash_digestsize(tfm), 0);
+
 		printk("%s\n",
 		       memcmp(result, hash_tv[i].digest,
 			      crypto_hash_digestsize(tfm)) ?
@@ -203,7 +197,9 @@ static void test_hash(char *algo, struct hash_testvec *template,
 				goto out;
 			}
 
-			hexdump(result, crypto_hash_digestsize(tfm));
+			print_hex_dump("", "", DUMP_PREFIX_OFFSET,
+					16, 1,
+					result, crypto_hash_digestsize(tfm), 0);
 			printk("%s\n",
 			       memcmp(result, hash_tv[i].digest,
 				      crypto_hash_digestsize(tfm)) ?
@@ -319,7 +315,9 @@ static void test_cipher(char *algo, int enc,
 			}
 
 			q = kmap(sg_page(&sg[0])) + sg[0].offset;
-			hexdump(q, cipher_tv[i].rlen);
+			print_hex_dump("", "", DUMP_PREFIX_OFFSET,
+					16, 1,
+					q, cipher_tv[i].rlen, 0);
 
 			printk("%s\n",
 			       memcmp(q, cipher_tv[i].result,
@@ -393,7 +391,9 @@ static void test_cipher(char *algo, int enc,
 			for (k = 0; k < cipher_tv[i].np; k++) {
 				printk("page %u\n", k);
 				q = kmap(sg_page(&sg[k])) + sg[k].offset;
-				hexdump(q, cipher_tv[i].tap[k]);
+				print_hex_dump("", "", DUMP_PREFIX_OFFSET,
+						16, 1,
+						q, cipher_tv[i].tap[k], 0);
 				printk("%s\n",
 					memcmp(q, cipher_tv[i].result + temp,
 						cipher_tv[i].tap[k]) ? "fail" :
@@ -839,7 +839,8 @@ static void test_deflate(void)
 			printk("fail: ret=%d\n", ret);
 			continue;
 		}
-		hexdump(result, dlen);
+		print_hex_dump("", "", DUMP_PREFIX_OFFSET, 16, 1,
+				result, dlen, 0);
 		printk("%s (ratio %d:%d)\n",
 		       memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
 		       ilen, dlen);
@@ -870,7 +871,8 @@ static void test_deflate(void)
 			printk("fail: ret=%d\n", ret);
 			continue;
 		}
-		hexdump(result, dlen);
+		print_hex_dump("", "", DUMP_PREFIX_OFFSET, 16, 1,
+				result, dlen, 0);
 		printk("%s (ratio %d:%d)\n",
 		       memcmp(result, tv[i].output, dlen) ? "fail" : "pass",
 		       ilen, dlen);
Signature · 1 line
1.5.3.4
#3 lore raw

Re: [PATCH] [RESEND] crypto test: use print_hex_dump from <linux/kernel.h> instead

crypto/tcrypt.c static char *check[] = { · line 90

Quoted 7 lines · Denis Cheng
crypto/tcrypt.c +0 -7
-static void hexdump(unsigned char *buf, unsigned int len)
-{
-	while (len--)
-		printk("%02x", *buf++);
-
-	printk("\n");
-}
#define hexdump(buf, len) \
	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1, \
	               (buf), (len), false)

requires no other changes.

maintainer
#12 lore raw

Re: [PATCH] [RESEND] crypto test: use print_hex_dump from <linux/kernel.h> instead

In reply to Denis Cheng
Quoted 9 lines · Denis Cheng

this patch is against cryptodev-2.6, and have passed scripts/checkpatch.pl

KERN_DEBUG is stripped out, this acts more like the original in tcrypto.c

and the last parameter "bool ascii" set to zero to disable ascii output, this could keep it happy on Unicode terminals.

Sorry, it still doesn't compile because it doesn't change test_aead. Perhaps you need to pull cryptodev again?

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#4 lore raw

Re: [PATCH] [RESEND] crypto test: use print_hex_dump from <linux/kernel.h> instead

In reply to Joe Perches
Quoted 13 lines · Joe Perches

crypto/tcrypt.c static char *check[] = { · line 90

Quoted 7 lines · Denis Cheng
crypto/tcrypt.c +0 -7
-static void hexdump(unsigned char *buf, unsigned int len)
-{
-	while (len--)
-		printk("%02x", *buf++);
-
-	printk("\n");
-}
#define hexdump(buf, len) \
	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1, \
	               (buf), (len), false)
Quoted 1 line

requires no other changes.

Yes that's a good idea. Denis could you do another patch with this, preferably as a static inline function? That way you don't even need to worry about test_aead.

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#5 lore raw

PATCH RESEND 1/1 crypto test: use print_hex_dump from kernel.h instead

---
this is against the lastest cryptodev tree.

 crypto/tcrypt.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
crypto/tcrypt.c +4 -5
index 1e12b86..ae762c2 100644
@@ -87,12 +87,11 @@ static char *check[] = {
 	"camellia", "seed", "salsa20", NULL
 };
 
-static void hexdump(unsigned char *buf, unsigned int len)
+static inline void hexdump(unsigned char *buf, unsigned int len)
 {
-	while (len--)
-		printk("%02x", *buf++);
-
-	printk("\n");
+	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
+			16, 1,
+			buf, len, 0);
 }
 
 static void tcrypt_complete(struct crypto_async_request *req, int err)
Signature · 1 line
1.5.3.5
#6 lore raw

Re: [PATCH] [RESEND] crypto test: use print_hex_dump from kernel.h instead

Quoted 17 lines · Denis Cheng

---
this is against the lastest cryptodev tree.

 crypto/tcrypt.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
crypto/tcrypt.c +0 -1
index 1e12b86..ae762c2 100644
@@ -87,12 +87,11 @@ static char *check[] = {
 	"camellia", "seed", "salsa20", NULL
 };
 
-static void hexdump(unsigned char *buf, unsigned int len)

crypto/tcrypt.c static char *check[] = { · line 95

Quoted 10 lines
crypto/tcrypt.c +4 -4
+static inline void hexdump(unsigned char *buf, unsigned int len)
 {
-	while (len--)
-		printk("%02x", *buf++);
-
-	printk("\n");
+	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
+			16, 1,
+			buf, len, 0);
 

Not important, but why use '0' instead of 'false'?

Quoted 4 lines
crypto/tcrypt.c +0 -0
 }
 

static void tcrypt_complete(struct crypto_async_request *req, int err)

cu
Richard Knutsson

author
#7 lore raw

Re: [PATCH] [RESEND] crypto test: use print_hex_dump from kernel.h instead

On Nov 27, 2007 10:58 AM, Richard Knutsson <[email protected]> wrote:
...

Quoted 5 lines

Review

Quoted 4 lines
(quoted diff) +3 -0
+     print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
+                     16, 1,
+                     buf, len, 0);

Not important, but why use '0' instead of 'false'?

after read http://lkml.org/lkml/2006/7/27/281, I agreed with you. this is refreshed patch against the lastest cryptodev tree.

---
 crypto/tcrypt.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
crypto/tcrypt.c +4 -5
index 1e12b86..ae762c2 100644
@@ -87,12 +87,11 @@ static char *check[] = {
 	"camellia", "seed", "salsa20", NULL
 };
 
-static void hexdump(unsigned char *buf, unsigned int len)
+static inline void hexdump(unsigned char *buf, unsigned int len)
 {
-	while (len--)
-		printk("%02x", *buf++);
-
-	printk("\n");
+	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
+			16, 1,
+			buf, len, false);
 }
 
 static void tcrypt_complete(struct crypto_async_request *req, int err)
Signature · 1 line
Denis Cheng
#8 lore raw

Re: [PATCH] [RESEND] crypto test: use print_hex_dump from kernel.h instead

crypto/tcrypt.c static char *check[] = { · line 95

Quoted 11 lines · On Tue, 27 Nov 2007 13:03:29 +0800 "rae l" <[email protected]> wrote:
crypto/tcrypt.c +4 -5
-static void hexdump(unsigned char *buf, unsigned int len)
+static inline void hexdump(unsigned char *buf, unsigned int len)
 {
-	while (len--)
-		printk("%02x", *buf++);
-
-	printk("\n");
+	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
+			16, 1,
+			buf, len, false);
 }

uninlining this function shrinks crypto/tcrypt.o's .text from 20,009 bytes down to 19,701.

inlining is almost always wrong.

maintainer
#9 lore raw

Re: [PATCH] [RESEND] crypto test: use print_hex_dump from kernel.h instead

Quoted 17 lines · Andrew Morton

crypto/tcrypt.c static char *check[] = { · line 95

Quoted 11 lines · On Tue, 27 Nov 2007 13:03:29 +0800 "rae l" <[email protected]> wrote:
crypto/tcrypt.c +4 -5
-static void hexdump(unsigned char *buf, unsigned int len)
+static inline void hexdump(unsigned char *buf, unsigned int len)
 {
-	while (len--)
-		printk("%02x", *buf++);
-
-	printk("\n");
+	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
+			16, 1,
+			buf, len, false);
 }

uninlining this function shrinks crypto/tcrypt.o's .text from 20,009 bytes down to 19,701.

Quoted 1 line

inlining is almost always wrong.

I agree. Please do as Andrew suggests and resubmit.

Thanks,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
author
#10 lore raw

Re: [PATCH] [RESEND] crypto test: use print_hex_dump from kernel.h instead

On Nov 29, 2007 7:13 PM, Herbert Xu <[email protected]> wrote:
...

Quoted 6 lines
Quoted 4 lines

uninlining this function shrinks crypto/tcrypt.o's .text from 20,009 bytes down to 19,701.

inlining is almost always wrong.

I agree. Please do as Andrew suggests and resubmit.

inline disabled.

---

crypto/tcrypt.c +3 -4
index 24141fb..13efc72 100644
@@ -83,10 +83,9 @@ static char *check[] = {
 
 static void hexdump(unsigned char *buf, unsigned int len)
 {
-	while (len--)
-		printk("%02x", *buf++);
-
-	printk("\n");
+	print_hex_dump(KERN_CONT, "", DUMP_PREFIX_OFFSET,
+			16, 1,
+			buf, len, false);
 }
 
 static void tcrypt_complete(struct crypto_async_request *req, int err)
Signature · 1 line
Denis Cheng
maintainer
#11 lore raw

Re: [PATCH] [RESEND] crypto test: use print_hex_dump from kernel.h instead

Quoted 3 lines · rae l

Patch applied. Thanks a lot Denis!

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt