@@ -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 );
@@ -361,6 +365,12 @@ ble_hw_encrypt_block(struct ble_encryption_block *ecb)
361365 }
362366 }
363367
368+ /* Clear events after polling to prevent a latched ECB event from
369+ * asserting ECB00_IRQn later if another user enables the interrupt. */
370+ NRF_ECB -> EVENTS_END = 0 ;
371+ NRF_ECB -> EVENTS_ERROR = 0 ;
372+ __DSB ();
373+
364374 return rc ;
365375}
366376#endif
@@ -508,7 +518,8 @@ ble_rng_isr(void)
508518 /* No callback? Clear and disable interrupts */
509519 if (g_ble_rng_isr_cb == NULL ) {
510520 nrf_cracen_int_disable (NRF_CRACEN , NRF_CRACEN_INT_RNG_MASK );
511- NRF_CRACENCORE -> RNGCONTROL .CONTROL &= ~CRACENCORE_RNGCONTROL_CONTROL_INTENFULL_Msk ;
521+ NRF_CRACENCORE -> RNGCONTROL .CONTROL &=
522+ ~CRACENCORE_RNGCONTROL_CONTROL_INTENFULL_Msk ;
512523 NRF_CRACEN -> EVENTS_RNG = 0 ;
513524 os_trace_isr_exit ();
514525 return ;
@@ -538,10 +549,10 @@ int
538549ble_hw_rng_init (ble_rng_isr_cb_t cb , int bias )
539550{
540551 NRF_CRACEN -> ENABLE = CRACEN_ENABLE_CRYPTOMASTER_Msk |
541- CRACEN_ENABLE_RNG_Msk |
542- CRACEN_ENABLE_PKEIKG_Msk ;
552+ CRACEN_ENABLE_RNG_Msk | CRACEN_ENABLE_PKEIKG_Msk ;
543553
544- while (NRF_CRACENCORE -> PK .STATUS & CRACENCORE_PK_STATUS_PKBUSY_Msk );
554+ while (NRF_CRACENCORE -> PK .STATUS & CRACENCORE_PK_STATUS_PKBUSY_Msk )
555+ ;
545556 NRF_CRACENCORE -> PK .CONTROL &= ~CRACENCORE_IKG_PKECONTROL_CLEARIRQ_Msk ;
546557
547558 NRF_CRACENCORE -> RNGCONTROL .CONTROL = CRACENCORE_RNGCONTROL_CONTROL_ResetValue |
@@ -573,7 +584,8 @@ ble_hw_rng_start(void)
573584
574585 if (g_ble_rng_isr_cb ) {
575586 nrf_cracen_int_enable (NRF_CRACEN , NRF_CRACEN_INT_RNG_MASK );
576- NRF_CRACENCORE -> RNGCONTROL .CONTROL |= CRACENCORE_RNGCONTROL_CONTROL_INTENFULL_Msk ;
587+ NRF_CRACENCORE -> RNGCONTROL .CONTROL |=
588+ CRACENCORE_RNGCONTROL_CONTROL_INTENFULL_Msk ;
577589 /* Force regeneration of the samples */
578590 NRF_CRACENCORE -> RNGCONTROL .FIFOLEVEL = 0 ;
579591 }
@@ -615,10 +627,9 @@ ble_hw_rng_read(void)
615627
616628 /* Wait for a sample */
617629 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 ));
630+ assert ((NRF_CRACENCORE -> RNGCONTROL .STATUS & CRACENCORE_RNGCONTROL_STATUS_STATE_Msk ) !=
631+ (CRACENCORE_RNGCONTROL_STATUS_STATE_ERROR
632+ << CRACENCORE_RNGCONTROL_STATUS_STATE_Pos ));
622633 }
623634
624635 NRF_CRACEN -> EVENTS_RNG = 0 ;
0 commit comments