STM32L4xx_HAL_Driver  1.14.0
CRYPEx Private Functions

Functions

HAL_StatusTypeDef CRYP_AES_Auth_IT (CRYP_HandleTypeDef *hcryp)
 Handle CRYP block input/output data handling under interruption for GCM, GMAC, CCM or CMAC chaining modes. More...
 
static HAL_StatusTypeDef CRYP_ProcessData (CRYP_HandleTypeDef *hcryp, uint8_t *Input, uint16_t Ilength, uint8_t *Output, uint32_t Timeout)
 Write/read input/output data in polling mode. More...
 
static HAL_StatusTypeDef CRYP_ReadKey (CRYP_HandleTypeDef *hcryp, uint8_t *Output, uint32_t Timeout)
 Read derivative key in polling mode when CRYP hardware block is set in key derivation operating mode (mode 2). More...
 
static void CRYP_SetDMAConfig (CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr)
 Set the DMA configuration and start the DMA transfer. More...
 
static void CRYP_Authentication_SetDMAConfig (CRYP_HandleTypeDef *hcryp, uint32_t inputaddr, uint16_t Size, uint32_t outputaddr)
 Set the DMA configuration and start the DMA transfer for GCM, GMAC, CCM or CMAC chaining modes. More...
 
static void CRYP_Authentication_DMAInCplt (DMA_HandleTypeDef *hdma)
 DMA CRYP Input Data process complete callback for GCM, GMAC, CCM or CMAC chaining modes. More...
 
static void CRYP_Authentication_DMAError (DMA_HandleTypeDef *hdma)
 DMA CRYP communication error callback for GCM, GMAC, CCM or CMAC chaining modes. More...
 
static void CRYP_Authentication_DMAOutCplt (DMA_HandleTypeDef *hdma)
 DMA CRYP Output Data process complete callback for GCM, GMAC, CCM or CMAC chaining modes. More...
 
static HAL_StatusTypeDef CRYP_WaitOnCCFlag (CRYP_HandleTypeDef const *const hcryp, uint32_t Timeout)
 Handle CRYP hardware block Timeout when waiting for CCF flag to be raised. More...
 
static HAL_StatusTypeDef CRYP_WaitOnBusyFlagReset (CRYP_HandleTypeDef const *const hcryp, uint32_t Timeout)
 Wait for Busy Flag to be reset during a GCM payload encryption process suspension. More...
 
static void CRYP_DMAInCplt (DMA_HandleTypeDef *hdma)
 DMA CRYP Input Data process complete callback. More...
 
static void CRYP_DMAOutCplt (DMA_HandleTypeDef *hdma)
 DMA CRYP Output Data process complete callback. More...
 
static void CRYP_DMAError (DMA_HandleTypeDef *hdma)
 DMA CRYP communication error callback. More...
 
static void CRYP_Padding (CRYP_HandleTypeDef *hcryp, uint32_t difflength, uint32_t polling)
 Last header or payload block padding when size is not a multiple of 128 bits. More...
 

Detailed Description

Function Documentation

◆ CRYP_AES_Auth_IT()

HAL_StatusTypeDef CRYP_AES_Auth_IT ( CRYP_HandleTypeDef hcryp)

Handle CRYP block input/output data handling under interruption for GCM, GMAC, CCM or CMAC chaining modes.

Note
The function is called under interruption only, once interruptions have been enabled by HAL_CRYPEx_AES_Auth_IT().
Parameters
hcryppointer to a CRYP_HandleTypeDef structure that contains the configuration information for CRYP module
Return values
HALstatus

Definition at line 2236 of file stm32l4xx_hal_cryp_ex.c.

