-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/pbkdf2_fast_implementation' into 'master'
esp_wifi: Port fast_pbkdf2 implementation to calculate PMK See merge request espressif/esp-idf!24287
- Loading branch information
Showing
9 changed files
with
478 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
325 changes: 325 additions & 0 deletions
325
components/wpa_supplicant/esp_supplicant/src/crypto/fastpbkdf2.c
Large diffs are not rendered by default.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
components/wpa_supplicant/esp_supplicant/src/crypto/fastpbkdf2.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2015 Joseph Birr-Pixton <[email protected]> | ||
* | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
/* | ||
* fastpbkdf2 - Faster PBKDF2-HMAC calculation | ||
* Written in 2015 by Joseph Birr-Pixton <[email protected]> | ||
* | ||
* To the extent possible under law, the author(s) have dedicated all | ||
* copyright and related and neighboring rights to this software to the | ||
* public domain worldwide. This software is distributed without any | ||
* warranty. | ||
* | ||
* You should have received a copy of the CC0 Public Domain Dedication | ||
* along with this software. If not, see | ||
* <http://creativecommons.org/publicdomain/zero/1.0/>. | ||
*/ | ||
|
||
#ifndef FASTPBKDF2_H | ||
#define FASTPBKDF2_H | ||
|
||
#include <stdlib.h> | ||
#include <stdint.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** Calculates PBKDF2-HMAC-SHA1. | ||
* | ||
* @p npw bytes at @p pw are the password input. | ||
* @p nsalt bytes at @p salt are the salt input. | ||
* @p iterations is the PBKDF2 iteration count and must be non-zero. | ||
* @p nout bytes of output are written to @p out. @p nout must be non-zero. | ||
* | ||
* This function cannot fail; it does not report errors. | ||
*/ | ||
void fastpbkdf2_hmac_sha1(const uint8_t *pw, size_t npw, | ||
const uint8_t *salt, size_t nsalt, | ||
uint32_t iterations, | ||
uint8_t *out, size_t nout); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
*/ | ||
#include "string.h" | ||
#include <inttypes.h> | ||
#include "unity.h" | ||
#include "utils/common.h" | ||
#include "mbedtls/pkcs5.h" | ||
#include "crypto/sha1.h" | ||
|
||
#if SOC_WIFI_SUPPORTED | ||
|
||
#define PMK_LEN 32 | ||
|
||
TEST_CASE("Test pbkdf2", "[crypto-pbkdf2]") | ||
{ | ||
uint8_t PMK[PMK_LEN]; | ||
uint8_t ssid_len; | ||
uint8_t passphrase_len; | ||
uint8_t ssid[MAX_SSID_LEN]; | ||
uint8_t passphrase[MAX_PASSPHRASE_LEN]; | ||
uint8_t expected_pmk1[PMK_LEN] = | ||
{0xe7, 0x90, 0xd0, 0x65, 0x67, 0xf0, 0xbf, 0xca, 0xca, 0x10, 0x88, 0x0b, 0x85, 0xb2, 0x33, 0xe5, | ||
0xe1, 0xd5, 0xe5, 0xb8, 0xd0, 0xfd, 0x94, 0x60, 0x56, 0x95, 0x5e, 0x41, 0x5a, 0x7f, 0xfa, 0xfa}; | ||
|
||
uint8_t expected_pmk[PMK_LEN]; | ||
|
||
/* Compare Fast PBKDF output with expected output*/ | ||
pbkdf2_sha1("espressif", (uint8_t *)"espressif", strlen("espressif"), 4096, PMK, PMK_LEN); | ||
TEST_ASSERT(memcmp(PMK, expected_pmk1, PMK_LEN) == 0); | ||
|
||
/* Compare fast PBKDF output with mbedtls pbkdf2 function's output */ | ||
pbkdf2_sha1("espressif2", (uint8_t *)"espressif2", strlen("espressif2"), 4096, PMK, PMK_LEN); | ||
mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, (const unsigned char *) "espressif2", | ||
strlen("espressif2") , (const unsigned char *)"espressif2", | ||
strlen("espressif2"), 4096, PMK_LEN, expected_pmk); | ||
TEST_ASSERT(memcmp(PMK, expected_pmk, PMK_LEN) == 0); | ||
|
||
/* Calculate PMK using random ssid and passphrase and compare */ | ||
os_memset(ssid, 0, MAX_SSID_LEN); | ||
os_memset(passphrase, 0, MAX_PASSPHRASE_LEN); | ||
ssid_len = os_random(); | ||
ssid_len %= MAX_SSID_LEN; | ||
|
||
os_get_random(ssid, ssid_len); | ||
|
||
passphrase_len = os_random(); | ||
passphrase_len %= MAX_PASSPHRASE_LEN; | ||
|
||
os_get_random(passphrase, passphrase_len); | ||
pbkdf2_sha1((char *)passphrase, ssid, ssid_len, 4096, PMK, PMK_LEN); | ||
mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, (const unsigned char *) passphrase, | ||
strlen((char *)passphrase) , (const unsigned char *)ssid, | ||
ssid_len, 4096, PMK_LEN, expected_pmk); | ||
|
||
/* Dump values if fails */ | ||
if (memcmp(PMK, expected_pmk, PMK_LEN) != 0) { | ||
ESP_LOG_BUFFER_HEXDUMP("passphrase", passphrase, passphrase_len, ESP_LOG_INFO); | ||
ESP_LOG_BUFFER_HEXDUMP("ssid", ssid, ssid_len, ESP_LOG_INFO); | ||
ESP_LOG_BUFFER_HEXDUMP("PMK", PMK, PMK_LEN, ESP_LOG_INFO); | ||
ESP_LOG_BUFFER_HEXDUMP("expected_pmk", expected_pmk, PMK_LEN, ESP_LOG_INFO); | ||
} | ||
TEST_ASSERT(memcmp(PMK, expected_pmk, PMK_LEN) == 0); | ||
} | ||
|
||
#endif /* SOC_WIFI_SUPPORTED */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ These third party libraries can be included into the application (firmware) prod | |
|
||
* `wpa_supplicant`_ Copyright (c) 2003-2022 Jouni Malinen <[email protected]> and contributors and licensed under the BSD license. | ||
|
||
* :component_file:`Fast PBKDF2 <wpa_supplicant/esp_supplicant/src/crypto/crypto_mbedtls.c>` Copyright (c) 2015 Joseph Birr-Pixton and licensed under CC0 Public Domain Dedication license. | ||
|
||
* `FreeBSD net80211`_ Copyright (c) 2004-2008 Sam Leffler, Errno Consulting and licensed under the BSD license. | ||
|
||
* `argtable3`_ argument parsing library Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann and licensed under 3-clause BSD license. argtable3 also includes the following software components. For details, please see argtable3 :component_file:`LICENSE file<console/argtable3/LICENSE>`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters