diff mbox series

tools: Add simple utility to generate the PSK

Message ID 20220721021314.14066-1-denkenz@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show
Series tools: Add simple utility to generate the PSK | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-alpine-ci-fetch success Fetch PR
prestwoj/iwd-ci-gitlint success GitLint
prestwoj/iwd-ci-fetch success Fetch PR
prestwoj/iwd-ci-makedistcheck success Make Distcheck
prestwoj/iwd-ci-incremental_build success Incremental build not run PASS
prestwoj/iwd-alpine-ci-makedistcheck success Make Distcheck
prestwoj/iwd-alpine-ci-incremental_build success Incremental build not run PASS
prestwoj/iwd-ci-build success Build - Configure
prestwoj/iwd-alpine-ci-build success Build - Configure
prestwoj/iwd-ci-clang success clang PASS
prestwoj/iwd-ci-makecheck success Make Check
prestwoj/iwd-ci-makecheckvalgrind success Make Check w/Valgrind
prestwoj/iwd-alpine-ci-makecheckvalgrind success Make Check w/Valgrind
prestwoj/iwd-alpine-ci-makecheck success Make Check
prestwoj/iwd-ci-testrunner success test-runner PASS

Commit Message

Denis Kenzior July 21, 2022, 2:13 a.m. UTC
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

Comments

James Tavares July 21, 2022, 4:05 a.m. UTC | #1
On 7/20/22 10:13 PM, Denis Kenzior wrote:

> 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
Denis Kenzior July 21, 2022, 4:20 a.m. UTC | #2
Hi James,

> 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?

> 
> 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
KeithG July 21, 2022, 1:26 p.m. UTC | #3
James,

Interesting... Which arm distribution are you using?

Keith

On Wed, Jul 20, 2022 at 11:25 PM Denis Kenzior <denkenz@gmail.com> wrote:
>
> Hi James,
>
> > 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?
>
> >
> > 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
>
James Tavares July 21, 2022, 1:39 p.m. UTC | #4
On 7/21/22 9:26 AM, KeithG wrote:

> 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
Michael Nazzareno Trimarchi July 21, 2022, 2:17 p.m. UTC | #5
Hi

On Thu, Jul 21, 2022 at 3:39 PM James Tavares <jtavares@kvh.com> wrote:
>
> On 7/21/22 9:26 AM, KeithG wrote:
>
> > 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.

Can you try to disable caam?

Michael

>
> Regard,s
> James
>
>
diff mbox series

Patch

diff --git a/.gitignore b/.gitignore
index 0886643b8b99..3bd270c070fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/Makefile.am b/Makefile.am
index cffb0738fc55..148ffba0bb67 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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
 
diff --git a/tools/iwd-psk.c b/tools/iwd-psk.c
new file mode 100644
index 000000000000..0a0625c3be8a
--- /dev/null
+++ b/tools/iwd-psk.c
@@ -0,0 +1,70 @@ 
+/*
+ *
+ *  Wireless daemon for Linux
+ *
+ *  Copyright (C) 2022  Intel Corporation. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <stdio.h>
+#include <ell/ell.h>
+
+#include "ell/useful.h"
+#include "src/crypto.h"
+
+static void usage(const char *exec_name)
+{
+	printf("%s - Generate a psk from passphrase\n"
+		"Usage:\n", exec_name);
+	printf("\%s <ssid> <passphrase>\n", exec_name);
+	printf("\n");
+}
+
+int main(int argc, char *argv[])
+{
+	int ret = EXIT_FAILURE;
+	unsigned char *ssid;
+	size_t ssid_len;
+	const char *passphrase;
+	uint8_t psk[32];
+	char *hexpsk;
+	int err;
+
+	if (argc != 3) {
+		usage(argv[0]);
+		goto done;
+	}
+
+	ssid = (unsigned char *) argv[1];
+	ssid_len = strlen(argv[1]);
+	passphrase = argv[2];
+
+	err = crypto_psk_from_passphrase(passphrase, ssid, ssid_len, psk);
+	if (err < 0) {
+		printf("Unable to generate passphrase: %s\n", strerror(-err));
+		goto done;
+	}
+
+	hexpsk = l_util_hexstring(psk, sizeof(psk));
+	printf("PreSharedKey=%s\n", hexpsk);
+	l_free(hexpsk);
+
+	ret = EXIT_SUCCESS;
+
+done:
+	return ret;
+}