diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2011-09-30 07:39:54 -0400 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2011-10-23 23:20:48 -0400 |
commit | f2b56afd406b455fba339a35f43bfc4ada198073 (patch) | |
tree | f11190e11015c65d75b24ffbd8dee08db2e409e5 /drivers/target/iscsi | |
parent | a3eedc227bfa7c9e21ef3cebe164d06a4c507a71 (diff) |
iscsi-target: use native hex2bin for chap_string_to_hex
This patch converts chap_string_to_hex() to use hex2bin() instead of
the internal chap_asciihex_to_binaryhex().
(nab: Fix up minor compile breakage + typo)
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target/iscsi')
-rw-r--r-- | drivers/target/iscsi/iscsi_target_auth.c | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/drivers/target/iscsi/iscsi_target_auth.c b/drivers/target/iscsi/iscsi_target_auth.c index 11fd74307811..beb39469e7f1 100644 --- a/drivers/target/iscsi/iscsi_target_auth.c +++ b/drivers/target/iscsi/iscsi_target_auth.c | |||
@@ -18,6 +18,7 @@ | |||
18 | * GNU General Public License for more details. | 18 | * GNU General Public License for more details. |
19 | ******************************************************************************/ | 19 | ******************************************************************************/ |
20 | 20 | ||
21 | #include <linux/kernel.h> | ||
21 | #include <linux/string.h> | 22 | #include <linux/string.h> |
22 | #include <linux/crypto.h> | 23 | #include <linux/crypto.h> |
23 | #include <linux/err.h> | 24 | #include <linux/err.h> |
@@ -27,40 +28,11 @@ | |||
27 | #include "iscsi_target_nego.h" | 28 | #include "iscsi_target_nego.h" |
28 | #include "iscsi_target_auth.h" | 29 | #include "iscsi_target_auth.h" |
29 | 30 | ||
30 | static unsigned char chap_asciihex_to_binaryhex(unsigned char val[2]) | ||
31 | { | ||
32 | unsigned char result = 0; | ||
33 | /* | ||
34 | * MSB | ||
35 | */ | ||
36 | if ((val[0] >= 'a') && (val[0] <= 'f')) | ||
37 | result = ((val[0] - 'a' + 10) & 0xf) << 4; | ||
38 | else | ||
39 | if ((val[0] >= 'A') && (val[0] <= 'F')) | ||
40 | result = ((val[0] - 'A' + 10) & 0xf) << 4; | ||
41 | else /* digit */ | ||
42 | result = ((val[0] - '0') & 0xf) << 4; | ||
43 | /* | ||
44 | * LSB | ||
45 | */ | ||
46 | if ((val[1] >= 'a') && (val[1] <= 'f')) | ||
47 | result |= ((val[1] - 'a' + 10) & 0xf); | ||
48 | else | ||
49 | if ((val[1] >= 'A') && (val[1] <= 'F')) | ||
50 | result |= ((val[1] - 'A' + 10) & 0xf); | ||
51 | else /* digit */ | ||
52 | result |= ((val[1] - '0') & 0xf); | ||
53 | |||
54 | return result; | ||
55 | } | ||
56 | |||
57 | static int chap_string_to_hex(unsigned char *dst, unsigned char *src, int len) | 31 | static int chap_string_to_hex(unsigned char *dst, unsigned char *src, int len) |
58 | { | 32 | { |
59 | int i, j = 0; | 33 | int j = DIV_ROUND_UP(len, 2); |
60 | 34 | ||
61 | for (i = 0; i < len; i += 2) { | 35 | hex2bin(dst, src, j); |
62 | dst[j++] = (unsigned char) chap_asciihex_to_binaryhex(&src[i]); | ||
63 | } | ||
64 | 36 | ||
65 | dst[j] = '\0'; | 37 | dst[j] = '\0'; |
66 | return j; | 38 | return j; |