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_generate
This commit is contained in:
parent
7440b5e98d
commit
230a4f4bab
@ -27,6 +27,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <ell/ell.h>
|
||||
|
||||
@ -2559,3 +2560,23 @@ bool wsc_pin_is_checksum_valid(const char *pin)
|
||||
char digit = compute_check_digit(pin);
|
||||
return pin[7] == digit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate an 8 character PIN string into buffer given by @pin. @pin must be
|
||||
* at least 9 bytes long to account for the nul character.
|
||||
*/
|
||||
bool wsc_pin_generate(char *pin)
|
||||
{
|
||||
uint32_t random;
|
||||
bool ok;
|
||||
|
||||
ok = l_getrandom(&random, sizeof(random));
|
||||
if (!ok)
|
||||
return ok;
|
||||
|
||||
snprintf(pin, 8, "%07u", random);
|
||||
pin[7] = compute_check_digit(pin);
|
||||
pin[8] = '\0';
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -640,3 +640,4 @@ bool wsc_kdf(const void *kdk, void *output, size_t size);
|
||||
|
||||
bool wsc_pin_is_valid(const char *pin);
|
||||
bool wsc_pin_is_checksum_valid(const char *pin);
|
||||
bool wsc_pin_generate(char *pin);
|
||||
|
Loading…
Reference in New Issue
Block a user