38 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
45 #if (BLAKE2B_SUPPORT == ENABLED)
48 #define G(a, b, c, d, x, y) \
65 static const uint8_t sigma[12][16] =
67 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
68 {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
69 {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
70 {7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8},
71 {9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13},
72 {2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9},
73 {12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11},
74 {13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10},
75 {6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5},
76 {10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0},
77 {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
78 {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}
82 static const uint64_t
iv[8] =
84 0x6A09E667F3BCC908, 0xBB67AE8584CAA73B, 0x3C6EF372FE94F82B, 0xA54FF53A5F1D36F1,
85 0x510E527FADE682D1, 0x9B05688C2B3E6C1F, 0x1F83D9ABFB41BD6B, 0x5BE0CD19137E2179
101 size_t dataLen, uint8_t *digest,
size_t digestLen)
104 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
117 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
126 error =
blake2bInit(context, key, keyLen, digestLen);
137 #if (CRYPTO_STATIC_MEM_SUPPORT == DISABLED)
157 size_t keyLen,
size_t digestLen)
165 if(key == NULL && keyLen != 0)
173 if(digestLen < 1 || digestLen > 64)
177 for(i = 0; i < 8; i++)
179 context->
h[i] =
iv[i];
183 context->
h[0] ^= digestLen;
185 context->
h[0] ^= keyLen << 8;
187 context->
h[0] ^= 0x01010000;
231 if(context->
size == 128)
266 for(i = context->
size; i < 128; i++)
275 for(i = 0; i < 8; i++)
301 for(i = 0; i < 8; i++)
304 v[i] = context->
h[i];
334 for(i = 0; i < 16; i++)
340 for(i = 0; i < 12; i++)
344 G(v[0], v[4], v[8], v[12],
m[sigma[i][0]],
m[sigma[i][1]]);
345 G(v[1], v[5], v[9], v[13],
m[sigma[i][2]],
m[sigma[i][3]]);
346 G(v[2], v[6], v[10], v[14],
m[sigma[i][4]],
m[sigma[i][5]]);
347 G(v[3], v[7], v[11], v[15],
m[sigma[i][6]],
m[sigma[i][7]]);
352 G(v[0], v[5], v[10], v[15],
m[sigma[i][8]],
m[sigma[i][9]]);
353 G(v[1], v[6], v[11], v[12],
m[sigma[i][10]],
m[sigma[i][11]]);
354 G(v[2], v[7], v[8], v[13],
m[sigma[i][12]],
m[sigma[i][13]]);
355 G(v[3], v[4], v[9], v[14],
m[sigma[i][14]],
m[sigma[i][15]]);
359 for(i = 0; i < 8; i++)
361 context->
h[i] ^= v[i] ^ v[i + 8];