mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-24 06:52:37 +01:00
wscutil: Add wsc_pin_is_checksum_valid
This commit is contained in:
parent
5a8d573ae4
commit
94c49a4563
@ -2531,3 +2531,31 @@ bool wsc_pin_is_valid(const char *pin)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Takes the first 7 characters of a PIN as input and computes a check digit */
|
||||||
|
static char compute_check_digit(const char *pin)
|
||||||
|
{
|
||||||
|
unsigned int accum = 0;
|
||||||
|
unsigned int digit;
|
||||||
|
|
||||||
|
accum += 3 * ((pin[0] - '0') % 10);
|
||||||
|
accum += 1 * ((pin[1] - '0') % 10);
|
||||||
|
accum += 3 * ((pin[2] - '0') % 10);
|
||||||
|
accum += 1 * ((pin[3] - '0') % 10);
|
||||||
|
accum += 3 * ((pin[4] - '0') % 10);
|
||||||
|
accum += 1 * ((pin[5] - '0') % 10);
|
||||||
|
accum += 3 * ((pin[6] - '0') % 10);
|
||||||
|
|
||||||
|
digit = (10 - (accum % 10)) % 10;
|
||||||
|
return '0' + digit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Validates the checksum digit and returns true if valid. Assumes that the
|
||||||
|
* input is an 8-byte PIN already validated by wsc_pin_is_valid()
|
||||||
|
*/
|
||||||
|
bool wsc_pin_is_checksum_valid(const char *pin)
|
||||||
|
{
|
||||||
|
char digit = compute_check_digit(pin);
|
||||||
|
return pin[7] == digit;
|
||||||
|
}
|
||||||
|
@ -639,3 +639,4 @@ struct wsc_session_key {
|
|||||||
bool wsc_kdf(const void *kdk, void *output, size_t size);
|
bool wsc_kdf(const void *kdk, void *output, size_t size);
|
||||||
|
|
||||||
bool wsc_pin_is_valid(const char *pin);
|
bool wsc_pin_is_valid(const char *pin);
|
||||||
|
bool wsc_pin_is_checksum_valid(const char *pin);
|
||||||
|
Loading…
Reference in New Issue
Block a user