Lines Matching +full:no +full:- +full:1 +full:- +full:8 +full:- +full:v

1 // SPDX-License-Identifier: (GPL-2.0-only OR Apache-2.0)
3 * BLAKE2b reference source code package - reference C implementations
9 * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
10 * - OpenSSL license : https://www.openssl.org/source/license.html
11 * - Apache 2.0 : https://www.apache.org/licenses/LICENSE-2.0
28 #define BLAKE2B_160_DIGEST_SIZE (160 / 8)
29 #define BLAKE2B_256_DIGEST_SIZE (256 / 8)
30 #define BLAKE2B_384_DIGEST_SIZE (384 / 8)
31 #define BLAKE2B_512_DIGEST_SIZE (512 / 8)
39 u64 h[8];
46 static const u64 blake2b_IV[8] = {
54 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
55 { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
56 { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
57 { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
58 { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
59 { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
60 { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
61 { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
62 { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
63 { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
64 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
65 { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
70 S->t[0] += inc; in blake2b_increment_counter()
71 S->t[1] += (S->t[0] < inc); in blake2b_increment_counter()
80 a = a + b + m[blake2b_sigma[r][2*i+1]]; \
88 G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
89 G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
90 G(r,2,v[ 2],v[ 6],v[10],v[14]); \
91 G(r,3,v[ 3],v[ 7],v[11],v[15]); \
92 G(r,4,v[ 0],v[ 5],v[10],v[15]); \
93 G(r,5,v[ 1],v[ 6],v[11],v[12]); \
94 G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
95 G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
102 u64 v[16]; in blake2b_compress() local
108 for (i = 0; i < 8; ++i) in blake2b_compress()
109 v[i] = S->h[i]; in blake2b_compress()
111 v[ 8] = blake2b_IV[0]; in blake2b_compress()
112 v[ 9] = blake2b_IV[1]; in blake2b_compress()
113 v[10] = blake2b_IV[2]; in blake2b_compress()
114 v[11] = blake2b_IV[3]; in blake2b_compress()
115 v[12] = blake2b_IV[4] ^ S->t[0]; in blake2b_compress()
116 v[13] = blake2b_IV[5] ^ S->t[1]; in blake2b_compress()
117 v[14] = blake2b_IV[6] ^ S->f[0]; in blake2b_compress()
118 v[15] = blake2b_IV[7] ^ S->f[1]; in blake2b_compress()
121 ROUND(1); in blake2b_compress()
128 ROUND(8); in blake2b_compress()
135 for (i = 0; i < 8; ++i) in blake2b_compress()
136 S->h[i] = S->h[i] ^ v[i] ^ v[i + 8]; in blake2b_compress()
153 return -EINVAL; in blake2b_setkey()
155 memcpy(tctx->key, key, keylen); in blake2b_setkey()
156 tctx->keylen = keylen; in blake2b_setkey()
163 struct blake2b_tfm_ctx *tctx = crypto_shash_ctx(desc->tfm); in blake2b_init()
165 const int digestsize = crypto_shash_digestsize(desc->tfm); in blake2b_init()
168 memcpy(state->h, blake2b_IV, sizeof(state->h)); in blake2b_init()
170 /* Parameter block is all zeros except index 0, no xor for 1..7 */ in blake2b_init()
171 state->h[0] ^= 0x01010000 | tctx->keylen << 8 | digestsize; in blake2b_init()
173 if (tctx->keylen) { in blake2b_init()
178 memcpy(state->buf, tctx->key, tctx->keylen); in blake2b_init()
179 state->buflen = BLAKE2B_BLOCKBYTES; in blake2b_init()
188 const size_t left = state->buflen; in blake2b_update()
189 const size_t fill = BLAKE2B_BLOCKBYTES - left; in blake2b_update()
195 state->buflen = 0; in blake2b_update()
197 memcpy(state->buf + left, in, fill); in blake2b_update()
200 blake2b_compress(state, state->buf); in blake2b_update()
202 inlen -= fill; in blake2b_update()
207 inlen -= BLAKE2B_BLOCKBYTES; in blake2b_update()
210 memcpy(state->buf + state->buflen, in, inlen); in blake2b_update()
211 state->buflen += inlen; in blake2b_update()
219 const int digestsize = crypto_shash_digestsize(desc->tfm); in blake2b_final()
222 blake2b_increment_counter(state, state->buflen); in blake2b_final()
224 state->f[0] = (u64)-1; in blake2b_final()
226 memset(state->buf + state->buflen, 0, BLAKE2B_BLOCKBYTES - state->buflen); in blake2b_final()
227 blake2b_compress(state, state->buf); in blake2b_final()
230 for (i = 0; i < ARRAY_SIZE(state->h); i++) in blake2b_final()
231 __cpu_to_le64s(&state->h[i]); in blake2b_final()
233 memcpy(out, state->h, digestsize); in blake2b_final()
239 .base.cra_name = "blake2b-160",
240 .base.cra_driver_name = "blake2b-160-generic",
253 .base.cra_name = "blake2b-256",
254 .base.cra_driver_name = "blake2b-256-generic",
267 .base.cra_name = "blake2b-384",
268 .base.cra_driver_name = "blake2b-384-generic",
281 .base.cra_name = "blake2b-512",
282 .base.cra_driver_name = "blake2b-512-generic",
313 MODULE_ALIAS_CRYPTO("blake2b-160");
314 MODULE_ALIAS_CRYPTO("blake2b-160-generic");
315 MODULE_ALIAS_CRYPTO("blake2b-256");
316 MODULE_ALIAS_CRYPTO("blake2b-256-generic");
317 MODULE_ALIAS_CRYPTO("blake2b-384");
318 MODULE_ALIAS_CRYPTO("blake2b-384-generic");
319 MODULE_ALIAS_CRYPTO("blake2b-512");
320 MODULE_ALIAS_CRYPTO("blake2b-512-generic");