Skip to content

Commit 3eddb29

Browse files
committed
Issue #1348 - Fixed usage of wrong API for general purpose keys
1 parent d018408 commit 3eddb29

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/peripherals/lr1110-se/lr1110-se.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ SecureElementStatus_t SecureElementInit( SecureElementNvmData_t* nvm )
9696

9797
lr1110_crypto_restore_from_flash( &LR1110, &status );
9898

99+
if( status != LR1110_CRYPTO_STATUS_SUCCESS )
100+
{
101+
return ( SecureElementStatus_t ) status;
102+
}
103+
99104
#if defined( SECURE_ELEMENT_PRE_PROVISIONED )
100105
// Read LR1110 pre-provisioned identity
101106
lr1110_system_read_uid( &LR1110, SeNvm->DevEui );
@@ -108,6 +113,10 @@ SecureElementStatus_t SecureElementInit( SecureElementNvmData_t* nvm )
108113
#endif
109114
#endif
110115

116+
const lr1110_crypto_key_t zero_key = { 0 };
117+
lr1110_crypto_set_key( &LR1110, &status,
118+
convert_key_id_from_se_to_lr1110( SLOT_RAND_ZERO_KEY ), zero_key );
119+
111120
return ( SecureElementStatus_t ) status;
112121
}
113122

@@ -198,9 +207,16 @@ SecureElementStatus_t SecureElementAesEncrypt( uint8_t* buffer, uint16_t size, K
198207
return SECURE_ELEMENT_ERROR_NPE;
199208
}
200209

201-
lr1110_crypto_aes_encrypt_01( &LR1110, ( lr1110_crypto_status_t* ) &status,
202-
convert_key_id_from_se_to_lr1110( keyID ), buffer, size, encBuffer );
203-
210+
if( keyID < SLOT_RAND_ZERO_KEY )
211+
{
212+
lr1110_crypto_aes_encrypt_01( &LR1110, ( lr1110_crypto_status_t* ) &status,
213+
convert_key_id_from_se_to_lr1110( keyID ), buffer, size, encBuffer );
214+
}
215+
else
216+
{
217+
lr1110_crypto_aes_encrypt( &LR1110, ( lr1110_crypto_status_t* ) &status,
218+
convert_key_id_from_se_to_lr1110( keyID ), buffer, size, encBuffer );
219+
}
204220
return status;
205221
}
206222

0 commit comments

Comments
 (0)