@@ -141,7 +141,7 @@ void ecb_encrypt(uint8_t const *const key_le, uint8_t const *const clear_text_le
141141 }
142142}
143143
144- uint32_t ecb_encrypt_nonblocking (struct ecb * ecb )
144+ void ecb_encrypt_nonblocking (struct ecb * ecb )
145145{
146146 /* prepare to be used in a BE AES h/w */
147147 if (ecb -> in_key_le ) {
@@ -194,43 +194,40 @@ uint32_t ecb_encrypt_nonblocking(struct ecb *ecb)
194194
195195 /* start the encryption h/w */
196196 nrf_ecb_task_trigger (NRF_ECB , NRF_ECB_TASK_STARTECB );
197-
198- return 0 ;
199197}
200198
201- static void ecb_cleanup ( void )
199+ static void isr_ecb ( const void * arg )
202200{
203- /* stop h/w */
204- NRF_ECB -> TASKS_STOPECB = 1 ;
201+ #if defined(NRF54L_SERIES )
202+ struct ecb * ecb = (void * )((uint8_t * )NRF_ECB -> ECBDATAPTR -
203+ sizeof (struct ecb ));
204+ #else /* !NRF54L_SERIES */
205+ struct ecb * ecb = (void * )NRF_ECB -> ECBDATAPTR ;
206+ #endif /* !NRF54L_SERIES */
207+
208+ ARG_UNUSED (arg );
209+
210+ /* Stop ECB h/w */
205211 nrf_ecb_task_trigger (NRF_ECB , NRF_ECB_TASK_STOPECB );
206212
207- /* cleanup interrupt */
213+ /* We are done or encountered error, disable interrupt */
208214 irq_disable (ECB_IRQn );
209- }
210-
211- void isr_ecb (void * param )
212- {
213- ARG_UNUSED (param );
214215
215216 if (NRF_ECB -> EVENTS_ERRORECB ) {
216- struct ecb * ecb = ( struct ecb * ) NRF_ECB -> ECBDATAPTR ;
217+ NRF_ECB -> EVENTS_ERRORECB = 0U ;
217218
218- ecb_cleanup ();
219-
220- ecb -> fp_ecb (1 , NULL , ecb -> context );
219+ ecb -> fp_ecb (1U , NULL , ecb -> context );
221220 }
222221
223222 else if (NRF_ECB -> EVENTS_ENDECB ) {
224- struct ecb * ecb = (struct ecb * )NRF_ECB -> ECBDATAPTR ;
225-
226- ecb_cleanup ();
223+ NRF_ECB -> EVENTS_ENDECB = 0U ;
227224
228- ecb -> fp_ecb (0 , & ecb -> out_cipher_text_be [0 ],
225+ ecb -> fp_ecb (0U , & ecb -> out_cipher_text_be [0 ],
229226 ecb -> context );
230227 }
231228
232229 else {
233- LL_ASSERT (0 );
230+ LL_ASSERT (false );
234231 }
235232}
236233
@@ -253,35 +250,62 @@ static void ecb_cb(uint32_t status, uint8_t *cipher_be, void *context)
253250 }
254251}
255252
256- uint32_t ecb_ut (void )
253+ int ecb_ut (void )
257254{
258- uint8_t key [16 ] = { 0x00 , 0x11 , 0x22 , 0x33 , 0x44 , 0x55 , 0x66 , 0x77 , 0x88 ,
259- 0x99 , 0x00 , 0x11 , 0x22 , 0x33 , 0x44 , 0x55 };
260- uint8_t clear_text [16 ] = { 0x00 , 0x11 , 0x22 , 0x33 , 0x44 , 0x55 , 0x66 , 0x77 ,
261- 0x88 , 0x99 , 0x00 , 0x11 , 0x22 , 0x33 , 0x44 ,
262- 0x55 };
263- uint8_t cipher_text [16 ];
264- uint32_t status = 0U ;
265- struct ecb ecb ;
266- struct ecb_ut_context context ;
255+ uint8_t key [] = {
256+ 0xbf , 0x01 , 0xfb , 0x9d , 0x4e , 0xf3 , 0xbc , 0x36 ,
257+ 0xd8 , 0x74 , 0xf5 , 0x39 , 0x41 , 0x38 , 0x68 , 0x4c
258+ };
259+ uint8_t clear_text [] = {
260+ 0x13 , 0x02 , 0xf1 , 0xe0 , 0xdf , 0xce , 0xbd , 0xac ,
261+ 0x79 , 0x68 , 0x57 , 0x46 , 0x35 , 0x24 , 0x13 , 0x02
262+ };
263+ uint8_t cipher_text_expected [] = {
264+ 0x66 , 0xc6 , 0xc2 , 0x27 , 0x8e , 0x3b , 0x8e , 0x05 ,
265+ 0x3e , 0x7e , 0xa3 , 0x26 , 0x52 , 0x1b , 0xad , 0x99
266+ };
267+ uint8_t cipher_text_actual [16 ];
268+ int status ;
269+
270+ (void )memset (cipher_text_actual , 0 , sizeof (cipher_text_actual ));
271+ ecb_encrypt (key , clear_text , cipher_text_actual , NULL );
272+
273+ status = memcmp (cipher_text_actual , cipher_text_expected ,
274+ sizeof (cipher_text_actual ));
275+ if (status ) {
276+ return status ;
277+ }
267278
268- ecb_encrypt (key , clear_text , cipher_text , NULL );
279+ #if defined(CONFIG_BT_CTLR_DYNAMIC_INTERRUPTS )
280+ irq_connect_dynamic (ECB_IRQn , CONFIG_BT_CTLR_ULL_LOW_PRIO , isr_ecb , NULL , 0 );
281+ #else /* !CONFIG_BT_CTLR_DYNAMIC_INTERRUPTS */
282+ IRQ_CONNECT (ECB_IRQn , CONFIG_BT_CTLR_ULL_LOW_PRIO , isr_ecb , NULL , 0 );
283+ #endif /* !CONFIG_BT_CTLR_DYNAMIC_INTERRUPTS */
269284
270- context .done = 0U ;
271- ecb .in_key_le = key ;
272- ecb .in_clear_text_le = clear_text ;
273- ecb .fp_ecb = ecb_cb ;
274- ecb .context = & context ;
275- status = ecb_encrypt_nonblocking (& ecb );
285+ uint8_t ecb_mem [sizeof (struct ecb ) + 32U ];
286+ struct ecb * ecb = (void * )ecb_mem ;
287+ struct ecb_ut_context context ;
288+
289+ (void )memset (& context , 0 , sizeof (context ));
290+ ecb -> in_key_le = key ;
291+ ecb -> in_clear_text_le = clear_text ;
292+ ecb -> fp_ecb = ecb_cb ;
293+ ecb -> context = & context ;
294+ ecb_encrypt_nonblocking (ecb );
276295 do {
296+ #if defined(CONFIG_SOC_SERIES_BSIM_NRFXX )
297+ k_busy_wait (10 );
298+ #else
277299 cpu_sleep ();
300+ #endif
278301 } while (!context .done );
279302
280303 if (context .status != 0U ) {
281304 return context .status ;
282305 }
283306
284- status = memcmp (cipher_text , context .cipher_text , sizeof (cipher_text ));
307+ status = memcmp (cipher_text_expected , context .cipher_text ,
308+ sizeof (cipher_text_expected ));
285309 if (status ) {
286310 return status ;
287311 }
0 commit comments