From 52fe1fe5d61b9f3df95b45dd8adb3b7238b1840b Mon Sep 17 00:00:00 2001 From: simon75j Date: Thu, 30 Apr 2009 14:59:54 +0000 Subject: [PATCH] Use hex decoding from libyubikey. git-svn-id: https://yubikey-personalization.googlecode.com/svn/trunk@53 b62f149e-849f-11dd-9899-c7ba65f7c4c7 --- ykpers.c | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/ykpers.c b/ykpers.c index 5310d63..0db2dc5 100644 --- a/ykpers.c +++ b/ykpers.c @@ -71,39 +71,6 @@ int ykp_free_config(CONFIG *cfg) return 0; } -static int hex_to_binary(const char *data, char *dest) -{ - char value; - int desti=0; - char hexstr[3]="xx"; - -/* We only allow an even number of hex digits (full bytes) */ - if (strlen(data) % 2) { - return 0; - } - -/* Convert the hex to binary. */ - while (*data != '\0' && hexstr[1] != '\0') { - int i; - for (i=0; i<2; i++) { - char c; c=tolower(*data); - hexstr[i]=c; - data++; -/* In ASCII, 0-9 == 48-57 and a-f == 97-102. */ - if ( (c<48||(c>57 && c<97)||c>102) && (i!=0 && c!='\0') ) { - return 0; /* Not a valid hex digit */ - } - } - dest[desti] = (char)strtol(hexstr, NULL, 16); - desti+=sizeof(char); - } - -/* Tack a NULL on the end then return the number of bytes - in the converted binary _minus_ the NULL. */ - dest[desti] = '\0'; - return desti; -} - int ykp_AES_key_from_hex(CONFIG *cfg, const char *hexkey) { char aesbin[256]; unsigned long int aeslong; @@ -123,7 +90,7 @@ int ykp_AES_key_from_hex(CONFIG *cfg, const char *hexkey) { } } - hex_to_binary(hexkey, aesbin); + yubikey_hex_decode(aesbin, hexkey, sizeof(aesbin)); memcpy(cfg->key, aesbin, sizeof(cfg->key)); return 0; -- 2.39.5