32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
39 #if (SM3_SUPPORT == ENABLED)
42 #define W(n) w[(n) & 0x0F]
45 #define FF1(x, y, z) ((x) ^ (y) ^ (z))
46 #define FF2(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
47 #define GG1(x, y, z) ((x) ^ (y) ^ (z))
48 #define GG2(x, y, z) (((x) & (y)) | ((~x) & (z)))
49 #define P0(x) ((x) ^ ROL32(x, 9) ^ ROL32(x, 17))
50 #define P1(x) ((x) ^ ROL32(x, 15) ^ ROL32(x, 23))
53 #define TJ1 0x79CC4519
54 #define TJ2 0x7A879D8A
57 static const uint8_t padding[64] =
59 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
66 const uint8_t
SM3_OID[6] = {0x28, 0xCF, 0x06, 0x03, 0x00, 0x41};
97 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
110 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
125 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
143 context->
h[0] = 0x7380166F;
144 context->
h[1] = 0x4914B2B9;
145 context->
h[2] = 0x172442D7;
146 context->
h[3] = 0xDA8A0600;
147 context->
h[4] = 0xA96F30BC;
148 context->
h[5] = 0x163138AA;
149 context->
h[6] = 0xE38DEE4D;
150 context->
h[7] = 0xB0FB0E4E;
188 if(context->
size == 64)
215 if(context->
size < 56)
217 paddingSize = 56 - context->
size;
221 paddingSize = 64 + 56 - context->
size;
225 sm3Update(context, padding, paddingSize);
228 context->
w[14] =
htobe32((uint32_t) (totalSize >> 32));
229 context->
w[15] =
htobe32((uint32_t) totalSize);
235 for(i = 0; i < 8; i++)
259 for(i = 0; i < 8; i++)
268 for(i = 0; i < 8; i++)
290 uint32_t
a = context->
h[0];
291 uint32_t
b = context->
h[1];
292 uint32_t
c = context->
h[2];
293 uint32_t d = context->
h[3];
294 uint32_t e = context->
h[4];
295 uint32_t f = context->
h[5];
296 uint32_t g = context->
h[6];
297 uint32_t
h = context->
h[7];
300 uint32_t *w = context->
w;
303 for(i = 0; i < 16; i++)
309 for(i = 0; i < 64; i++)
314 temp =
W(i + 4) ^
W(i + 11) ^
ROL32(
W(i + 1), 15);
315 W(i + 4) =
P1(temp) ^
ROL32(
W(i + 7), 7) ^
W(i + 14);
322 ss1 =
ROL32(temp, 7);
324 tt1 =
FF1(
a,
b,
c) + d + ss2 + (
W(i) ^
W(i + 4));
325 tt2 =
GG1(e, f, g) +
h + ss1 +
W(i);
330 ss1 =
ROL32(temp, 7);
332 tt1 =
FF2(
a,
b,
c) + d + ss2 + (
W(i) ^
W(i + 4));
333 tt2 =
GG2(e, f, g) +
h + ss1 +
W(i);