mirror of
https://github.com/espressif/openthread.git
synced 2026-08-05 10:27:49 +00:00
[commissioner] change GeneratePskc to use otPskc/Pskc types (#4294)
This commit is contained in:
committed by
Jonathan Hui
parent
09a9aa4e34
commit
090ed57141
@@ -403,25 +403,23 @@ uint16_t otCommissionerGetSessionId(otInstance *aInstance);
|
||||
otCommissionerState otCommissionerGetState(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This method generates PSKc.
|
||||
* This helper function generates PSKc from a given pass-phrase, network name, and extended PAN Id.
|
||||
*
|
||||
* PSKc is used to establish the Commissioner Session.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aPassPhrase The commissioning passphrase.
|
||||
* @param[in] aPassPhrase The commissioning pass-phrase.
|
||||
* @param[in] aNetworkName The network name for PSKc computation.
|
||||
* @param[in] aExtPanId The extended pan id for PSKc computation.
|
||||
* @param[out] aPskc A pointer to the generated PSKc.
|
||||
* @param[in] aExtPanId The extended PAN ID for PSKc computation.
|
||||
* @param[out] aPskc A pointer to variable to output the generated PSKc.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully generate PSKc.
|
||||
* @retval OT_ERROR_INVALID_ARGS If any of the input arguments is invalid.
|
||||
*
|
||||
*/
|
||||
otError otCommissionerGeneratePskc(otInstance * aInstance,
|
||||
const char * aPassPhrase,
|
||||
otError otCommissionerGeneratePskc(const char * aPassPhrase,
|
||||
const char * aNetworkName,
|
||||
const otExtendedPanId *aExtPanId,
|
||||
uint8_t * aPskc);
|
||||
otPskc * aPskc);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
@@ -181,15 +181,12 @@ otCommissionerState otCommissionerGetState(otInstance *aInstance)
|
||||
return instance.Get<MeshCoP::Commissioner>().GetState();
|
||||
}
|
||||
|
||||
otError otCommissionerGeneratePskc(otInstance * aInstance,
|
||||
const char * aPassPhrase,
|
||||
otError otCommissionerGeneratePskc(const char * aPassPhrase,
|
||||
const char * aNetworkName,
|
||||
const otExtendedPanId *aExtPanId,
|
||||
uint8_t * aPskc)
|
||||
otPskc * aPskc)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aInstance);
|
||||
|
||||
return MeshCoP::Commissioner::GeneratePskc(aPassPhrase, aNetworkName,
|
||||
*static_cast<const Mac::ExtendedPanId *>(aExtPanId), aPskc);
|
||||
return MeshCoP::Commissioner::GeneratePskc(
|
||||
aPassPhrase, aNetworkName, *static_cast<const Mac::ExtendedPanId *>(aExtPanId), *static_cast<Pskc *>(aPskc));
|
||||
}
|
||||
#endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
|
||||
|
||||
@@ -1100,7 +1100,7 @@ exit:
|
||||
otError Commissioner::GeneratePskc(const char * aPassPhrase,
|
||||
const char * aNetworkName,
|
||||
const Mac::ExtendedPanId &aExtPanId,
|
||||
uint8_t * aPskc)
|
||||
Pskc & aPskc)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
const char *saltPrefix = "Thread";
|
||||
@@ -1122,7 +1122,7 @@ otError Commissioner::GeneratePskc(const char * aPassPhrase,
|
||||
saltLen += static_cast<uint16_t>(strlen(aNetworkName));
|
||||
|
||||
otPbkdf2Cmac(reinterpret_cast<const uint8_t *>(aPassPhrase), static_cast<uint16_t>(strlen(aPassPhrase)),
|
||||
reinterpret_cast<const uint8_t *>(salt), saltLen, 16384, OT_PSKC_MAX_SIZE, aPskc);
|
||||
reinterpret_cast<const uint8_t *>(salt), saltLen, 16384, OT_PSKC_MAX_SIZE, aPskc.m8);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "meshcop/energy_scan_client.hpp"
|
||||
#include "meshcop/panid_query_client.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
#include "thread/key_manager.hpp"
|
||||
#include "thread/mle.hpp"
|
||||
|
||||
namespace ot {
|
||||
@@ -218,7 +219,7 @@ public:
|
||||
* @param[in] aPassPhrase The commissioning passphrase.
|
||||
* @param[in] aNetworkName The network name for PSKc computation.
|
||||
* @param[in] aExtPanId The extended pan id for PSKc computation.
|
||||
* @param[out] aPskc A pointer to where the generated PSKc will be placed.
|
||||
* @param[out] aPskc A reference to a PSKc where the generated PSKc will be placed.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully generate PSKc.
|
||||
* @retval OT_ERROR_INVALID_ARGS If the length of passphrase is out of range.
|
||||
@@ -227,7 +228,7 @@ public:
|
||||
static otError GeneratePskc(const char * aPassPhrase,
|
||||
const char * aNetworkName,
|
||||
const Mac::ExtendedPanId &aExtPanId,
|
||||
uint8_t * aPskc);
|
||||
Pskc & aPskc);
|
||||
|
||||
/**
|
||||
* This method returns a reference to the AnnounceBeginClient instance.
|
||||
|
||||
@@ -40,7 +40,7 @@ static const otExtendedPanId sXPanId = {{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x0
|
||||
|
||||
void TestMinimumPassphrase(void)
|
||||
{
|
||||
uint8_t pskc[OT_PSKC_MAX_SIZE];
|
||||
ot::Pskc pskc;
|
||||
const uint8_t expectedPskc[] = {0x44, 0x98, 0x8e, 0x22, 0xcf, 0x65, 0x2e, 0xee,
|
||||
0xcc, 0xd1, 0xe4, 0xc0, 0x1d, 0x01, 0x54, 0xf8};
|
||||
const char passphrase[] = "123456";
|
||||
@@ -48,13 +48,13 @@ void TestMinimumPassphrase(void)
|
||||
SuccessOrQuit(ot::MeshCoP::Commissioner::GeneratePskc(passphrase, "OpenThread",
|
||||
static_cast<const ot::Mac::ExtendedPanId &>(sXPanId), pskc),
|
||||
"TestMinimumPassphrase failed to generate PSKc");
|
||||
VerifyOrQuit(memcmp(pskc, expectedPskc, sizeof(pskc)) == 0, "TestMinimumPassphrase got wrong pskc");
|
||||
VerifyOrQuit(memcmp(pskc.m8, expectedPskc, sizeof(pskc)) == 0, "TestMinimumPassphrase got wrong pskc");
|
||||
testFreeInstance(instance);
|
||||
}
|
||||
|
||||
void TestMaximumPassphrase(void)
|
||||
{
|
||||
uint8_t pskc[OT_PSKC_MAX_SIZE];
|
||||
ot::Pskc pskc;
|
||||
const uint8_t expectedPskc[] = {0x9e, 0x81, 0xbd, 0x35, 0xa2, 0x53, 0x76, 0x2f,
|
||||
0x80, 0xee, 0x04, 0xff, 0x2f, 0xa2, 0x85, 0xe9};
|
||||
const char passphrase[] = "1234567812345678"
|
||||
@@ -78,7 +78,7 @@ void TestMaximumPassphrase(void)
|
||||
SuccessOrQuit(ot::MeshCoP::Commissioner::GeneratePskc(passphrase, "OpenThread",
|
||||
static_cast<const ot::Mac::ExtendedPanId &>(sXPanId), pskc),
|
||||
"TestMaximumPassphrase failed to generate PSKc");
|
||||
VerifyOrQuit(memcmp(pskc, expectedPskc, sizeof(pskc)) == 0, "TestMaximumPassphrase got wrong pskc");
|
||||
VerifyOrQuit(memcmp(pskc.m8, expectedPskc, sizeof(pskc)) == 0, "TestMaximumPassphrase got wrong pskc");
|
||||
testFreeInstance(instance);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user