From: simon75j Date: Thu, 30 Apr 2009 14:59:54 +0000 (+0000) Subject: Use hex decoding from libyubikey. X-Git-Tag: yubikey-personalisation_0.97-1~110 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=52fe1fe5d61b9f3df95b45dd8adb3b7238b1840b;p=yubikey-personalization Use hex decoding from libyubikey. git-svn-id: https://yubikey-personalization.googlecode.com/svn/trunk@53 b62f149e-849f-11dd-9899-c7ba65f7c4c7 --- 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;