mirror of
https://github.com/espressif/openthread.git
synced 2026-09-01 14:59:54 +00:00
[code-style] apply clang-format
This commit is contained in:
+38
-74
@@ -41,49 +41,30 @@
|
||||
*/
|
||||
void TestMacBeaconFrame(void)
|
||||
{
|
||||
uint8_t key[] =
|
||||
{
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
||||
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
uint8_t key[] = {
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
};
|
||||
|
||||
uint8_t test[] =
|
||||
{
|
||||
0x08, 0xD0, 0x84, 0x21, 0x43, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0x48, 0xDE, 0xAC, 0x02, 0x05, 0x00,
|
||||
0x00, 0x00, 0x55, 0xCF, 0x00, 0x00, 0x51, 0x52,
|
||||
0x53, 0x54, 0x22, 0x3B, 0xC1, 0xEC, 0x84, 0x1A,
|
||||
0xB5, 0x53
|
||||
};
|
||||
uint8_t test[] = {0x08, 0xD0, 0x84, 0x21, 0x43, 0x01, 0x00, 0x00, 0x00, 0x00, 0x48, 0xDE,
|
||||
0xAC, 0x02, 0x05, 0x00, 0x00, 0x00, 0x55, 0xCF, 0x00, 0x00, 0x51, 0x52,
|
||||
0x53, 0x54, 0x22, 0x3B, 0xC1, 0xEC, 0x84, 0x1A, 0xB5, 0x53};
|
||||
|
||||
uint8_t encrypted[] =
|
||||
{
|
||||
0x08, 0xD0, 0x84, 0x21, 0x43, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0x48, 0xDE, 0xAC, 0x02, 0x05, 0x00,
|
||||
0x00, 0x00, 0x55, 0xCF, 0x00, 0x00, 0x51, 0x52,
|
||||
0x53, 0x54, 0x22, 0x3B, 0xC1, 0xEC, 0x84, 0x1A,
|
||||
0xB5, 0x53
|
||||
};
|
||||
uint8_t encrypted[] = {0x08, 0xD0, 0x84, 0x21, 0x43, 0x01, 0x00, 0x00, 0x00, 0x00, 0x48, 0xDE,
|
||||
0xAC, 0x02, 0x05, 0x00, 0x00, 0x00, 0x55, 0xCF, 0x00, 0x00, 0x51, 0x52,
|
||||
0x53, 0x54, 0x22, 0x3B, 0xC1, 0xEC, 0x84, 0x1A, 0xB5, 0x53};
|
||||
|
||||
uint8_t decrypted[] =
|
||||
{
|
||||
0x08, 0xD0, 0x84, 0x21, 0x43, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0x48, 0xDE, 0xAC, 0x02, 0x05, 0x00,
|
||||
0x00, 0x00, 0x55, 0xCF, 0x00, 0x00, 0x51, 0x52,
|
||||
0x53, 0x54, 0x22, 0x3B, 0xC1, 0xEC, 0x84, 0x1A,
|
||||
0xB5, 0x53
|
||||
};
|
||||
uint8_t decrypted[] = {0x08, 0xD0, 0x84, 0x21, 0x43, 0x01, 0x00, 0x00, 0x00, 0x00, 0x48, 0xDE,
|
||||
0xAC, 0x02, 0x05, 0x00, 0x00, 0x00, 0x55, 0xCF, 0x00, 0x00, 0x51, 0x52,
|
||||
0x53, 0x54, 0x22, 0x3B, 0xC1, 0xEC, 0x84, 0x1A, 0xB5, 0x53};
|
||||
|
||||
otInstance *instance = testInitInstance();
|
||||
otInstance * instance = testInitInstance();
|
||||
ot::Crypto::AesCcm aesCcm;
|
||||
uint32_t headerLength = sizeof(test) - 8;
|
||||
uint32_t payloadLength = 0;
|
||||
uint8_t tagLength = 8;
|
||||
uint32_t headerLength = sizeof(test) - 8;
|
||||
uint32_t payloadLength = 0;
|
||||
uint8_t tagLength = 8;
|
||||
|
||||
uint8_t nonce[] =
|
||||
{
|
||||
0xAC, 0xDE, 0x48, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x05, 0x02,
|
||||
uint8_t nonce[] = {
|
||||
0xAC, 0xDE, 0x48, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x02,
|
||||
};
|
||||
|
||||
VerifyOrQuit(instance != NULL, "Null OpenThread instance");
|
||||
@@ -93,15 +74,13 @@ void TestMacBeaconFrame(void)
|
||||
aesCcm.Header(test, headerLength);
|
||||
aesCcm.Finalize(test + headerLength, &tagLength);
|
||||
|
||||
VerifyOrQuit(memcmp(test, encrypted, sizeof(encrypted)) == 0,
|
||||
"TestMacBeaconFrame encrypt failed");
|
||||
VerifyOrQuit(memcmp(test, encrypted, sizeof(encrypted)) == 0, "TestMacBeaconFrame encrypt failed");
|
||||
|
||||
aesCcm.Init(headerLength, payloadLength, tagLength, nonce, sizeof(nonce));
|
||||
aesCcm.Header(test, headerLength);
|
||||
aesCcm.Finalize(test + headerLength, &tagLength);
|
||||
|
||||
VerifyOrQuit(memcmp(test, decrypted, sizeof(decrypted)) == 0,
|
||||
"TestMacBeaconFrame decrypt failed");
|
||||
VerifyOrQuit(memcmp(test, decrypted, sizeof(decrypted)) == 0, "TestMacBeaconFrame decrypt failed");
|
||||
|
||||
testFreeInstance(instance);
|
||||
}
|
||||
@@ -111,46 +90,33 @@ void TestMacBeaconFrame(void)
|
||||
*/
|
||||
void TestMacCommandFrame()
|
||||
{
|
||||
uint8_t key[] =
|
||||
{
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
||||
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
uint8_t key[] = {
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
};
|
||||
|
||||
uint8_t test[] =
|
||||
{
|
||||
0x2B, 0xDC, 0x84, 0x21, 0x43, 0x02, 0x00, 0x00,
|
||||
0x00, 0x00, 0x48, 0xDE, 0xAC, 0xFF, 0xFF, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x48, 0xDE, 0xAC, 0x06,
|
||||
0x05, 0x00, 0x00, 0x00, 0x01, 0xCE, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
uint8_t test[] = {
|
||||
0x2B, 0xDC, 0x84, 0x21, 0x43, 0x02, 0x00, 0x00, 0x00, 0x00, 0x48, 0xDE, 0xAC,
|
||||
0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x48, 0xDE, 0xAC, 0x06, 0x05, 0x00,
|
||||
0x00, 0x00, 0x01, 0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
uint32_t headerLength = 29, payloadLength = 1;
|
||||
uint8_t tagLength = 8;
|
||||
uint8_t tagLength = 8;
|
||||
|
||||
uint8_t encrypted[] =
|
||||
{
|
||||
0x2B, 0xDC, 0x84, 0x21, 0x43, 0x02, 0x00, 0x00,
|
||||
0x00, 0x00, 0x48, 0xDE, 0xAC, 0xFF, 0xFF, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x48, 0xDE, 0xAC, 0x06,
|
||||
0x05, 0x00, 0x00, 0x00, 0x01, 0xD8, 0x4F, 0xDE,
|
||||
0x52, 0x90, 0x61, 0xF9, 0xC6, 0xF1,
|
||||
uint8_t encrypted[] = {
|
||||
0x2B, 0xDC, 0x84, 0x21, 0x43, 0x02, 0x00, 0x00, 0x00, 0x00, 0x48, 0xDE, 0xAC,
|
||||
0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x48, 0xDE, 0xAC, 0x06, 0x05, 0x00,
|
||||
0x00, 0x00, 0x01, 0xD8, 0x4F, 0xDE, 0x52, 0x90, 0x61, 0xF9, 0xC6, 0xF1,
|
||||
};
|
||||
|
||||
uint8_t decrypted[] =
|
||||
{
|
||||
0x2B, 0xDC, 0x84, 0x21, 0x43, 0x02, 0x00, 0x00,
|
||||
0x00, 0x00, 0x48, 0xDE, 0xAC, 0xFF, 0xFF, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x48, 0xDE, 0xAC, 0x06,
|
||||
0x05, 0x00, 0x00, 0x00, 0x01, 0xCE, 0x4F, 0xDE,
|
||||
0x52, 0x90, 0x61, 0xF9, 0xC6, 0xF1,
|
||||
uint8_t decrypted[] = {
|
||||
0x2B, 0xDC, 0x84, 0x21, 0x43, 0x02, 0x00, 0x00, 0x00, 0x00, 0x48, 0xDE, 0xAC,
|
||||
0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x48, 0xDE, 0xAC, 0x06, 0x05, 0x00,
|
||||
0x00, 0x00, 0x01, 0xCE, 0x4F, 0xDE, 0x52, 0x90, 0x61, 0xF9, 0xC6, 0xF1,
|
||||
};
|
||||
|
||||
uint8_t nonce[] =
|
||||
{
|
||||
0xAC, 0xDE, 0x48, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x05, 0x06,
|
||||
uint8_t nonce[] = {
|
||||
0xAC, 0xDE, 0x48, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x05, 0x06,
|
||||
};
|
||||
|
||||
ot::Crypto::AesCcm aesCcm;
|
||||
@@ -159,16 +125,14 @@ void TestMacCommandFrame()
|
||||
aesCcm.Header(test, headerLength);
|
||||
aesCcm.Payload(test + headerLength, test + headerLength, payloadLength, true);
|
||||
aesCcm.Finalize(test + headerLength + payloadLength, &tagLength);
|
||||
VerifyOrQuit(memcmp(test, encrypted, sizeof(encrypted)) == 0,
|
||||
"TestMacCommandFrame encrypt failed\n");
|
||||
VerifyOrQuit(memcmp(test, encrypted, sizeof(encrypted)) == 0, "TestMacCommandFrame encrypt failed\n");
|
||||
|
||||
aesCcm.Init(headerLength, payloadLength, tagLength, nonce, sizeof(nonce));
|
||||
aesCcm.Header(test, headerLength);
|
||||
aesCcm.Payload(test + headerLength, test + headerLength, payloadLength, false);
|
||||
aesCcm.Finalize(test + headerLength + payloadLength, &tagLength);
|
||||
|
||||
VerifyOrQuit(memcmp(test, decrypted, sizeof(decrypted)) == 0,
|
||||
"TestMacCommandFrame decrypt failed\n");
|
||||
VerifyOrQuit(memcmp(test, decrypted, sizeof(decrypted)) == 0, "TestMacCommandFrame decrypt failed\n");
|
||||
}
|
||||
|
||||
#ifdef ENABLE_TEST_MAIN
|
||||
|
||||
Reference in New Issue
Block a user