@@ -306,9 +306,6 @@ ble_hw_encrypt_block(struct ble_encryption_block *ecb)
306306 return rc ;
307307}
308308#else
309- #define NRF_ECB NRF_ECB00
310- #define NRF_AAR NRF_AAR00
311-
312309/* ECB data structure */
313310struct ecb_job_entry {
314311 uint8_t * ptr ;
@@ -329,9 +326,9 @@ ble_hw_encrypt_block(struct ble_encryption_block *ecb)
329326 nrf_ecb_task_trigger (NRF_ECB , NRF_ECB_TASK_STOP );
330327
331328 ecb_input_job_list [0 ].ptr = ecb -> plain_text ;
332- ecb_input_job_list [0 ].attr_and_length = (11 << 24 ) | ( 16 & 0x00ffffff ) ;
329+ ecb_input_job_list [0 ].attr_and_length = (ECB_ATTR_DATA << 24 ) | 16 ;
333330 ecb_output_job_list [0 ].ptr = ecb -> cipher_text ;
334- ecb_output_job_list [0 ].attr_and_length = (11 << 24 ) | ( 16 & 0x00ffffff ) ;
331+ ecb_output_job_list [0 ].attr_and_length = (ECB_ATTR_DATA << 24 ) | 16 ;
335332
336333 /* The end of a job list shall be 0 */
337334 ecb_input_job_list [1 ].ptr = 0 ;
@@ -343,7 +340,14 @@ ble_hw_encrypt_block(struct ble_encryption_block *ecb)
343340 NRF_ECB -> EVENTS_ERROR = 0 ;
344341 NRF_ECB -> IN .PTR = (uint32_t )ecb_input_job_list ;
345342 NRF_ECB -> OUT .PTR = (uint32_t )ecb_output_job_list ;
346- memcpy ((void * )NRF_ECB -> KEY .VALUE , ecb -> key , sizeof (uint32_t ) * 4 );
343+ /* nRF54L KEY.VALUE uses reversed byte order (same as CCM) */
344+ {
345+ const uint32_t * kp = (const uint32_t * )ecb -> key ;
346+ NRF_ECB -> KEY .VALUE [0 ] = __builtin_bswap32 (kp [3 ]);
347+ NRF_ECB -> KEY .VALUE [1 ] = __builtin_bswap32 (kp [2 ]);
348+ NRF_ECB -> KEY .VALUE [2 ] = __builtin_bswap32 (kp [1 ]);
349+ NRF_ECB -> KEY .VALUE [3 ] = __builtin_bswap32 (kp [0 ]);
350+ }
347351
348352 /* Start ECB */
349353 nrf_ecb_task_trigger (NRF_ECB , NRF_ECB_TASK_START );
@@ -508,7 +512,8 @@ ble_rng_isr(void)
508512 /* No callback? Clear and disable interrupts */
509513 if (g_ble_rng_isr_cb == NULL ) {
510514 nrf_cracen_int_disable (NRF_CRACEN , NRF_CRACEN_INT_RNG_MASK );
511- NRF_CRACENCORE -> RNGCONTROL .CONTROL &= ~CRACENCORE_RNGCONTROL_CONTROL_INTENFULL_Msk ;
515+ NRF_CRACENCORE -> RNGCONTROL .CONTROL &=
516+ ~CRACENCORE_RNGCONTROL_CONTROL_INTENFULL_Msk ;
512517 NRF_CRACEN -> EVENTS_RNG = 0 ;
513518 os_trace_isr_exit ();
514519 return ;
@@ -538,10 +543,10 @@ int
538543ble_hw_rng_init (ble_rng_isr_cb_t cb , int bias )
539544{
540545 NRF_CRACEN -> ENABLE = CRACEN_ENABLE_CRYPTOMASTER_Msk |
541- CRACEN_ENABLE_RNG_Msk |
542- CRACEN_ENABLE_PKEIKG_Msk ;
546+ CRACEN_ENABLE_RNG_Msk | CRACEN_ENABLE_PKEIKG_Msk ;
543547
544- while (NRF_CRACENCORE -> PK .STATUS & CRACENCORE_PK_STATUS_PKBUSY_Msk );
548+ while (NRF_CRACENCORE -> PK .STATUS & CRACENCORE_PK_STATUS_PKBUSY_Msk )
549+ ;
545550 NRF_CRACENCORE -> PK .CONTROL &= ~CRACENCORE_IKG_PKECONTROL_CLEARIRQ_Msk ;
546551
547552 NRF_CRACENCORE -> RNGCONTROL .CONTROL = CRACENCORE_RNGCONTROL_CONTROL_ResetValue |
@@ -573,7 +578,8 @@ ble_hw_rng_start(void)
573578
574579 if (g_ble_rng_isr_cb ) {
575580 nrf_cracen_int_enable (NRF_CRACEN , NRF_CRACEN_INT_RNG_MASK );
576- NRF_CRACENCORE -> RNGCONTROL .CONTROL |= CRACENCORE_RNGCONTROL_CONTROL_INTENFULL_Msk ;
581+ NRF_CRACENCORE -> RNGCONTROL .CONTROL |=
582+ CRACENCORE_RNGCONTROL_CONTROL_INTENFULL_Msk ;
577583 /* Force regeneration of the samples */
578584 NRF_CRACENCORE -> RNGCONTROL .FIFOLEVEL = 0 ;
579585 }
@@ -615,10 +621,9 @@ ble_hw_rng_read(void)
615621
616622 /* Wait for a sample */
617623 while (NRF_CRACENCORE -> RNGCONTROL .FIFOLEVEL == 0 ) {
618- assert ((NRF_CRACENCORE -> RNGCONTROL .STATUS &
619- CRACENCORE_RNGCONTROL_STATUS_STATE_Msk ) !=
620- (CRACENCORE_RNGCONTROL_STATUS_STATE_ERROR <<
621- CRACENCORE_RNGCONTROL_STATUS_STATE_Pos ));
624+ assert ((NRF_CRACENCORE -> RNGCONTROL .STATUS & CRACENCORE_RNGCONTROL_STATUS_STATE_Msk ) !=
625+ (CRACENCORE_RNGCONTROL_STATUS_STATE_ERROR
626+ << CRACENCORE_RNGCONTROL_STATUS_STATE_Pos ));
622627 }
623628
624629 NRF_CRACEN -> EVENTS_RNG = 0 ;
0 commit comments