Skip to contentSkip to conversation

tools: Add simple utility to generate the PSK

PATCH In review Denis Kenzior 4 participants 6 messages Jul 21, 2022 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: Add simple utility to generate the PSK

This utility is the equivalent to wpa_passphrase and produces a PSK as would be generated by iwd.

---
 .gitignore      |  1 +
 Makefile.am     |  5 +++-
 tools/iwd-psk.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 tools/iwd-psk.c
.gitignore +1 -0
index 0886643b8b99..3bd270c070fe 100644
@@ -38,6 +38,7 @@ tools/hwsim
 tools/hwsim.1
 tools/probe-req
 tools/iwd-decrypt-profile
+tools/iwd-psk
 unit/test-cmac-aes
 unit/test-arc4
 unit/test-hmac-md5
Makefile.am +4 -1
index cffb0738fc55..148ffba0bb67 100644
@@ -363,7 +363,7 @@ man_MANS += wired/ead.8
 endif
 endif
 
-noinst_PROGRAMS += tools/probe-req tools/iwd-decrypt-profile
+noinst_PROGRAMS += tools/probe-req tools/iwd-decrypt-profile tools/iwd-psk
 
 tools_probe_req_SOURCES = tools/probe-req.c src/mpdu.h src/mpdu.c \
 					src/ie.h src/ie.c \
@@ -379,6 +379,9 @@ tools_iwd_decrypt_profile_SOURCES = tools/iwd-decrypt-profile.c \
 					src/storage.h src/storage.c
 tools_iwd_decrypt_profile_LDADD = ${ell_ldadd}
 
+tools_iwd_psk_SOURCES = tools/iwd-psk.c src/crypto.h src/crypto.c
+tools_iwd_psk_LDADD = ${ell_ldadd}
+
 if HWSIM
 bin_PROGRAMS += tools/hwsim
 
tools/iwd-psk.c new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.35.1
#1 lore raw
Quoted 2 lines · Denis Kenzior

This utility is the equivalent to wpa_passphrase and produces a PSK as would be generated by iwd.

Awesome! Thank you. With this, I was able able to confirm that there is indeed a problem at the 40/41 character mark. Passphrases of 40 characters reliably produce the same pre-shared keys as wpa_passphrase. Passphrases of characters 41 and greater produce random pre-shared keys (although they sometimes repeat, as-if there was an uninitialized memory, alignment or aliasing issue?).

My other observation is that iwd-psk (@ 0.450 seconds) is considerably slower than wpa_passphrase (@ 0.017 seconds) at generating a pre-shared key.

Here is an example at 40 characters:

- iwd-pk:

$ i=10; while [ $i -gt 0 ]; do ./iwd-psk ShortWiFiName
0000000000111111111122222222223333333333; ((i--)); done
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc

- wpa_passphrase:

$ i=10; while [ $i -gt 0 ]; do wpa_passphrase ShortWiFiName
0000000000111111111122222222223333333333 | grep psk | grep -v \#;
((i--)); done
psk=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
psk=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
psk=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
psk=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
psk=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
psk=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
psk=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
psk=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
psk=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
psk=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc

Here is an example at 41 characters:

- iwd-psk:

$ i=10; while [ $i -gt 0 ]; do ./iwd-psk ShortWiFiName
00000000001111111111222222222233333333334; ((i--)); done
PreSharedKey=d11a9661447c2cbf945148b305f0cf6caccac072158b8be7a0ce3a8dc28cd5c4
PreSharedKey=f5c7f45c4f8ca1ece53c0118513893b50ddbd05153d4f3bc7295cd5acbfb12e3
PreSharedKey=a7edff123b9710da3d36f18a700fc3b1e214fa5f0ad4c2681f629a0248ebe5da
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
PreSharedKey=aeff2dbc47d74eacd4a27e5b7e4bb6dccb7376d013d6eebfbc12b75a5632aa22
PreSharedKey=6fa3c9218bf6abd053ed640ad90f301d55732d1dc9562c637b40ec4e78496e9a
PreSharedKey=934e0f09e85b1efabd89df31a9c24faf916049b7fcf6c9ce18cbaded1cb1ad49
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc
PreSharedKey=9523012d845c07633331ca915761e6610d9cc23194b8704863a2ffd848ac72d1
PreSharedKey=f9408e131af312a8a49128f802b8b755a50aa352a903307bbf5671d876efe7cc

