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  * History : DD.MM.YYYY Version Description
9  *         : 05.10.2020 1.00        First Release.
10  *         : 02.12.2020 1.01        Added new functions such as the Brainpool curve.
11 ***********************************************************************************************************************/
12 
13 /***********************************************************************************************************************
14 Includes   <System Includes> , "Project Includes"
15 ***********************************************************************************************************************/
16 #include "r_sce_if.h"
17 #include "hw_sce_ra_private.h"
18 
19 /***********************************************************************************************************************
20 Macro definitions
21 ***********************************************************************************************************************/
22 
23 /***********************************************************************************************************************
24 Typedef definitions
25 ***********************************************************************************************************************/
26 
27 /***********************************************************************************************************************
28 Imported global variables and functions (from other files)
29 ***********************************************************************************************************************/
30 
31 /***********************************************************************************************************************
32 Exported global variables (to be accessed by other files)
33 ***********************************************************************************************************************/
34 
35 /***********************************************************************************************************************
36 Private global variables and functions
37 ***********************************************************************************************************************/
38 
HW_SCE_Sha224256GenerateMessageDigestSub(const uint32_t * InData_InitVal,const uint32_t * InData_PaddedMsg,const uint32_t MAX_CNT,uint32_t * OutData_MsgDigest)39 fsp_err_t HW_SCE_Sha224256GenerateMessageDigestSub(const uint32_t *InData_InitVal, const uint32_t *InData_PaddedMsg, const uint32_t MAX_CNT, uint32_t *OutData_MsgDigest)
40 {
41     uint32_t iLoop    = 0U;
42     uint32_t iLoop1   = 0U;
43     uint32_t iLoop2   = 0U;
44     int32_t  jLoop    = 0U;
45     uint32_t kLoop    = 0U;
46     uint32_t oLoop    = 0U;
47     uint32_t oLoop1   = 0U;
48     uint32_t oLoop2   = 0U;
49     uint32_t dummy    = 0U;
50     uint32_t KEY_ADR  = 0U;
51     uint32_t OFS_ADR  = 0U;
52     uint32_t MAX_CNT2 = 0U;
53     (void)iLoop;
54     (void)iLoop1;
55     (void)iLoop2;
56     (void)jLoop;
57     (void)kLoop;
58     (void)oLoop;
59     (void)oLoop1;
60     (void)oLoop2;
61     (void)dummy;
62     (void)KEY_ADR;
63     (void)OFS_ADR;
64     (void)MAX_CNT2;
65     if (0x0U != (SCE->REG_1BCH & 0x1fU))
66     {
67         return FSP_ERR_CRYPTO_SCE_RESOURCE_CONFLICT;
68     }
69     SCE->REG_84H = 0x00007201U;
70     SCE->REG_108H = 0x00000000U;
71     HW_SCE_p_func100(0x89b55281U, 0x097f6146U, 0xd6a77de8U, 0xec3b48deU);
72     SCE->REG_7CH = 0x00000011U;
73     SCE->REG_104H = 0x00000764U;
74     SCE->REG_74H = 0x00000004U;
75     /* WAIT_LOOP */
76     while (1U != SCE->REG_104H_b.B31)
77     {
78         /* waiting */
79     }
80     SCE->REG_100H = InData_InitVal[0];
81     SCE->REG_100H = InData_InitVal[1];
82     SCE->REG_100H = InData_InitVal[2];
83     SCE->REG_100H = InData_InitVal[3];
84     SCE->REG_100H = InData_InitVal[4];
85     SCE->REG_100H = InData_InitVal[5];
86     SCE->REG_100H = InData_InitVal[6];
87     SCE->REG_100H = InData_InitVal[7];
88     SCE->REG_104H = 0x000000b4U;
89     SCE->REG_74H = 0x08000002U;
90     for (iLoop = 0; iLoop < MAX_CNT ; iLoop = iLoop + 16)
91     {
92         /* WAIT_LOOP */
93         while (1U != SCE->REG_104H_b.B31)
94         {
95             /* waiting */
96         }
97         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 0];
98         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 1];
99         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 2];
100         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 3];
101         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 4];
102         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 5];
103         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 6];
104         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 7];
105         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 8];
106         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 9];
107         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 10];
108         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 11];
109         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 12];
110         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 13];
111         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 14];
112         SCE->REG_100H = InData_PaddedMsg[0+iLoop + 15];
113     }
114     /* WAIT_LOOP */
115     while (0U != SCE->REG_74H_b.B18)
116     {
117         /* waiting */
118     }
119     SCE->REG_74H = 0x00000000U;
120     SCE->REG_104H = 0x00000000U;
121     SCE->REG_1CH = 0x00001600U;
122     SCE->REG_74H = 0x00000008U;
123     SCE->REG_04H = 0x00000523U;
124     /* WAIT_LOOP */
125     while (1U != SCE->REG_04H_b.B30)
126     {
127         /* waiting */
128     }
129     OutData_MsgDigest[0] = SCE->REG_100H;
130     OutData_MsgDigest[1] = SCE->REG_100H;
131     OutData_MsgDigest[2] = SCE->REG_100H;
132     OutData_MsgDigest[3] = SCE->REG_100H;
133     OutData_MsgDigest[4] = SCE->REG_100H;
134     OutData_MsgDigest[5] = SCE->REG_100H;
135     OutData_MsgDigest[6] = SCE->REG_100H;
136     OutData_MsgDigest[7] = SCE->REG_100H;
137     HW_SCE_p_func102(0x482a4372U, 0x21f251ebU, 0x29dc06a6U, 0x84167a56U);
138     SCE->REG_1BCH = 0x00000040U;
139     /* WAIT_LOOP */
140     while (0U != SCE->REG_18H_b.B12)
141     {
142         /* waiting */
143     }
144     return FSP_SUCCESS;
145 }
146 
147 /***********************************************************************************************************************
148 End of function ./input_dir/S6C1/Cryptographic_PlainKey/HW_SCE_p_p72.prc
149 ***********************************************************************************************************************/
150