37 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
44 #if (SHA224_SUPPORT == ENABLED || SHA256_SUPPORT == ENABLED)
47 #define W(n) w[(n) & 0x0F]
50 #define CH(x, y, z) (((x) & (y)) | (~(x) & (z)))
51 #define MAJ(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
52 #define SIGMA1(x) (ROR32(x, 2) ^ ROR32(x, 13) ^ ROR32(x, 22))
53 #define SIGMA2(x) (ROR32(x, 6) ^ ROR32(x, 11) ^ ROR32(x, 25))
54 #define SIGMA3(x) (ROR32(x, 7) ^ ROR32(x, 18) ^ SHR32(x, 3))
55 #define SIGMA4(x) (ROR32(x, 17) ^ ROR32(x, 19) ^ SHR32(x, 10))
58 static const uint8_t padding[64] =
60 0x80, 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,
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
67 static const uint32_t k[64] =
69 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
70 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
71 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
72 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
73 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
74 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
75 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
76 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
80 const uint8_t
SHA256_OID[9] = {0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01};
97 #if ((defined(MIMXRT1050_CRYPTO_HASH_SUPPORT) && MIMXRT1050_CRYPTO_HASH_SUPPORT == ENABLED) || \
98 (defined(MIMXRT1060_CRYPTO_HASH_SUPPORT) && MIMXRT1060_CRYPTO_HASH_SUPPORT == ENABLED) || \
99 (defined(MIMXRT1160_CRYPTO_HASH_SUPPORT) && MIMXRT1160_CRYPTO_HASH_SUPPORT == ENABLED) || \
100 (defined(MIMXRT1170_CRYPTO_HASH_SUPPORT) && MIMXRT1170_CRYPTO_HASH_SUPPORT == ENABLED))
118 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
131 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
146 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
164 context->
h[0] = 0x6A09E667;
165 context->
h[1] = 0xBB67AE85;
166 context->
h[2] = 0x3C6EF372;
167 context->
h[3] = 0xA54FF53A;
168 context->
h[4] = 0x510E527F;
169 context->
h[5] = 0x9B05688C;
170 context->
h[6] = 0x1F83D9AB;
171 context->
h[7] = 0x5BE0CD19;
209 if(context->
size == 64)
236 if(context->
size < 56)
238 paddingSize = 56 - context->
size;
242 paddingSize = 64 + 56 - context->
size;
249 context->
w[14] =
htobe32((uint32_t) (totalSize >> 32));
250 context->
w[15] =
htobe32((uint32_t) totalSize);
256 for(i = 0; i < 8; i++)
280 for(i = 0; i < 8; i++)
289 for(i = 0; i < 8; i++)
308 uint32_t
a = context->
h[0];
309 uint32_t
b = context->
h[1];
310 uint32_t
c = context->
h[2];
311 uint32_t d = context->
h[3];
312 uint32_t e = context->
h[4];
313 uint32_t f = context->
h[5];
314 uint32_t g = context->
h[6];
315 uint32_t
h = context->
h[7];
318 uint32_t *w = context->
w;
321 for(i = 0; i < 16; i++)
327 for(i = 0; i < 64; i++)
336 temp1 =
h +
SIGMA2(e) +
CH(e, f, g) + k[i] +
W(i);