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>
This commit is contained in:
parent
a3eedc227b
commit
f2b56afd40
1 changed files with 3 additions and 31 deletions
|
@ -18,6 +18,7 @@
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include <linux/kernel.h>
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <linux/crypto.h>
|
#include <linux/crypto.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
|
@ -27,40 +28,11 @@
|
||||||
#include "iscsi_target_nego.h"
|
#include "iscsi_target_nego.h"
|
||||||
#include "iscsi_target_auth.h"
|
#include "iscsi_target_auth.h"
|
||||||
|
|
||||||
static unsigned char chap_asciihex_to_binaryhex(unsigned char val[2])
|
|
||||||
{
|
|
||||||
unsigned char result = 0;
|
|
||||||
/*
|
|
||||||
* MSB
|
|
||||||
*/
|
|
||||||
if ((val[0] >= 'a') && (val[0] <= 'f'))
|
|
||||||
result = ((val[0] - 'a' + 10) & 0xf) << 4;
|
|
||||||
else
|
|
||||||
if ((val[0] >= 'A') && (val[0] <= 'F'))
|
|
||||||
result = ((val[0] - 'A' + 10) & 0xf) << 4;
|
|
||||||
else /* digit */
|
|
||||||
result = ((val[0] - '0') & 0xf) << 4;
|
|
||||||
/*
|
|
||||||
* LSB
|
|
||||||
*/
|
|
||||||
if ((val[1] >= 'a') && (val[1] <= 'f'))
|
|
||||||
result |= ((val[1] - 'a' + 10) & 0xf);
|
|
||||||
else
|
|
||||||
if ((val[1] >= 'A') && (val[1] <= 'F'))
|
|
||||||
result |= ((val[1] - 'A' + 10) & 0xf);
|
|
||||||
else /* digit */
|
|
||||||
result |= ((val[1] - '0') & 0xf);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int chap_string_to_hex(unsigned char *dst, unsigned char *src, int len)
|
static int chap_string_to_hex(unsigned char *dst, unsigned char *src, int len)
|
||||||
{
|
{
|
||||||
int i, j = 0;
|
int j = DIV_ROUND_UP(len, 2);
|
||||||
|
|
||||||
for (i = 0; i < len; i += 2) {
|
hex2bin(dst, src, j);
|
||||||
dst[j++] = (unsigned char) chap_asciihex_to_binaryhex(&src[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
dst[j] = '\0';
|
dst[j] = '\0';
|
||||||
return j;
|
return j;
|
||||||
|
|
Loading…
Reference in a new issue