Skip to content

Commit 3a55fda

Browse files
committed
Initialize the standard zero key in the soft-se itself.
1 parent 7248bb4 commit 3a55fda

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/mac/LoRaMacClassB.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ static LoRaMacClassBCtx_t Ctx;
190190
*/
191191
static void ComputePingOffset( uint64_t beaconTime, uint32_t address, uint16_t pingPeriod, uint16_t *pingOffset )
192192
{
193-
uint8_t zeroKey[16];
194193
uint8_t buffer[16];
195194
uint8_t cipher[16];
196195
uint32_t result = 0;
@@ -199,7 +198,6 @@ static void ComputePingOffset( uint64_t beaconTime, uint32_t address, uint16_t p
199198
*/
200199
uint32_t time = ( beaconTime % ( ( ( uint64_t ) 1 ) << 32 ) );
201200

202-
memset1( zeroKey, 0, 16 );
203201
memset1( buffer, 0, 16 );
204202
memset1( cipher, 0, 16 );
205203

@@ -213,8 +211,6 @@ static void ComputePingOffset( uint64_t beaconTime, uint32_t address, uint16_t p
213211
buffer[6] = ( address >> 16 ) & 0xFF;
214212
buffer[7] = ( address >> 24 ) & 0xFF;
215213

216-
SecureElementSetKey( SLOT_RAND_ZERO_KEY, zeroKey );
217-
218214
SecureElementAesEncrypt( buffer, 16, SLOT_RAND_ZERO_KEY, cipher );
219215

220216
result = ( ( ( uint32_t ) cipher[0] ) + ( ( ( uint32_t ) cipher[1] ) * 256 ) );

src/peripherals/soft-se/soft-se.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,10 @@ static SecureElementStatus_t ComputeCmac( uint8_t *micBxBuffer, uint8_t *buffer,
159159

160160
SecureElementStatus_t SecureElementInit( SecureElementNvmEvent seNvmCtxChanged )
161161
{
162-
// Initialize with defaults
163162
uint8_t itr = 0;
163+
uint8_t zeroKey[16] = { 0 };
164+
165+
// Initialize with defaults
164166
SeNvmCtx.KeyList[itr++].KeyID = APP_KEY;
165167
SeNvmCtx.KeyList[itr++].KeyID = GEN_APP_KEY;
166168
SeNvmCtx.KeyList[itr++].KeyID = NWK_KEY;
@@ -184,7 +186,10 @@ SecureElementStatus_t SecureElementInit( SecureElementNvmEvent seNvmCtxChanged )
184186
SeNvmCtx.KeyList[itr++].KeyID = MC_KEY_3;
185187
SeNvmCtx.KeyList[itr++].KeyID = MC_APP_S_KEY_3;
186188
SeNvmCtx.KeyList[itr++].KeyID = MC_NWK_S_KEY_3;
187-
SeNvmCtx.KeyList[itr++].KeyID = SLOT_RAND_ZERO_KEY;
189+
SeNvmCtx.KeyList[itr].KeyID = SLOT_RAND_ZERO_KEY;
190+
191+
// Set standard keys
192+
memcpy1( SeNvmCtx.KeyList[itr].KeyValue, zeroKey, KEY_SIZE );
188193

189194
// Assign callback
190195
if( seNvmCtxChanged != 0 )

0 commit comments

Comments
 (0)