- wpa_passphrase:

$ i=10; while [ $i -gt 0 ]; do wpa_passphrase ShortWiFiName
00000000001111111111222222222233333333334 | grep psk | grep -v \#;
((i--)); done
	psk=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2
psk=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2
psk=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2
psk=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2
psk=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2
psk=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2
psk=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2
psk=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2
psk=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2
psk=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2
#2 lore raw

Hi James,

Quoted 6 lines

Awesome! Thank you. With this, I was able able to confirm that there is indeed a problem at the 40/41 character mark. Passphrases of 40 characters reliably produce the same pre-shared keys as wpa_passphrase. Passphrases of characters 41 and greater produce random pre-shared keys (although they sometimes repeat, as-if there was an uninitialized memory, alignment or aliasing issue?).

Using your 41-char example:

denkenz@localhost ~/iwd-master/tools $ i=10; while [ $i -gt 0 ]; do ./iwd-psk ShortWiFiName 00000000001111111111222222222233333333334; ((i--)); done PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2

Not sure what to say... Maybe there's something subtle being triggered by being on ARM? Kernel bug?

Quoted 5 lines

My other observation is that iwd-psk (@ 0.450 seconds) is considerably slower than wpa_passphrase (@ 0.017 seconds) at generating a pre-shared key.

Yes, that is something we're aware of. Kernel doesn't have a native pbkdf2 transformation, so we end up re-trapping into the kernel many times and that is slow. Hence we cache the PSK for subsequent connections.

Regards,
-Denis

#3 lore raw

James,

Interesting... Which arm distribution are you using?

Keith

Quoted 41 lines · Denis Kenzior

Hi James,

Quoted 6 lines

Awesome! Thank you. With this, I was able able to confirm that there is indeed a problem at the 40/41 character mark. Passphrases of 40 characters reliably produce the same pre-shared keys as wpa_passphrase. Passphrases of characters 41 and greater produce random pre-shared keys (although they sometimes repeat, as-if there was an uninitialized memory, alignment or aliasing issue?).

Using your 41-char example:

denkenz@localhost ~/iwd-master/tools $ i=10; while [ $i -gt 0 ]; do ./iwd-psk ShortWiFiName 00000000001111111111222222222233333333334; ((i--)); done PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2 PreSharedKey=64f0097675bbe0d4c316bdddfff3321fc39dbb11d2a629ff34cd1ee74ac112c2

Not sure what to say... Maybe there's something subtle being triggered by being on ARM? Kernel bug?

Quoted 5 lines

My other observation is that iwd-psk (@ 0.450 seconds) is considerably slower than wpa_passphrase (@ 0.017 seconds) at generating a pre-shared key.

Yes, that is something we're aware of. Kernel doesn't have a native pbkdf2 transformation, so we end up re-trapping into the kernel many times and that is slow. Hence we cache the PSK for subsequent connections.

Regards,
-Denis

#4 lore raw
Quoted 1 line · KeithG

Interesting... Which arm distribution are you using?

NXP (aka "Freescale") Linux kernel (based on kernel 5.10.9) Variscite Linux layer
Yocto Gatesgarth

Hardware is a DART-MX8M-PLUS SOM from Variscite with an NXP i.MX 8M Plus processor.

Does anyone have a suggestion for a libkcapi-based test that help isolate kernel issue vs. iwd issue?

I was looking at the kcapi-dgst tool but honest have gotten a little tripped up with it.

Regard,s
James

#5 lore raw

Hi

Quoted 13 lines · James Tavares
Quoted 1 line · KeithG

Interesting... Which arm distribution are you using?

NXP (aka "Freescale") Linux kernel (based on kernel 5.10.9) Variscite Linux layer
Yocto Gatesgarth

Hardware is a DART-MX8M-PLUS SOM from Variscite with an NXP i.MX 8M Plus processor.

Quoted 5 lines

Does anyone have a suggestion for a libkcapi-based test that help isolate kernel issue vs. iwd issue?

I was looking at the kcapi-dgst tool but honest have gotten a little tripped up with it.

Can you try to disable caam?

Michael

Quoted 5 lines

Regard,s
James

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com