Subject: | "bad decrypt" on high-endian platfrom |
Date: | Mon, 4 Feb 2013 17:15:59 +0100 (CET) |
To: | bug-Filter-Crypto [...] rt.cpan.org |
From: | "Weber, Jörg" <joerg.weber [...] meta-level.de> |
Hi maintainers,
I think I've stumbled across a bug in CryptoCommon-c.inc, where in a loop 2
bytes at a time from a string named "in_text" are converted to a byte value via
sscanf. The call to sscanf with format "%02x" produces a 4-byte value with its
upper 3 bytes all 0. Unfortunately, on a high endian machine like our AIX
servers, storing this value in another string will put the highest byte (0)
instead of the lowest in the intended destination. For me this patch worked:
--- CryptoCommon-c.inc.orig 2013-02-04 16:20:12.000000000 +0100
+++ CryptoCommon-c.inc 2013-02-04 16:13:12.000000000 +0100
@@ -1025,6 +1025,9 @@
FilterCrypto_SvSetCUR(out_sv, out_len);
}
+ /* convert a hex digit with lower case letters to a byte */
+ #define HN2B(hn) (((hn) >= 'a') ? ((hn)-'a'+10) : ((hn)-'0'))
+
/*
* Function to decode the text from one SV into another SV. Inverse function
* of FilterCrypto_EncodeSV().
@@ -1064,7 +1067,7 @@
}
for (i = 0; i < in_len; i += 2) {
- sscanf(in_text + i, "%02x", &out_text[i / 2]);
+ out_text[i/2] = (HN2B(in_text[i]) << 4) | HN2B(in_text[i+1]);
out_len++;
}
Kind regards and thanks for your fine development job,
Jörg Weber
--------------------------------
META-LEVEL Software AG
Saarbrücker Str. 51
66130 Saarbrücken
Germany
Tel: +49 - 681 / 99687-0
Fax: +49 - 681 / 99687-99
Mail: info@meta-level.de <mailto:info@meta-level.de>
Web: www.meta-level.de <http://www.meta-level.de>