eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit 116b36e94368e9d29dc35fd4f50107de996bb10d
parent fbb077671698fa7a014cdd8724f922bfe9032210
Author: Andrew Zaborowski <andrew.zaborowski@intel.com>
Date:   Fri, 11 Sep 2020 21:50:58 +0200

p2putil: Add p2p_get_random_string

Add a utility to select random characters from the set defined in P2P
v1.7 Section 3.2.1.  In this version the assumption is that we're only
actually using this for the two SSID characters.

Diffstat:
Msrc/p2putil.c | 33+++++++++++++++++++++++++++++++++
Msrc/p2putil.h | 2++
2 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/src/p2putil.c b/src/p2putil.c @@ -2611,3 +2611,36 @@ uint8_t *p2p_build_go_disc_req(size_t *out_len) return p2p_build_action_frame(false, P2P_ACTION_GO_DISCOVERABILITY_REQ, 0, NULL, NULL, NULL, 0, out_len); } + +/* + * Select a string of random characters from the set defined in section + * 3.2.1: + * + * "Following "DIRECT-" the SSID shall contain two ASCII characters "xy", + * randomly selected with a uniform distribution from the following + * character set: upper case letters, lower case letters and numbers." + * + * "The WPA2-Personal pass-phrase shall contain at least eight ASCII + * characters randomly selected with a uniform distribution from the + * following character set: upper case letters, lower case letters and + * numbers." + * + * Our random distribution is not uniform but close enough for use in + * the SSID. + */ +void p2p_get_random_string(char *buf, size_t len) +{ +#define CHARSET "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" \ + "0123456789" + static const int set_size = strlen(CHARSET); + + l_getrandom(buf, len); + + while (len) { + int index = *buf % set_size; + + *buf++ = CHARSET[index]; + len--; + } +#undef CHARSET +} diff --git a/src/p2putil.h b/src/p2putil.h @@ -603,3 +603,5 @@ uint8_t *p2p_build_presence_req(const struct p2p_presence_req *data, uint8_t *p2p_build_presence_resp(const struct p2p_presence_resp *data, size_t *out_len); uint8_t *p2p_build_go_disc_req(size_t *out_len); + +void p2p_get_random_string(char *buf, size_t len);