1 /*
2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6 
7 //////////////////////////////////////////////////////////////////////
8 // <SC32#4 AES-256 Decryption CBC Mode>                             //
9 // Procedure number: 23                                             //
10 // File name      : SC324_p23.prc                                   //
11 // State Diagram  : main(FSM1)                                      //
12 // Start State    : main03                                          //
13 // End State      : main03                                          //
14 // Input Data     : InData_Key[8]                                   //
15 // : InData_IV[4]                                    //
16 // : InData_Text[MAX_CNT]                            //
17 // Output Data    : OutData_Text[MAX_CNT]                           //
18 // : (MAX_CNT is Multiples of four.)                 //
19 // OutData_IV[4]                                   //
20 // Return Value   : Pass, Fail or Resource_Conflict                 //
21 // ------------------------------------------------------------------//
22 // total cycle    : polling + write access + read access            //
23 // polling        :                                                 //
24 // polling access :                                                 //
25 // write access   :                                                 //
26 // read  access   :                                                 //
27 //////////////////////////////////////////////////////////////////////
28 
29 #include "sc324_aes_private.h"
30 #include "hw_sce_aes_private.h"
31 
32 /*******************************************************************************************************************//**
33  * AES-256 Decryption CBC Mode
34  *
35  * @param[in]  InData_Key      In data key
36  * @param[in]  InData_IV       In data iv
37  * @param[in]  num_words       The number words
38  * @param[in]  InData_Text     In data text
39  * @param      OutData_Text    The out data text
40  * @param      OutData_IV      The out data iv
41  *
42  * @retval FSP_SUCCESS          The operation completed successfully.
43  * @retval FSP_ERR_CRYPTO_INVALID_SIZE          The size of the data must be multiples of 4 WORDS / 16 bytes.
44  **********************************************************************************************************************/
HW_SCE_AES_256CbcDecrypt(const uint32_t * InData_Key,const uint32_t * InData_IV,const uint32_t num_words,const uint32_t * InData_Text,uint32_t * OutData_Text,uint32_t * OutData_IV)45 fsp_err_t HW_SCE_AES_256CbcDecrypt (const uint32_t * InData_Key,
46                                     const uint32_t * InData_IV,
47                                     const uint32_t   num_words,
48                                     const uint32_t * InData_Text,
49                                     uint32_t       * OutData_Text,
50                                     uint32_t       * OutData_IV)
51 {
52     hw_sc324_aes_ctrl_t aesCtrl;
53 
54     aesCtrl.encrypt_flag = SC324_AES_DECRYPT;
55     aesCtrl.keysize      = SC324_AES_KEYSIZE_256;
56     aesCtrl.mode         = SC324_AES_CBC;
57 
58     return hw_sc324_aes_kernel_process_data(&aesCtrl,
59                                             InData_Key,
60                                             InData_IV,
61                                             num_words,
62                                             InData_Text,
63                                             OutData_Text,
64                                             OutData_IV);
65 }
66