32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
35 #include "mxc_device.h"
45 #if (MAX32690_CRYPTO_HASH_SUPPORT == ENABLED)
58 size_t length, uint32_t *
h,
size_t hLen)
65 if(algo == MXC_CTB_HASH_SHA1 || algo == MXC_CTB_HASH_SHA224 ||
66 algo == MXC_CTB_HASH_SHA256)
79 MXC_CTB->ctrl = MXC_F_CTB_CTRL_RST;
83 while((MXC_CTB->ctrl & MXC_F_CTB_CTRL_RDY) == 0)
88 MXC_CTB->ctrl |= MXC_F_CTB_CTRL_FLAG_MODE;
90 MXC_CTB->ctrl |= MXC_F_CTB_CTRL_HSH_DONE;
93 MXC_CTB->hash_ctrl = (algo << MXC_F_CTB_HASH_CTRL_HASH_POS) &
94 MXC_F_CTB_HASH_CTRL_HASH;
97 MXC_CTB->hash_msg_sz[0] =
length;
98 MXC_CTB->hash_msg_sz[1] = 0;
99 MXC_CTB->hash_msg_sz[2] = 0;
100 MXC_CTB->hash_msg_sz[3] = 0;
103 temp = MXC_CTB->ctrl & ~MXC_F_CTB_CTRL_SRC;
104 temp |= MXC_CTB_HASH_SOURCE_INFIFO << MXC_F_CTB_CTRL_SRC_POS;
105 MXC_CTB->ctrl = temp;
108 MXC_CTB->hash_ctrl |= MXC_F_CTB_HASH_CTRL_INIT;
111 while((MXC_CTB->hash_ctrl & MXC_F_CTB_HASH_CTRL_INIT) != 0)
119 for(i = 0; i < hLen; i++)
121 MXC_CTB->hash_digest[i] =
htobe32(
h[i]);
127 for(i = 0; i < hLen; i += 2)
129 MXC_CTB->hash_digest[i] =
htobe32(
h[i + 1]);
130 MXC_CTB->hash_digest[i + 1] =
htobe32(
h[i]);
135 while(
length >= blockSize)
138 MXC_CTB->din[0] = __UNALIGNED_UINT32_READ(
data);
139 MXC_CTB->din[1] = __UNALIGNED_UINT32_READ(
data + 4);
140 MXC_CTB->din[2] = __UNALIGNED_UINT32_READ(
data + 8);
141 MXC_CTB->din[3] = __UNALIGNED_UINT32_READ(
data + 12);
142 MXC_CTB->din[0] = __UNALIGNED_UINT32_READ(
data + 16);
143 MXC_CTB->din[1] = __UNALIGNED_UINT32_READ(
data + 20);
144 MXC_CTB->din[2] = __UNALIGNED_UINT32_READ(
data + 24);
145 MXC_CTB->din[3] = __UNALIGNED_UINT32_READ(
data + 28);
146 MXC_CTB->din[0] = __UNALIGNED_UINT32_READ(
data + 32);
147 MXC_CTB->din[1] = __UNALIGNED_UINT32_READ(
data + 36);
148 MXC_CTB->din[2] = __UNALIGNED_UINT32_READ(
data + 40);
149 MXC_CTB->din[3] = __UNALIGNED_UINT32_READ(
data + 44);
150 MXC_CTB->din[0] = __UNALIGNED_UINT32_READ(
data + 48);
151 MXC_CTB->din[1] = __UNALIGNED_UINT32_READ(
data + 52);
152 MXC_CTB->din[2] = __UNALIGNED_UINT32_READ(
data + 56);
153 MXC_CTB->din[3] = __UNALIGNED_UINT32_READ(
data + 60);
158 MXC_CTB->din[0] = __UNALIGNED_UINT32_READ(
data + 64);
159 MXC_CTB->din[1] = __UNALIGNED_UINT32_READ(
data + 68);
160 MXC_CTB->din[2] = __UNALIGNED_UINT32_READ(
data + 72);
161 MXC_CTB->din[3] = __UNALIGNED_UINT32_READ(
data + 76);
162 MXC_CTB->din[0] = __UNALIGNED_UINT32_READ(
data + 80);
163 MXC_CTB->din[1] = __UNALIGNED_UINT32_READ(
data + 84);
164 MXC_CTB->din[2] = __UNALIGNED_UINT32_READ(
data + 88);
165 MXC_CTB->din[3] = __UNALIGNED_UINT32_READ(
data + 92);
166 MXC_CTB->din[0] = __UNALIGNED_UINT32_READ(
data + 96);
167 MXC_CTB->din[1] = __UNALIGNED_UINT32_READ(
data + 100);
168 MXC_CTB->din[2] = __UNALIGNED_UINT32_READ(
data + 104);
169 MXC_CTB->din[3] = __UNALIGNED_UINT32_READ(
data + 108);
170 MXC_CTB->din[0] = __UNALIGNED_UINT32_READ(
data + 112);
171 MXC_CTB->din[1] = __UNALIGNED_UINT32_READ(
data + 116);
172 MXC_CTB->din[2] = __UNALIGNED_UINT32_READ(
data + 120);
173 MXC_CTB->din[3] = __UNALIGNED_UINT32_READ(
data + 124);
177 while((MXC_CTB->ctrl & MXC_F_CTB_CTRL_HSH_DONE) == 0)
182 MXC_CTB->ctrl |= MXC_F_CTB_CTRL_HSH_DONE;
193 for(i = 0; i < hLen; i++)
195 h[i] =
betoh32(MXC_CTB->hash_digest[i]);
201 for(i = 0; i < hLen; i += 2)
203 h[i] =
betoh32(MXC_CTB->hash_digest[i + 1]);
204 h[i + 1] =
betoh32(MXC_CTB->hash_digest[i]);
209 MXC_CTB->hash_ctrl = (MXC_CTB_HASH_DIS << MXC_F_CTB_HASH_CTRL_HASH_POS) &
210 MXC_F_CTB_HASH_CTRL_HASH;
217 #if (SHA1_SUPPORT == ENABLED)
267 if(context->
size == 64)
294 #if (SHA256_SUPPORT == ENABLED)
344 if(context->
size == 64)
371 #if (SHA512_SUPPORT == ENABLED)
421 if(context->
size == 128)