@@ -1082,7 +1082,7 @@ LoRaMacCryptoStatus_t LoRaMacCryptoSetKey( KeyIdentifier_t keyID, uint8_t* key )
10821082 if ( keyID == APP_KEY )
10831083 {
10841084 // Derive lifetime keys
1085- if ( LoRaMacCryptoDeriveMcRootKey ( keyID ) != LORAMAC_CRYPTO_SUCCESS )
1085+ if ( LoRaMacCryptoDeriveMcRootKey ( CryptoCtx . NvmCtx -> LrWanVersion . Fields . Minor , keyID ) != LORAMAC_CRYPTO_SUCCESS )
10861086 {
10871087 return LORAMAC_CRYPTO_ERROR_SECURE_ELEMENT_FUNC ;
10881088 }
@@ -1295,22 +1295,23 @@ LoRaMacCryptoStatus_t LoRaMacCryptoHandleJoinAccept( JoinReqIdentifier_t joinReq
12951295 }
12961296#endif
12971297
1298+ // Derive lifetime keys
1299+ retval = LoRaMacCryptoDeriveMcRootKey ( versionMinor , APP_KEY );
1300+ if ( retval != LORAMAC_CRYPTO_SUCCESS )
1301+ {
1302+ return retval ;
1303+ }
1304+
1305+ retval = LoRaMacCryptoDeriveMcKEKey ( MC_ROOT_KEY );
1306+ if ( retval != LORAMAC_CRYPTO_SUCCESS )
1307+ {
1308+ return retval ;
1309+ }
1310+
12981311#if ( USE_LRWAN_1_1_X_CRYPTO == 1 )
12991312 if ( versionMinor == 1 )
13001313 {
13011314 // Operating in LoRaWAN 1.1.x mode
1302- // Derive lifetime keys
1303- retval = LoRaMacCryptoDeriveMcRootKey ( APP_KEY );
1304- if ( retval != LORAMAC_CRYPTO_SUCCESS )
1305- {
1306- return retval ;
1307- }
1308-
1309- retval = LoRaMacCryptoDeriveMcKEKey ( MC_ROOT_KEY );
1310- if ( retval != LORAMAC_CRYPTO_SUCCESS )
1311- {
1312- return retval ;
1313- }
13141315
13151316 retval = DeriveSessionKey11x ( F_NWK_S_INT_KEY , macMsg -> JoinNonce , joinEUI , nonce );
13161317 if ( retval != LORAMAC_CRYPTO_SUCCESS )
@@ -1340,17 +1341,6 @@ LoRaMacCryptoStatus_t LoRaMacCryptoHandleJoinAccept( JoinReqIdentifier_t joinReq
13401341#endif
13411342 {
13421343 // Operating in LoRaWAN 1.0.x mode
1343- retval = LoRaMacCryptoDeriveMcRootKey ( APP_KEY );
1344- if ( retval != LORAMAC_CRYPTO_SUCCESS )
1345- {
1346- return retval ;
1347- }
1348-
1349- retval = LoRaMacCryptoDeriveMcKEKey ( MC_ROOT_KEY );
1350- if ( retval != LORAMAC_CRYPTO_SUCCESS )
1351- {
1352- return retval ;
1353- }
13541344
13551345 retval = DeriveSessionKey10x ( APP_S_KEY , macMsg -> JoinNonce , macMsg -> NetID , ( uint8_t * )& CryptoCtx .NvmCtx -> DevNonce );
13561346 if ( retval != LORAMAC_CRYPTO_SUCCESS )
@@ -1576,7 +1566,7 @@ LoRaMacCryptoStatus_t LoRaMacCryptoUnsecureMessage( AddressIdentifier_t addrID,
15761566 return LORAMAC_CRYPTO_SUCCESS ;
15771567}
15781568
1579- LoRaMacCryptoStatus_t LoRaMacCryptoDeriveMcRootKey ( KeyIdentifier_t keyID )
1569+ LoRaMacCryptoStatus_t LoRaMacCryptoDeriveMcRootKey ( uint8_t versionMinor , KeyIdentifier_t keyID )
15801570{
15811571 // Prevent other keys than AppKey
15821572 if ( keyID != APP_KEY )
@@ -1585,7 +1575,7 @@ LoRaMacCryptoStatus_t LoRaMacCryptoDeriveMcRootKey( KeyIdentifier_t keyID )
15851575 }
15861576 uint8_t compBase [16 ] = { 0 };
15871577
1588- if ( CryptoCtx . NvmCtx -> LrWanVersion . Fields . Minor == 1 )
1578+ if ( versionMinor == 1 )
15891579 {
15901580 compBase [0 ] = 0x20 ;
15911581 }
0 commit comments