From 56fbdc2372f1afbe90bc0386ef714115884dbca3 Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <PromyLOPh@lavabit.com>
Date: Tue, 7 Oct 2008 12:39:14 +0200
Subject: piano: Use faster hex2int conversion

---
 libpiano/src/crypt.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/libpiano/src/crypt.c b/libpiano/src/crypt.c
index eef1057..43edd0c 100644
--- a/libpiano/src/crypt.c
+++ b/libpiano/src/crypt.c
@@ -38,15 +38,12 @@ THE SOFTWARE.
 void PianoHexToInts (const char *strHex, unsigned int **retInts,
 		size_t *retIntsN) {
 	size_t i, strHexN = strlen (strHex);
-	char hexInt[9];
 	unsigned int *arrInts = calloc (strHexN / 8, sizeof (*arrInts));
 
-	/* FIXME: error handling: string too short, e.g. */
 	/* unsigned int = 4 bytes, 8 chars in hex */
-	for (i = 0; i < strHexN; i += 8) {
-		memcpy (hexInt, strHex+i, sizeof (hexInt)-1);
-		hexInt[sizeof (hexInt) - 1] = 0;
-		sscanf (hexInt, "%x", &arrInts[i/8]);
+	for (i = 0; i < strHexN; i++) {
+		arrInts[i/8] |= ((strHex[i] < 'a' ? strHex[i]: strHex[i] + 9) &
+				0x0f) << (7*4 - i*4);
 	}
 	*retInts = arrInts;
 	*retIntsN = strHexN / 8;
-- 
cgit v1.2.3