2237 {
2238  uint32_t inputaddr ;
2239  uint32_t outputaddr ;
2240  uint32_t index ;
2241  uint32_t addhoc_process = 0;
2242  uint32_t difflength = 0;
2243  uint32_t difflengthmod4 = 0;
2244  uint32_t mask[4][3] ;
2245  uint32_t mask_index = hcryp->Init.DataType >> AES_CR_DATATYPE_Pos;
2246  uint32_t intermediate_data[4] = {0};
2247 
2248  mask[0][0] = 0xFF000000U; mask[0][1] = 0xFFFF0000U; mask[0][2] = 0xFFFFFF00U; /* 32-bit data */
2249  mask[1][0] = 0x0000FF00U; mask[1][1] = 0x0000FFFFU; mask[1][2] = 0xFF00FFFFU; /* 16-bit data */
2250  mask[2][0] = 0x000000FFU; mask[2][1] = 0x0000FFFFU; mask[2][2] = 0x00FFFFFFU; /* 8-bit data */
2251  mask[3][0] = 0x000000FFU; mask[3][1] = 0x0000FFFFU; mask[3][2] = 0x00FFFFFFU; /* Bit data */
2252 
2253  if(hcryp->State == HAL_CRYP_STATE_BUSY)
2254  {
2255  /*===========================*/
2256  /* GCM/GMAC(/CCM) init phase */
2257  /*===========================*/
2258  if (hcryp->Init.GCMCMACPhase == CRYP_INIT_PHASE)
2259  {
2260  /* Clear Computation Complete Flag */
2261  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2262  /* Disable Computation Complete Flag and Errors Interrupts */
2263  __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_CCFIE|CRYP_IT_ERRIE);
2264  /* Change the CRYP state */
2265  hcryp->State = HAL_CRYP_STATE_READY;
2266 
2267  /* Mark that the initialization phase is over */
2269 
2270  /* Process Unlocked */
2271  __HAL_UNLOCK(hcryp);
2272  /* Call computation complete callback */
2273 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2274  hcryp->CompCpltCallback(hcryp);
2275 #else
2277 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2278  return HAL_OK;
2279  }
2280  /*========================================*/
2281  /* GCM/GMAC (or CCM or CMAC) header phase */
2282  /*========================================*/
2283  else if (hcryp->Init.GCMCMACPhase == CRYP_HEADER_PHASE)
2284  {
2285  /* Check if all input header data have been entered */
2286  if (hcryp->CrypInCount == 0U)
2287  {
2288  /* Clear Computation Complete Flag */
2289  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2290  /* Disable Computation Complete Flag and Errors Interrupts */
2291  __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_CCFIE|CRYP_IT_ERRIE);
2292  /* Change the CRYP state */
2293  hcryp->State = HAL_CRYP_STATE_READY;
2294  /* Mark that the header phase is over */
2296 
2297  /* Process Unlocked */
2298  __HAL_UNLOCK(hcryp);
2299 
2300  /* Call computation complete callback */
2301 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2302  hcryp->CompCpltCallback(hcryp);
2303 #else
2305 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2306 
2307  return HAL_OK;
2308  }
2309  /* If suspension flag has been raised, suspend processing */
2310  else if (hcryp->SuspendRequest == HAL_CRYP_SUSPEND)
2311  {
2312  /* Clear CCF Flag */
2313  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2314 
2315  /* reset SuspendRequest */
2317  /* Disable Computation Complete Flag and Errors Interrupts */
2318  __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_CCFIE|CRYP_IT_ERRIE);
2319  /* Change the CRYP state */
2321  /* Mark that the header phase is suspended */
2323 
2324  /* Process Unlocked */
2325  __HAL_UNLOCK(hcryp);
2326 
2327  return HAL_OK;
2328  }
2329  else /* Carry on feeding input data to the CRYP hardware block */
2330  {
2331  /* Clear Computation Complete Flag */
2332  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2333  /* Get the last Input data address */
2334  inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
2335 
2336  /* Increment/decrement instance pointer/counter */
2337  if (hcryp->CrypInCount < 16U)
2338  {
2339  difflength = hcryp->CrypInCount;
2340  hcryp->CrypInCount = 0;
2341  addhoc_process = 1;
2342  difflengthmod4 = difflength%4U;
2343  }
2344  else
2345  {
2346  hcryp->pCrypInBuffPtr += 16;
2347  hcryp->CrypInCount -= 16U;
2348  }
2349 
2350 #if defined(AES_CR_NPBLB)
2351  if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CCM)
2352 #else
2353  if (hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_CMAC)
2354 #endif
2355  {
2356  if (hcryp->CrypInCount == hcryp->Init.HeaderSize)
2357  {
2358  /* All B blocks will have been entered after the next
2359  four DINR writing, so point at header buffer for
2360  the next iteration */
2361  hcryp->pCrypInBuffPtr = hcryp->Init.Header;
2362  }
2363  }
2364 
2365  /* Write the Input block in the Data Input register */
2366  if (addhoc_process == 0U)
2367  {
2368  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2369  inputaddr+=4U;
2370  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2371  inputaddr+=4U;
2372  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2373  inputaddr+=4U;
2374  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2375  }
2376  else
2377  {
2378  /* Header remainder has size less than 128 bits */
2379  /* Enter complete words when possible */
2380  for(index=0U ; index < (difflength/4U); index ++)
2381  {
2382  /* Write the Input block in the Data Input register */
2383  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2384  inputaddr+=4U;
2385  }
2386  /* Enter incomplete word padded with zeroes if applicable
2387  (case of header length not a multiple of 32-bits) */
2388  if (difflengthmod4 != 0U)
2389  {
2390  hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1U]);
2391  }
2392  /* Pad with zero-words to reach 128-bit long block and wrap-up header feeding to the IP */
2393  for(index=0U; index < (4U - ((difflength+3U)/4U)); index ++)
2394  {
2395  hcryp->Instance->DINR = 0;
2396  }
2397  }
2398 
2399  return HAL_OK;
2400  }
2401  }
2402  /*=======================*/
2403  /* GCM/CCM payload phase */
2404  /*=======================*/
2405  else if (hcryp->Init.GCMCMACPhase == CRYP_PAYLOAD_PHASE)
2406  {
2407  /* Get the last output data address */
2408  outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
2409 
2410  /* Specific handling to manage payload size less than 128 bits
2411  when GCM (or CCM when applicable) encryption or decryption is selected.
2412  Check here if the last block output data are read */
2413 #if defined(AES_CR_NPBLB)
2414  if ((hcryp->CrypOutCount < 16U) && \
2415  (hcryp->CrypOutCount > 0U))
2416 #else
2417  if ((hcryp->Init.ChainingMode == CRYP_CHAINMODE_AES_GCM_GMAC) && \
2418  (hcryp->CrypOutCount < 16U) && \
2419  (hcryp->CrypOutCount > 0U))
2420 #endif
2421  {
2422  difflength = hcryp->CrypOutCount;
2423  difflengthmod4 = difflength%4U;
2424  hcryp->CrypOutCount = 0; /* mark that no more output data will be needed */
2425  /* Retrieve intermediate data */
2426  for(index=0U ; index < 4U; index ++)
2427  {
2428  intermediate_data[index] = hcryp->Instance->DOUTR;
2429  }
2430  /* Retrieve last words of cyphered data */
2431  /* First, retrieve complete output words */
2432  for(index=0U ; index < (difflength/4U); index ++)
2433  {
2434  *(uint32_t*)(outputaddr) = intermediate_data[index];
2435  outputaddr+=4U;
2436  }
2437  /* Next, retrieve partial output word if applicable;
2438  at the same time, start masking intermediate data
2439  with a mask of zeros of same size than the padding
2440  applied to the last block of payload */
2441  if (difflengthmod4 != 0U)
2442  {
2443  intermediate_data[difflength/4U] &= mask[mask_index][difflengthmod4-1U];
2444  *(uint32_t*)(outputaddr) = intermediate_data[difflength/4U];
2445  }
2446 
2447 #if !defined(AES_CR_NPBLB)
2448  if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_ENCRYPT)
2449  {
2450  /* Change again CHMOD configuration to GCM mode */
2451  __HAL_CRYP_SET_CHAININGMODE(hcryp, CRYP_CHAINMODE_AES_GCM_GMAC);
2452 
2453  /* Select FINAL phase */
2454  MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_FINAL_PHASE);
2455 
2456  /* Before inserting the intermediate data, carry on masking operation
2457  with a mask of zeros of same size than the padding applied to the last block of payload */
2458  for(index=0U ; index < (4U - ((difflength+3U)/4U)); index ++)
2459  {
2460  intermediate_data[((difflength+3U)/4U)+index] = 0;
2461  }
2462 
2463  /* Insert intermediate data to trigger an additional DOUTR reading round */
2464  /* Clear Computation Complete Flag before entering new block */
2465  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2466  for(index=0U ; index < 4U; index ++)
2467  {
2468  hcryp->Instance->DINR = intermediate_data[index];
2469  }
2470  }
2471  else
2472 #endif
2473  {
2474  /* Payload phase is now over */
2475  /* Clear Computation Complete Flag */
2476  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2477  /* Disable Computation Complete Flag and Errors Interrupts */
2478  __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_CCFIE|CRYP_IT_ERRIE);
2479  /* Change the CRYP state */
2480  hcryp->State = HAL_CRYP_STATE_READY;
2481  /* Mark that the payload phase is over */
2483 
2484  /* Process Unlocked */
2485  __HAL_UNLOCK(hcryp);
2486 
2487  /* Call computation complete callback */
2488 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2489  hcryp->CompCpltCallback(hcryp);
2490 #else
2492 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2493  }
2494  return HAL_OK;
2495  }
2496  else
2497  {
2498  if (hcryp->CrypOutCount != 0U)
2499  {
2500  /* Usual case (different than GCM/CCM last block < 128 bits ciphering) */
2501  /* Retrieve the last block available from the CRYP hardware block:
2502  read the output block from the Data Output Register */
2503  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2504  outputaddr+=4U;
2505  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2506  outputaddr+=4U;
2507  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2508  outputaddr+=4U;
2509  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2510 
2511  /* Increment/decrement instance pointer/counter */
2512  hcryp->pCrypOutBuffPtr += 16;
2513  hcryp->CrypOutCount -= 16U;
2514  }
2515 #if !defined(AES_CR_NPBLB)
2516  else
2517  {
2518  /* Software work-around: additional DOUTR reading round to discard the data */
2519  for(index=0U ; index < 4U; index ++)
2520  {
2521  intermediate_data[index] = hcryp->Instance->DOUTR;
2522  }
2523  }
2524 #endif
2525  }
2526 
2527  /* Check if all output text has been retrieved */
2528  if (hcryp->CrypOutCount == 0U)
2529  {
2530  /* Clear Computation Complete Flag */
2531  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2532  /* Disable Computation Complete Flag and Errors Interrupts */
2533  __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_CCFIE|CRYP_IT_ERRIE);
2534  /* Change the CRYP state */
2535  hcryp->State = HAL_CRYP_STATE_READY;
2536  /* Mark that the payload phase is over */
2538 
2539  /* Process Unlocked */
2540  __HAL_UNLOCK(hcryp);
2541 
2542  /* Call computation complete callback */
2543 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2544  hcryp->CompCpltCallback(hcryp);
2545 #else
2547 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2548 
2549  return HAL_OK;
2550  }
2551  /* If suspension flag has been raised, suspend processing */
2552  else if (hcryp->SuspendRequest == HAL_CRYP_SUSPEND)
2553  {
2554  /* Clear CCF Flag */
2555  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2556 
2557  /* reset SuspendRequest */
2559  /* Disable Computation Complete Flag and Errors Interrupts */
2560  __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_CCFIE|CRYP_IT_ERRIE);
2561  /* Change the CRYP state */
2563  /* Mark that the payload phase is suspended */
2565 
2566  /* Process Unlocked */
2567  __HAL_UNLOCK(hcryp);
2568 
2569  return HAL_OK;
2570  }
2571  else /* Output data are still expected, carry on feeding the CRYP
2572  hardware block with input data */
2573  {
2574  /* Clear Computation Complete Flag */
2575  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2576  /* Get the last Input data address */
2577  inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
2578 
2579  /* Usual input data feeding case */
2580  if (hcryp->CrypInCount < 16U)
2581  {
2582  difflength = (uint32_t) (hcryp->CrypInCount);
2583  difflengthmod4 = difflength%4U;
2584  hcryp->CrypInCount = 0;
2585 
2586 #if defined(AES_CR_NPBLB)
2587  /* In case of GCM encryption or CCM decryption, specify the number of padding
2588  bytes in last block of payload */
2589  {
2590  uint32_t cr_temp = hcryp->Instance->CR;
2591 
2592  if (((cr_temp & (AES_CR_CHMOD|AES_CR_MODE)) == (CRYP_CHAINMODE_AES_GCM_GMAC|CRYP_ALGOMODE_ENCRYPT))
2593  || ((cr_temp & (AES_CR_CHMOD|AES_CR_MODE)) == (CRYP_CHAINMODE_AES_CCM|CRYP_ALGOMODE_DECRYPT)))
2594  {
2595  /* Set NPBLB field in writing the number of padding bytes
2596  for the last block of payload */
2597  MODIFY_REG(hcryp->Instance->CR, AES_CR_NPBLB, (16U - difflength) << AES_POSITION_CR_NPBLB);
2598  }
2599  }
2600 #else
2601  /* Software workaround applied to GCM encryption only */
2602  if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_ENCRYPT)
2603  {
2604  /* Change the mode configured in CHMOD bits of CR register to select CTR mode */
2605  __HAL_CRYP_SET_CHAININGMODE(hcryp, CRYP_CHAINMODE_AES_CTR);
2606  }
2607 #endif
2608 
2609  /* Insert the last block (which size is inferior to 128 bits) padded with zeroes
2610  to have a complete block of 128 bits */
2611  for(index=0U ; index < (difflength/4U); index ++)
2612  {
2613  /* Write the Input block in the Data Input register */
2614  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2615  inputaddr+=4U;
2616  }
2617  /* If required, manage input data size not multiple of 32 bits */
2618  if (difflengthmod4 != 0U)
2619  {
2620  hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1U]);
2621  }
2622  /* Wrap-up in padding with zero-words if applicable */
2623  for(index=0U ; index < (4U - ((difflength+3U)/4U)); index ++)
2624  {
2625  hcryp->Instance->DINR = 0;
2626  }
2627 
2628  }
2629  else
2630  {
2631  hcryp->pCrypInBuffPtr += 16;
2632  hcryp->CrypInCount -= 16U;
2633 
2634  /* Write the Input block in the Data Input register */
2635  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2636  inputaddr+=4U;
2637  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2638  inputaddr+=4U;
2639  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2640  inputaddr+=4U;
2641  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2642  }
2643 
2644 
2645  return HAL_OK;
2646  }
2647  }
2648  /*=======================================*/
2649  /* GCM/GMAC (or CCM or CMAC) final phase */
2650  /*=======================================*/
2651  else if (hcryp->Init.GCMCMACPhase == CRYP_FINAL_PHASE)
2652  {
2653  /* Clear Computation Complete Flag */
2654  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2655 
2656  /* Get the last output data address */
2657  outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
2658 
2659  /* Retrieve the last expected data from the CRYP hardware block:
2660  read the output block from the Data Output Register */
2661  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2662  outputaddr+=4U;
2663  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2664  outputaddr+=4U;
2665  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2666  outputaddr+=4U;
2667  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2668 
2669  /* Disable Computation Complete Flag and Errors Interrupts */
2670  __HAL_CRYP_DISABLE_IT(hcryp, CRYP_IT_CCFIE|CRYP_IT_ERRIE);
2671  /* Change the CRYP state */
2672  hcryp->State = HAL_CRYP_STATE_READY;
2673  /* Mark that the header phase is over */
2675 
2676  /* Disable the Peripheral */
2677  __HAL_CRYP_DISABLE(hcryp);
2678  /* Process Unlocked */
2679  __HAL_UNLOCK(hcryp);
2680 
2681  /* Call computation complete callback */
2682 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2683  hcryp->CompCpltCallback(hcryp);
2684 #else
2686 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2687 
2688  return HAL_OK;
2689  }
2690  else
2691  {
2692  /* Clear Computation Complete Flag */
2693  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2694  hcryp->State = HAL_CRYP_STATE_ERROR;
2695  __HAL_UNLOCK(hcryp);
2696  return HAL_ERROR;
2697  }
2698  }
2699  else
2700  {
2701  return HAL_BUSY;
2702  }
2703 }
__IO HAL_CRYP_STATETypeDef State
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
__HAL_UNLOCK(hrtc)
HAL_SuspendTypeDef SuspendRequest
return HAL_OK
void(* CompCpltCallback)(struct __CRYP_HandleTypeDef *hcryp)
HAL_PhaseTypeDef Phase
__weak void HAL_CRYPEx_ComputationCpltCallback(CRYP_HandleTypeDef *hcryp)
Computation completed callbacks.
ADC handle Structure definition.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)

