1. WPS PIN Code checksum運算 For 8-digit numeric PINs, the last digit in the PIN is used as a checksum of the other digits. Ex: The 7-digit numeric PINs is "1234567". The 8th digit should be "0". ( 1*3 + 2*1 + 3*3 + 4*1 + 5*3 + 6*1 + 7*3 ) = 60 60 % 10 = 0 10 - 0 = 10 10 % 10 = 0 Get the 8th digit is "0". So the 8-digit numberic PINs is "12345670". If the 7-digit numberic PINs is "5967201", the 8th digit should be "2". ( 5*3 + 9*1 + 6*3 + 7*1 + 2*3 + 0*1 + 1*3) = 58 58 % 10 = 8 10 - 8 = 2 2 % 10 = 2 Get the 8th digit is "2". So the 8-digit numberic PINs is "59672012".The corresponding algorithm to compute the checksum digit given the other seven random PIN digits is:
/** * wps_pin_checksum - Compute PIN checksum * @pin: Seven digit PIN (i.e., eight digit PIN without the checksum digit) * Returns: Checksum digit */ unsigned int wps_pin_checksum(unsigned int pin) { unsigned int accum = 0; while (pin) { accum += 3 * (pin % 10); pin /= 10; accum += pin % 10; pin /= 10; } return (10 - accum % 10) % 10; }2. 驗證WPS PIN Code是否合法 The algorithm to validate the checksum is given in C code below.
/** * wps_pin_valid - Check whether a PIN has a valid checksum * @pin: Eight digit PIN (i.e., including the checksum digit) * Returns: 1 if checksum digit is valid, or 0 if not */ unsigned int wps_pin_valid(unsigned int pin) { return wps_pin_checksum(pin / 10) == (pin % 10); }3. 參考來源
http://ftp.netbsd.org/pub/NetBSD/NetBSD-release-6/src/external/bsd/wpa/dist/src/wps/wps_common.c
沒有留言:
張貼留言