◆ CRYP_Authentication_DMAError()

static void CRYP_Authentication_DMAError ( DMA_HandleTypeDef hdma)
static

DMA CRYP communication error callback for GCM, GMAC, CCM or CMAC chaining modes.

Parameters
hdmaDMA handle
Return values
None

Definition at line 2210 of file stm32l4xx_hal_cryp_ex.c.

2211 {
2212  CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
2213 
2214  hcryp->State= HAL_CRYP_STATE_ERROR;
2215  hcryp->ErrorCode |= HAL_CRYP_DMA_ERROR;
2216 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2217  hcryp->ErrorCallback(hcryp);
2218 #else
2219  HAL_CRYP_ErrorCallback(hcryp);
2220 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2221  /* Clear Error Flag */
2222  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_ERR_CLEAR);
2223 }
void(* ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp)
__IO HAL_CRYP_STATETypeDef State
DMA handle Structure definition.
CRYP handle Structure definition.
void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp)
CRYP error callback.

◆ CRYP_Authentication_DMAInCplt()

static void CRYP_Authentication_DMAInCplt ( DMA_HandleTypeDef hdma)
static

DMA CRYP Input Data process complete callback for GCM, GMAC, CCM or CMAC chaining modes.

Note
Specific setting of hcryp fields are required only in the case of header phase where no output data DMA transfer is on-going (only input data transfer is enabled in such a case).
Parameters
hdmaDMA handle.
Return values
None

Definition at line 2126 of file stm32l4xx_hal_cryp_ex.c.

2127 {
2128  uint32_t difflength;
2129  CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
2130 
2131  /* Disable the DMA transfer for input request */
2132  CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAINEN);
2133 
2134  if (hcryp->Init.GCMCMACPhase == CRYP_HEADER_PHASE)
2135  {
2136 
2137  if (hcryp->CrypInCount != 0U)
2138  {
2139  /* Last block is now entered in polling mode, no actual gain in resorting to DMA */
2140  difflength = hcryp->CrypInCount;
2141  hcryp->CrypInCount = 0;
2142 
2143  CRYP_Padding(hcryp, difflength, CRYP_POLLING_OFF);
2144  }
2145  hcryp->State = HAL_CRYP_STATE_READY;
2146  /* Mark that the header phase is over */
2148  }
2149  /* CCF flag indicating header phase AES processing completion
2150  will be checked at the start of the next phase:
2151  - payload phase (GCM or CCM when applicable)
2152  - final phase (GMAC or CMAC).
2153  This allows to avoid the Wait on Flag within the IRQ handling. */
2154 
2155  /* Call input data transfer complete callback */
2156 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2157  hcryp->InCpltCallback(hcryp);
2158 #else
2159  HAL_CRYP_InCpltCallback(hcryp);
2160 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2161 }
__IO HAL_CRYP_STATETypeDef State
DMA handle Structure definition.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
CRYP handle Structure definition.
static void CRYP_Padding(CRYP_HandleTypeDef *hcryp, uint32_t difflength, uint32_t polling)
Last header or payload block padding when size is not a multiple of 128 bits.
void(* InCpltCallback)(struct __CRYP_HandleTypeDef *hcryp)
void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp)
Input DMA transfer complete callback.
HAL_PhaseTypeDef Phase

◆ CRYP_Authentication_DMAOutCplt()

static void CRYP_Authentication_DMAOutCplt ( DMA_HandleTypeDef hdma)
static

DMA CRYP Output Data process complete callback for GCM, GMAC, CCM or CMAC chaining modes.

Note
This callback is called only in the payload phase.
Parameters
hdmaDMA handle.
Return values
None

Definition at line 2170 of file stm32l4xx_hal_cryp_ex.c.

2171 {
2172  uint32_t difflength;
2173  CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
2174 
2175  /* Disable the DMA transfer for output request */
2176  CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAOUTEN);
2177 
2178  /* Clear CCF Flag */
2179  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2180 
2181  /* Initiate additional transfer to wrap-up data feeding to the IP */
2182  if (hcryp->CrypInCount != 0U)
2183  {
2184  /* Last block is now entered in polling mode, no actual gain in resorting to DMA */
2185  difflength = hcryp->CrypInCount;
2186  hcryp->CrypInCount = 0;
2187 
2188  CRYP_Padding(hcryp, difflength, CRYP_POLLING_ON);
2189  }
2190 
2191  /* Change the CRYP state to ready */
2192  hcryp->State = HAL_CRYP_STATE_READY;
2193  /* Mark that the payload phase is over */
2195 
2196  /* Call output data transfer complete callback */
2197 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2198  hcryp->OutCpltCallback(hcryp);
2199 #else
2200  HAL_CRYP_OutCpltCallback(hcryp);
2201 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2202 }
__IO HAL_CRYP_STATETypeDef State
DMA handle Structure definition.
void(* OutCpltCallback)(struct __CRYP_HandleTypeDef *hcryp)
void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp)
Output DMA transfer complete callback.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
CRYP handle Structure definition.
static void CRYP_Padding(CRYP_HandleTypeDef *hcryp, uint32_t difflength, uint32_t polling)
Last header or payload block padding when size is not a multiple of 128 bits.
HAL_PhaseTypeDef Phase

◆ CRYP_Authentication_SetDMAConfig()

static void CRYP_Authentication_SetDMAConfig ( CRYP_HandleTypeDef hcryp,
uint32_t  inputaddr,
uint16_t  Size,
uint32_t  outputaddr 
)
static

Set the DMA configuration and start the DMA transfer for GCM, GMAC, CCM or CMAC chaining modes.

Parameters
hcryppointer to a CRYP_HandleTypeDef structure that contains the configuration information for CRYP module.
inputaddrAddress of the Input buffer.
SizeSize of the Input buffer un bytes, must be a multiple of 16.
outputaddrAddress of the Output buffer, null pointer when no output DMA stream has to be configured.
Return values
None

Definition at line 2718 of file stm32l4xx_hal_cryp_ex.c.

2719 {
2720 
2721  /* Set the input CRYP DMA transfer complete callback */
2723  /* Set the DMA error callback */
2725 
2726  if (outputaddr != 0U)
2727  {
2728  /* Set the output CRYP DMA transfer complete callback */
2730  /* Set the DMA error callback */
2732  }
2733 
2734  /* Enable the CRYP peripheral */
2735  __HAL_CRYP_ENABLE(hcryp);
2736 
2737  /* Enable the DMA input stream */
2738  if (HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&hcryp->Instance->DINR, ((uint32_t)Size)/4U) != HAL_OK)
2739  {
2740 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2741  hcryp->ErrorCallback(hcryp);
2742 #else
2743  HAL_CRYP_ErrorCallback(hcryp);
2744 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2745  }
2746 
2747  /* Enable the DMA input request */
2748  SET_BIT(hcryp->Instance->CR, AES_CR_DMAINEN);
2749 
2750 
2751  if (outputaddr != 0U)
2752  {
2753  /* Enable the DMA output stream */
2754  if (HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&hcryp->Instance->DOUTR, outputaddr, ((uint32_t)Size)/4U) != HAL_OK)
2755  {
2756 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2757  hcryp->ErrorCallback(hcryp);
2758 #else
2759  HAL_CRYP_ErrorCallback(hcryp);
2760 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2761  }
2762 
2763  /* Enable the DMA output request */
2764  SET_BIT(hcryp->Instance->CR, AES_CR_DMAOUTEN);
2765  }
2766 }
static void CRYP_Authentication_DMAError(DMA_HandleTypeDef *hdma)
DMA CRYP communication error callback for GCM, GMAC, CCM or CMAC chaining modes.
void(* ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp)
DMA_HandleTypeDef * hdmaout
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA_HandleTypeDef * hdmain
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
return HAL_OK
static void CRYP_Authentication_DMAOutCplt(DMA_HandleTypeDef *hdma)
DMA CRYP Output Data process complete callback for GCM, GMAC, CCM or CMAC chaining modes...
void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp)
CRYP error callback.
static void CRYP_Authentication_DMAInCplt(DMA_HandleTypeDef *hdma)
DMA CRYP Input Data process complete callback for GCM, GMAC, CCM or CMAC chaining modes...

◆ CRYP_DMAError()

static void CRYP_DMAError ( DMA_HandleTypeDef hdma)
static

DMA CRYP communication error callback.

Parameters
hdmaDMA handle.
Return values
None

Definition at line 3059 of file stm32l4xx_hal_cryp_ex.c.

3060 {
3061  CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
3062 
3063  hcryp->State= HAL_CRYP_STATE_ERROR;
3064  hcryp->ErrorCode |= HAL_CRYP_DMA_ERROR;
3065 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
3066  hcryp->ErrorCallback(hcryp);
3067 #else
3068  HAL_CRYP_ErrorCallback(hcryp);
3069 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
3070  /* Clear Error Flag */
3071  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_ERR_CLEAR);
3072 }
void(* ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp)
__IO HAL_CRYP_STATETypeDef State
DMA handle Structure definition.
CRYP handle Structure definition.
void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp)
CRYP error callback.

◆ CRYP_DMAInCplt()

static void CRYP_DMAInCplt ( DMA_HandleTypeDef hdma)
static

DMA CRYP Input Data process complete callback.

Parameters
hdmaDMA handle.
Return values
None

Definition at line 3010 of file stm32l4xx_hal_cryp_ex.c.

3011 {
3012  CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
3013 
3014  /* Disable the DMA transfer for input request */
3015  CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAINEN);
3016 
3017  /* Call input data transfer complete callback */
3018 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
3019  hcryp->InCpltCallback(hcryp);
3020 #else
3021  HAL_CRYP_InCpltCallback(hcryp);
3022 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
3023 }
DMA handle Structure definition.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
CRYP handle Structure definition.
void(* InCpltCallback)(struct __CRYP_HandleTypeDef *hcryp)
void HAL_CRYP_InCpltCallback(CRYP_HandleTypeDef *hcryp)
Input DMA transfer complete callback.

◆ CRYP_DMAOutCplt()

static void CRYP_DMAOutCplt ( DMA_HandleTypeDef hdma)
static

DMA CRYP Output Data process complete callback.

Parameters
hdmaDMA handle.
Return values
None

Definition at line 3030 of file stm32l4xx_hal_cryp_ex.c.

3031 {
3032  CRYP_HandleTypeDef* hcryp = (CRYP_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent; /* Derogation MisraC2012 R.11.5 */
3033 
3034  /* Disable the DMA transfer for output request */
3035  CLEAR_BIT(hcryp->Instance->CR, AES_CR_DMAOUTEN);
3036 
3037  /* Clear CCF Flag */
3038  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
3039 
3040  /* Disable CRYP */
3041  __HAL_CRYP_DISABLE(hcryp);
3042 
3043  /* Change the CRYP state to ready */
3044  hcryp->State = HAL_CRYP_STATE_READY;
3045 
3046  /* Call output data transfer complete callback */
3047 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
3048  hcryp->OutCpltCallback(hcryp);
3049 #else
3050  HAL_CRYP_OutCpltCallback(hcryp);
3051 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
3052 }
__IO HAL_CRYP_STATETypeDef State
DMA handle Structure definition.
void(* OutCpltCallback)(struct __CRYP_HandleTypeDef *hcryp)
void HAL_CRYP_OutCpltCallback(CRYP_HandleTypeDef *hcryp)
Output DMA transfer complete callback.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
CRYP handle Structure definition.

◆ CRYP_Padding()

static void CRYP_Padding ( CRYP_HandleTypeDef hcryp,
uint32_t  difflength,
uint32_t  polling 
)
static

Last header or payload block padding when size is not a multiple of 128 bits.

Parameters
hcryppointer to a CRYP_HandleTypeDef structure that contains the configuration information for CRYP module.
difflengthsize remainder after having fed all complete 128-bit blocks.
pollingspecifies whether or not polling on CCF must be done after having entered a complete block.
Return values
None

Definition at line 3083 of file stm32l4xx_hal_cryp_ex.c.

3084 {
3085  uint32_t index;
3086  uint32_t difflengthmod4 = difflength%4U;
3087  uint32_t inputaddr = (uint32_t)hcryp->pCrypInBuffPtr;
3088  uint32_t outputaddr = (uint32_t)hcryp->pCrypOutBuffPtr;
3089  uint32_t mask[4][3];
3090  uint32_t mask_index = hcryp->Init.DataType >> AES_CR_DATATYPE_Pos;
3091 
3092  uint32_t intermediate_data[4] = {0};
3093 
3094  mask[0][0] = 0xFF000000U; mask[0][1] = 0xFFFF0000U; mask[0][2] = 0xFFFFFF00U; /* 32-bit data */
3095  mask[1][0] = 0x0000FF00U; mask[1][1] = 0x0000FFFFU; mask[1][2] = 0xFF00FFFFU; /* 16-bit data */
3096  mask[2][0] = 0x000000FFU; mask[2][1] = 0x0000FFFFU; mask[2][2] = 0x00FFFFFFU; /* 8-bit data */
3097  mask[3][0] = 0x000000FFU; mask[3][1] = 0x0000FFFFU; mask[3][2] = 0x00FFFFFFU; /* Bit data */
3098 
3099 #if defined(AES_CR_NPBLB)
3100  /* In case of GCM encryption or CCM decryption, specify the number of padding
3101  bytes in last block of payload */
3102  if (READ_BIT(hcryp->Instance->CR,AES_CR_GCMPH) == CRYP_PAYLOAD_PHASE)
3103  {
3104  uint32_t cr_temp = hcryp->Instance->CR;
3105 
3106  if (((cr_temp & (AES_CR_CHMOD|AES_CR_MODE)) == (CRYP_CHAINMODE_AES_GCM_GMAC|CRYP_ALGOMODE_ENCRYPT))
3107  || ((cr_temp & (AES_CR_CHMOD|AES_CR_MODE)) == (CRYP_CHAINMODE_AES_CCM|CRYP_ALGOMODE_DECRYPT)))
3108  {
3109  /* Set NPBLB field in writing the number of padding bytes
3110  for the last block of payload */
3111  MODIFY_REG(hcryp->Instance->CR, AES_CR_NPBLB, (16U - difflength) << AES_POSITION_CR_NPBLB);
3112  }
3113  }
3114 #else
3115  /* Software workaround applied to GCM encryption only */
3116  if ((hcryp->Init.GCMCMACPhase == CRYP_PAYLOAD_PHASE) &&
3117  (hcryp->Init.OperatingMode == CRYP_ALGOMODE_ENCRYPT))
3118  {
3119  /* Change the mode configured in CHMOD bits of CR register to select CTR mode */
3120  __HAL_CRYP_SET_CHAININGMODE(hcryp, CRYP_CHAINMODE_AES_CTR);
3121  }
3122 #endif
3123 
3124  /* Wrap-up entering header or payload data */
3125  /* Enter complete words when possible */
3126  for(index=0U ; index < (difflength/4U); index ++)
3127  {
3128  /* Write the Input block in the Data Input register */
3129  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
3130  inputaddr+=4U;
3131  }
3132  /* Enter incomplete word padded with zeroes if applicable
3133  (case of header length not a multiple of 32-bits) */
3134  if (difflengthmod4 != 0U)
3135  {
3136  hcryp->Instance->DINR = ((*(uint32_t*)(inputaddr)) & mask[mask_index][difflengthmod4-1U]);
3137  }
3138  /* Pad with zero-words to reach 128-bit long block and wrap-up header feeding to the IP */
3139  for(index=0U ; index < (4U - ((difflength+3U)/4U)); index ++)
3140  {
3141  hcryp->Instance->DINR = 0;
3142  }
3143 
3144  if (polling == (uint32_t)CRYP_POLLING_ON)
3145  {
3146  if(CRYP_WaitOnCCFlag(hcryp, CRYP_CCF_TIMEOUTVALUE) != HAL_OK)
3147  {
3148  hcryp->State = HAL_CRYP_STATE_READY;
3149  __HAL_UNLOCK(hcryp);
3150 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
3151  hcryp->ErrorCallback(hcryp);
3152 #else
3153  HAL_CRYP_ErrorCallback(hcryp);
3154 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
3155  }
3156 
3157  /* Clear CCF Flag */
3158  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
3159  }
3160 
3161  /* if payload */
3162  if (hcryp->Init.GCMCMACPhase == CRYP_PAYLOAD_PHASE)
3163  {
3164 
3165  /* Retrieve intermediate data */
3166  for(index=0U ; index < 4U; index ++)
3167  {
3168  intermediate_data[index] = hcryp->Instance->DOUTR;
3169  }
3170  /* Retrieve last words of cyphered data */
3171  /* First, retrieve complete output words */
3172  for(index=0U ; index < (difflength/4U); index ++)
3173  {
3174  *(uint32_t*)(outputaddr) = intermediate_data[index];
3175  outputaddr+=4U;
3176  }
3177  /* Next, retrieve partial output word if applicable;
3178  at the same time, start masking intermediate data
3179  with a mask of zeros of same size than the padding
3180  applied to the last block of payload */
3181  if (difflengthmod4 != 0U)
3182  {
3183  intermediate_data[difflength/4U] &= mask[mask_index][difflengthmod4-1U];
3184  *(uint32_t*)(outputaddr) = intermediate_data[difflength/4U];
3185  }
3186 
3187 
3188 #if !defined(AES_CR_NPBLB)
3189  /* Software workaround applied to GCM encryption only,
3190  applicable for AES IP v2 version (where NPBLB is not defined) */
3191  if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_ENCRYPT)
3192  {
3193  /* Change again CHMOD configuration to GCM mode */
3194  __HAL_CRYP_SET_CHAININGMODE(hcryp, CRYP_CHAINMODE_AES_GCM_GMAC);
3195 
3196  /* Select FINAL phase */
3197  MODIFY_REG(hcryp->Instance->CR, AES_CR_GCMPH, CRYP_FINAL_PHASE);
3198 
3199  /* Before inserting the intermediate data, carry on masking operation
3200  with a mask of zeros of same size than the padding applied to the last block of payload */
3201  for(index=0U ; index < (4U - ((difflength+3U)/4U)); index ++)
3202  {
3203  intermediate_data[((difflength+3U)/4U)+index] = 0;
3204  }
3205  /* Insert intermediate data */
3206  for(index=0U ; index < 4U; index ++)
3207  {
3208  hcryp->Instance->DINR = intermediate_data[index];
3209  }
3210 
3211  /* Wait for completion, and read data on DOUT. This data is to discard. */
3212  if(CRYP_WaitOnCCFlag(hcryp, CRYP_CCF_TIMEOUTVALUE) != HAL_OK)
3213  {
3214  hcryp->State = HAL_CRYP_STATE_READY;
3215  __HAL_UNLOCK(hcryp);
3216  HAL_CRYP_ErrorCallback(hcryp);
3217  }
3218 
3219  /* Read data to discard */
3220  /* Clear CCF Flag */
3221  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
3222  for(index=0U ; index < 4U; index ++)
3223  {
3224  intermediate_data[index] = hcryp->Instance->DOUTR;
3225  }
3226 
3227  } /* if (hcryp->Init.OperatingMode == CRYP_ALGOMODE_ENCRYPT) */
3228 #endif /* !defined(AES_CR_NPBLB) */
3229  } /* if (hcryp->Init.GCMCMACPhase == CRYP_PAYLOAD_PHASE) */
3230 
3231 }
void(* ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp)
__IO HAL_CRYP_STATETypeDef State
__HAL_UNLOCK(hrtc)
return HAL_OK
void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp)
CRYP error callback.
static HAL_StatusTypeDef CRYP_WaitOnCCFlag(CRYP_HandleTypeDef const *const hcryp, uint32_t Timeout)
Handle CRYP hardware block Timeout when waiting for CCF flag to be raised.
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)

◆ CRYP_ProcessData()

static HAL_StatusTypeDef CRYP_ProcessData ( CRYP_HandleTypeDef hcryp,
uint8_t *  Input,
uint16_t  Ilength,
uint8_t *  Output,
uint32_t  Timeout 
)
static

Write/read input/output data in polling mode.

Parameters
hcryppointer to a CRYP_HandleTypeDef structure that contains the configuration information for CRYP module.
InputPointer to the Input buffer.
IlengthLength of the Input buffer in bytes, must be a multiple of 16.
OutputPointer to the returned buffer.
TimeoutSpecify Timeout value.
Return values
HALstatus

Definition at line 2780 of file stm32l4xx_hal_cryp_ex.c.

2781 {
2782  uint32_t index;
2783  uint32_t inputaddr = (uint32_t)Input;
2784  uint32_t outputaddr = (uint32_t)Output;
2785 
2786 
2787  for(index=0U ; (index < Ilength); index += 16U)
2788  {
2789  /* Write the Input block in the Data Input register */
2790  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2791  inputaddr+=4U;
2792  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2793  inputaddr+=4U;
2794  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2795  inputaddr+=4U;
2796  hcryp->Instance->DINR = *(uint32_t*)(inputaddr);
2797  inputaddr+=4U;
2798 
2799  /* Wait for CCF flag to be raised */
2800  if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
2801  {
2802  hcryp->State = HAL_CRYP_STATE_READY;
2803  __HAL_UNLOCK(hcryp);
2804  return HAL_TIMEOUT;
2805  }
2806 
2807  /* Clear CCF Flag */
2808  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2809 
2810  /* Read the Output block from the Data Output Register */
2811  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2812  outputaddr+=4U;
2813  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2814  outputaddr+=4U;
2815  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2816  outputaddr+=4U;
2817  *(uint32_t*)(outputaddr) = hcryp->Instance->DOUTR;
2818  outputaddr+=4U;
2819 
2820  /* If the suspension flag has been raised and if the processing is not about
2821  to end, suspend processing */
2822  if ((hcryp->SuspendRequest == HAL_CRYP_SUSPEND) && ((index+16U) < Ilength))
2823  {
2824  /* Reset SuspendRequest */
2826 
2827  /* Save current reading and writing locations of Input and Output buffers */
2828  hcryp->pCrypOutBuffPtr = (uint8_t *)outputaddr;
2829  hcryp->pCrypInBuffPtr = (uint8_t *)inputaddr;
2830  /* Save the number of bytes that remain to be processed at this point */
2831  hcryp->CrypInCount = Ilength - (index+16U);
2832 
2833  /* Change the CRYP state */
2835 
2836  return HAL_OK;
2837  }
2838 
2839 
2840  }
2841  /* Return function status */
2842  return HAL_OK;
2843 
2844 }
__IO HAL_CRYP_STATETypeDef State
__HAL_UNLOCK(hrtc)
HAL_SuspendTypeDef SuspendRequest
return HAL_OK
static HAL_StatusTypeDef CRYP_WaitOnCCFlag(CRYP_HandleTypeDef const *const hcryp, uint32_t Timeout)
Handle CRYP hardware block Timeout when waiting for CCF flag to be raised.

◆ CRYP_ReadKey()

static HAL_StatusTypeDef CRYP_ReadKey ( CRYP_HandleTypeDef hcryp,
uint8_t *  Output,
uint32_t  Timeout 
)
static

Read derivative key in polling mode when CRYP hardware block is set in key derivation operating mode (mode 2).

Parameters
hcryppointer to a CRYP_HandleTypeDef structure that contains the configuration information for CRYP module.
OutputPointer to the returned buffer.
TimeoutSpecify Timeout value.
Return values
HALstatus

Definition at line 2859 of file stm32l4xx_hal_cryp_ex.c.

2860 {
2861  uint32_t outputaddr = (uint32_t)Output;
2862 
2863  /* Wait for CCF flag to be raised */
2864  if(CRYP_WaitOnCCFlag(hcryp, Timeout) != HAL_OK)
2865  {
2866  hcryp->State = HAL_CRYP_STATE_READY;
2867  __HAL_UNLOCK(hcryp);
2868  return HAL_TIMEOUT;
2869  }
2870  /* Clear CCF Flag */
2871  __HAL_CRYP_CLEAR_FLAG(hcryp, CRYP_CCF_CLEAR);
2872 
2873  /* Read the derivative key from the AES_KEYRx registers */
2874  if (hcryp->Init.KeySize == CRYP_KEYSIZE_256B)
2875  {
2876  *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR7);
2877  outputaddr+=4U;
2878  *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR6);
2879  outputaddr+=4U;
2880  *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR5);
2881  outputaddr+=4U;
2882  *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR4);
2883  outputaddr+=4U;
2884  }
2885 
2886  *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR3);
2887  outputaddr+=4U;
2888  *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR2);
2889  outputaddr+=4U;
2890  *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR1);
2891  outputaddr+=4U;
2892  *(uint32_t*)(outputaddr) = __REV(hcryp->Instance->KEYR0);
2893 
2894 
2895  /* Return function status */
2896  return HAL_OK;
2897 }
__IO HAL_CRYP_STATETypeDef State
__HAL_UNLOCK(hrtc)
return HAL_OK
static HAL_StatusTypeDef CRYP_WaitOnCCFlag(CRYP_HandleTypeDef const *const hcryp, uint32_t Timeout)
Handle CRYP hardware block Timeout when waiting for CCF flag to be raised.

◆ CRYP_SetDMAConfig()

static void CRYP_SetDMAConfig ( CRYP_HandleTypeDef hcryp,
uint32_t  inputaddr,
uint16_t  Size,
uint32_t  outputaddr 
)
static

Set the DMA configuration and start the DMA transfer.

Parameters
hcryppointer to a CRYP_HandleTypeDef structure that contains the configuration information for CRYP module.
inputaddrAddress of the Input buffer.
SizeSize of the Input buffer in bytes, must be a multiple of 16.
outputaddrAddress of the Output buffer.
Return values
None

Definition at line 2908 of file stm32l4xx_hal_cryp_ex.c.

2909 {
2910  /* Set the CRYP DMA transfer complete callback */
2912  /* Set the DMA error callback */
2914 
2915  /* Set the CRYP DMA transfer complete callback */
2917  /* Set the DMA error callback */
2919 
2920  /* Enable the DMA input stream */
2921  if (HAL_DMA_Start_IT(hcryp->hdmain, inputaddr, (uint32_t)&hcryp->Instance->DINR, ((uint32_t)Size)/4U) != HAL_OK)
2922  {
2923 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2924  hcryp->ErrorCallback(hcryp);
2925 #else
2926  HAL_CRYP_ErrorCallback(hcryp);
2927 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2928  }
2929 
2930  /* Enable the DMA output stream */
2931  if (HAL_DMA_Start_IT(hcryp->hdmaout, (uint32_t)&hcryp->Instance->DOUTR, outputaddr, ((uint32_t)Size)/4U) != HAL_OK)
2932  {
2933 #if (USE_HAL_CRYP_REGISTER_CALLBACKS == 1)
2934  hcryp->ErrorCallback(hcryp);
2935 #else
2936  HAL_CRYP_ErrorCallback(hcryp);
2937 #endif /* USE_HAL_CRYP_REGISTER_CALLBACKS */
2938  }
2939 
2940  /* Enable In and Out DMA requests */
2941  SET_BIT(hcryp->Instance->CR, (AES_CR_DMAINEN | AES_CR_DMAOUTEN));
2942 
2943  /* Enable the CRYP peripheral */
2944  __HAL_CRYP_ENABLE(hcryp);
2945 }
static void CRYP_DMAOutCplt(DMA_HandleTypeDef *hdma)
DMA CRYP Output Data process complete callback.
void(* ErrorCallback)(struct __CRYP_HandleTypeDef *hcryp)
DMA_HandleTypeDef * hdmaout
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA_HandleTypeDef * hdmain
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
return HAL_OK
static void CRYP_DMAInCplt(DMA_HandleTypeDef *hdma)
DMA CRYP Input Data process complete callback.
void HAL_CRYP_ErrorCallback(CRYP_HandleTypeDef *hcryp)
CRYP error callback.
static void CRYP_DMAError(DMA_HandleTypeDef *hdma)
DMA CRYP communication error callback.

◆ CRYP_WaitOnBusyFlagReset()

static HAL_StatusTypeDef CRYP_WaitOnBusyFlagReset ( CRYP_HandleTypeDef const *const  hcryp,
uint32_t  Timeout 
)
static

Wait for Busy Flag to be reset during a GCM payload encryption process suspension.

Parameters
hcryppointer to a CRYP_HandleTypeDef structure that contains the configuration information for CRYP module.
TimeoutTimeout duration.
Return values
HALstatus

Definition at line 2983 of file stm32l4xx_hal_cryp_ex.c.

2984 {
2985  uint32_t tickstart;
2986 
2987  /* Get timeout */
2988  tickstart = HAL_GetTick();
2989 
2990  while(HAL_IS_BIT_SET(hcryp->Instance->SR, AES_SR_BUSY))
2991  {
2992  /* Check for the Timeout */
2993  if(Timeout != HAL_MAX_DELAY)
2994  {
2995  if((HAL_GetTick() - tickstart ) > Timeout)
2996  {
2997  return HAL_TIMEOUT;
2998  }
2999  }
3000  }
3001  return HAL_OK;
3002 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
return HAL_OK

◆ CRYP_WaitOnCCFlag()

static HAL_StatusTypeDef CRYP_WaitOnCCFlag ( CRYP_HandleTypeDef const *const  hcryp,
uint32_t  Timeout 
)
static

Handle CRYP hardware block Timeout when waiting for CCF flag to be raised.

Parameters
hcryppointer to a CRYP_HandleTypeDef structure that contains the configuration information for CRYP module.
TimeoutTimeout duration.
Return values
HALstatus

Definition at line 2955 of file stm32l4xx_hal_cryp_ex.c.

2956 {
2957  uint32_t tickstart;
2958 
2959  /* Get timeout */
2960  tickstart = HAL_GetTick();
2961 
2962  while(HAL_IS_BIT_CLR(hcryp->Instance->SR, AES_SR_CCF))
2963  {
2964  /* Check for the Timeout */
2965  if(Timeout != HAL_MAX_DELAY)
2966  {
2967  if((HAL_GetTick() - tickstart ) > Timeout)
2968  {
2969  return HAL_TIMEOUT;
2970  }
2971  }
2972  }
2973  return HAL_OK;
2974 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
return HAL_OK