1*91d68933SDavid Sterba // SPDX-License-Identifier: (GPL-2.0-only OR Apache-2.0) 2*91d68933SDavid Sterba /* 3*91d68933SDavid Sterba * BLAKE2b reference source code package - reference C implementations 4*91d68933SDavid Sterba * 5*91d68933SDavid Sterba * Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the 6*91d68933SDavid Sterba * terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at 7*91d68933SDavid Sterba * your option. The terms of these licenses can be found at: 8*91d68933SDavid Sterba * 9*91d68933SDavid Sterba * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0 10*91d68933SDavid Sterba * - OpenSSL license : https://www.openssl.org/source/license.html 11*91d68933SDavid Sterba * - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0 12*91d68933SDavid Sterba * 13*91d68933SDavid Sterba * More information about the BLAKE2 hash function can be found at 14*91d68933SDavid Sterba * https://blake2.net. 15*91d68933SDavid Sterba * 16*91d68933SDavid Sterba * Note: the original sources have been modified for inclusion in linux kernel 17*91d68933SDavid Sterba * in terms of coding style, using generic helpers and simplifications of error 18*91d68933SDavid Sterba * handling. 19*91d68933SDavid Sterba */ 20*91d68933SDavid Sterba 21*91d68933SDavid Sterba #include <asm/unaligned.h> 22*91d68933SDavid Sterba #include <linux/module.h> 23*91d68933SDavid Sterba #include <linux/string.h> 24*91d68933SDavid Sterba #include <linux/kernel.h> 25*91d68933SDavid Sterba #include <linux/bitops.h> 26*91d68933SDavid Sterba #include <crypto/internal/hash.h> 27*91d68933SDavid Sterba 28*91d68933SDavid Sterba #define BLAKE2B_160_DIGEST_SIZE (160 / 8) 29*91d68933SDavid Sterba #define BLAKE2B_256_DIGEST_SIZE (256 / 8) 30*91d68933SDavid Sterba #define BLAKE2B_384_DIGEST_SIZE (384 / 8) 31*91d68933SDavid Sterba #define BLAKE2B_512_DIGEST_SIZE (512 / 8) 32*91d68933SDavid Sterba 33*91d68933SDavid Sterba enum blake2b_constant { 34*91d68933SDavid Sterba BLAKE2B_BLOCKBYTES = 128, 35*91d68933SDavid Sterba BLAKE2B_OUTBYTES = 64, 36*91d68933SDavid Sterba BLAKE2B_KEYBYTES = 64, 37*91d68933SDavid Sterba BLAKE2B_SALTBYTES = 16, 38*91d68933SDavid Sterba BLAKE2B_PERSONALBYTES = 16 39*91d68933SDavid Sterba }; 40*91d68933SDavid Sterba 41*91d68933SDavid Sterba struct blake2b_state { 42*91d68933SDavid Sterba u64 h[8]; 43*91d68933SDavid Sterba u64 t[2]; 44*91d68933SDavid Sterba u64 f[2]; 45*91d68933SDavid Sterba u8 buf[BLAKE2B_BLOCKBYTES]; 46*91d68933SDavid Sterba size_t buflen; 47*91d68933SDavid Sterba size_t outlen; 48*91d68933SDavid Sterba u8 last_node; 49*91d68933SDavid Sterba }; 50*91d68933SDavid Sterba 51*91d68933SDavid Sterba struct blake2b_param { 52*91d68933SDavid Sterba u8 digest_length; /* 1 */ 53*91d68933SDavid Sterba u8 key_length; /* 2 */ 54*91d68933SDavid Sterba u8 fanout; /* 3 */ 55*91d68933SDavid Sterba u8 depth; /* 4 */ 56*91d68933SDavid Sterba __le32 leaf_length; /* 8 */ 57*91d68933SDavid Sterba __le32 node_offset; /* 12 */ 58*91d68933SDavid Sterba __le32 xof_length; /* 16 */ 59*91d68933SDavid Sterba u8 node_depth; /* 17 */ 60*91d68933SDavid Sterba u8 inner_length; /* 18 */ 61*91d68933SDavid Sterba u8 reserved[14]; /* 32 */ 62*91d68933SDavid Sterba u8 salt[BLAKE2B_SALTBYTES]; /* 48 */ 63*91d68933SDavid Sterba u8 personal[BLAKE2B_PERSONALBYTES]; /* 64 */ 64*91d68933SDavid Sterba } __packed; 65*91d68933SDavid Sterba 66*91d68933SDavid Sterba static const u64 blake2b_IV[8] = { 67*91d68933SDavid Sterba 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 68*91d68933SDavid Sterba 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, 69*91d68933SDavid Sterba 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, 70*91d68933SDavid Sterba 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL 71*91d68933SDavid Sterba }; 72*91d68933SDavid Sterba 73*91d68933SDavid Sterba static const u8 blake2b_sigma[12][16] = { 74*91d68933SDavid Sterba { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 75*91d68933SDavid Sterba { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }, 76*91d68933SDavid Sterba { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 }, 77*91d68933SDavid Sterba { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 }, 78*91d68933SDavid Sterba { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 }, 79*91d68933SDavid Sterba { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }, 80*91d68933SDavid Sterba { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 }, 81*91d68933SDavid Sterba { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 }, 82*91d68933SDavid Sterba { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 }, 83*91d68933SDavid Sterba { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 }, 84*91d68933SDavid Sterba { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, 85*91d68933SDavid Sterba { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } 86*91d68933SDavid Sterba }; 87*91d68933SDavid Sterba 88*91d68933SDavid Sterba static void blake2b_update(struct blake2b_state *S, const void *pin, size_t inlen); 89*91d68933SDavid Sterba 90*91d68933SDavid Sterba static void blake2b_set_lastnode(struct blake2b_state *S) 91*91d68933SDavid Sterba { 92*91d68933SDavid Sterba S->f[1] = (u64)-1; 93*91d68933SDavid Sterba } 94*91d68933SDavid Sterba 95*91d68933SDavid Sterba static void blake2b_set_lastblock(struct blake2b_state *S) 96*91d68933SDavid Sterba { 97*91d68933SDavid Sterba if (S->last_node) 98*91d68933SDavid Sterba blake2b_set_lastnode(S); 99*91d68933SDavid Sterba 100*91d68933SDavid Sterba S->f[0] = (u64)-1; 101*91d68933SDavid Sterba } 102*91d68933SDavid Sterba 103*91d68933SDavid Sterba static void blake2b_increment_counter(struct blake2b_state *S, const u64 inc) 104*91d68933SDavid Sterba { 105*91d68933SDavid Sterba S->t[0] += inc; 106*91d68933SDavid Sterba S->t[1] += (S->t[0] < inc); 107*91d68933SDavid Sterba } 108*91d68933SDavid Sterba 109*91d68933SDavid Sterba static void blake2b_init0(struct blake2b_state *S) 110*91d68933SDavid Sterba { 111*91d68933SDavid Sterba size_t i; 112*91d68933SDavid Sterba 113*91d68933SDavid Sterba memset(S, 0, sizeof(struct blake2b_state)); 114*91d68933SDavid Sterba 115*91d68933SDavid Sterba for (i = 0; i < 8; ++i) 116*91d68933SDavid Sterba S->h[i] = blake2b_IV[i]; 117*91d68933SDavid Sterba } 118*91d68933SDavid Sterba 119*91d68933SDavid Sterba /* init xors IV with input parameter block */ 120*91d68933SDavid Sterba static void blake2b_init_param(struct blake2b_state *S, 121*91d68933SDavid Sterba const struct blake2b_param *P) 122*91d68933SDavid Sterba { 123*91d68933SDavid Sterba const u8 *p = (const u8 *)(P); 124*91d68933SDavid Sterba size_t i; 125*91d68933SDavid Sterba 126*91d68933SDavid Sterba blake2b_init0(S); 127*91d68933SDavid Sterba 128*91d68933SDavid Sterba /* IV XOR ParamBlock */ 129*91d68933SDavid Sterba for (i = 0; i < 8; ++i) 130*91d68933SDavid Sterba S->h[i] ^= get_unaligned_le64(p + sizeof(S->h[i]) * i); 131*91d68933SDavid Sterba 132*91d68933SDavid Sterba S->outlen = P->digest_length; 133*91d68933SDavid Sterba } 134*91d68933SDavid Sterba 135*91d68933SDavid Sterba static void blake2b_init(struct blake2b_state *S, size_t outlen) 136*91d68933SDavid Sterba { 137*91d68933SDavid Sterba struct blake2b_param P; 138*91d68933SDavid Sterba 139*91d68933SDavid Sterba P.digest_length = (u8)outlen; 140*91d68933SDavid Sterba P.key_length = 0; 141*91d68933SDavid Sterba P.fanout = 1; 142*91d68933SDavid Sterba P.depth = 1; 143*91d68933SDavid Sterba P.leaf_length = 0; 144*91d68933SDavid Sterba P.node_offset = 0; 145*91d68933SDavid Sterba P.xof_length = 0; 146*91d68933SDavid Sterba P.node_depth = 0; 147*91d68933SDavid Sterba P.inner_length = 0; 148*91d68933SDavid Sterba memset(P.reserved, 0, sizeof(P.reserved)); 149*91d68933SDavid Sterba memset(P.salt, 0, sizeof(P.salt)); 150*91d68933SDavid Sterba memset(P.personal, 0, sizeof(P.personal)); 151*91d68933SDavid Sterba blake2b_init_param(S, &P); 152*91d68933SDavid Sterba } 153*91d68933SDavid Sterba 154*91d68933SDavid Sterba static void blake2b_init_key(struct blake2b_state *S, size_t outlen, 155*91d68933SDavid Sterba const void *key, size_t keylen) 156*91d68933SDavid Sterba { 157*91d68933SDavid Sterba struct blake2b_param P; 158*91d68933SDavid Sterba 159*91d68933SDavid Sterba P.digest_length = (u8)outlen; 160*91d68933SDavid Sterba P.key_length = (u8)keylen; 161*91d68933SDavid Sterba P.fanout = 1; 162*91d68933SDavid Sterba P.depth = 1; 163*91d68933SDavid Sterba P.leaf_length = 0; 164*91d68933SDavid Sterba P.node_offset = 0; 165*91d68933SDavid Sterba P.xof_length = 0; 166*91d68933SDavid Sterba P.node_depth = 0; 167*91d68933SDavid Sterba P.inner_length = 0; 168*91d68933SDavid Sterba memset(P.reserved, 0, sizeof(P.reserved)); 169*91d68933SDavid Sterba memset(P.salt, 0, sizeof(P.salt)); 170*91d68933SDavid Sterba memset(P.personal, 0, sizeof(P.personal)); 171*91d68933SDavid Sterba 172*91d68933SDavid Sterba blake2b_init_param(S, &P); 173*91d68933SDavid Sterba 174*91d68933SDavid Sterba { 175*91d68933SDavid Sterba u8 block[BLAKE2B_BLOCKBYTES]; 176*91d68933SDavid Sterba 177*91d68933SDavid Sterba memset(block, 0, BLAKE2B_BLOCKBYTES); 178*91d68933SDavid Sterba memcpy(block, key, keylen); 179*91d68933SDavid Sterba blake2b_update(S, block, BLAKE2B_BLOCKBYTES); 180*91d68933SDavid Sterba memzero_explicit(block, BLAKE2B_BLOCKBYTES); 181*91d68933SDavid Sterba } 182*91d68933SDavid Sterba } 183*91d68933SDavid Sterba 184*91d68933SDavid Sterba #define G(r,i,a,b,c,d) \ 185*91d68933SDavid Sterba do { \ 186*91d68933SDavid Sterba a = a + b + m[blake2b_sigma[r][2*i+0]]; \ 187*91d68933SDavid Sterba d = ror64(d ^ a, 32); \ 188*91d68933SDavid Sterba c = c + d; \ 189*91d68933SDavid Sterba b = ror64(b ^ c, 24); \ 190*91d68933SDavid Sterba a = a + b + m[blake2b_sigma[r][2*i+1]]; \ 191*91d68933SDavid Sterba d = ror64(d ^ a, 16); \ 192*91d68933SDavid Sterba c = c + d; \ 193*91d68933SDavid Sterba b = ror64(b ^ c, 63); \ 194*91d68933SDavid Sterba } while (0) 195*91d68933SDavid Sterba 196*91d68933SDavid Sterba #define ROUND(r) \ 197*91d68933SDavid Sterba do { \ 198*91d68933SDavid Sterba G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \ 199*91d68933SDavid Sterba G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \ 200*91d68933SDavid Sterba G(r,2,v[ 2],v[ 6],v[10],v[14]); \ 201*91d68933SDavid Sterba G(r,3,v[ 3],v[ 7],v[11],v[15]); \ 202*91d68933SDavid Sterba G(r,4,v[ 0],v[ 5],v[10],v[15]); \ 203*91d68933SDavid Sterba G(r,5,v[ 1],v[ 6],v[11],v[12]); \ 204*91d68933SDavid Sterba G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \ 205*91d68933SDavid Sterba G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \ 206*91d68933SDavid Sterba } while (0) 207*91d68933SDavid Sterba 208*91d68933SDavid Sterba static void blake2b_compress(struct blake2b_state *S, 209*91d68933SDavid Sterba const u8 block[BLAKE2B_BLOCKBYTES]) 210*91d68933SDavid Sterba { 211*91d68933SDavid Sterba u64 m[16]; 212*91d68933SDavid Sterba u64 v[16]; 213*91d68933SDavid Sterba size_t i; 214*91d68933SDavid Sterba 215*91d68933SDavid Sterba for (i = 0; i < 16; ++i) 216*91d68933SDavid Sterba m[i] = get_unaligned_le64(block + i * sizeof(m[i])); 217*91d68933SDavid Sterba 218*91d68933SDavid Sterba for (i = 0; i < 8; ++i) 219*91d68933SDavid Sterba v[i] = S->h[i]; 220*91d68933SDavid Sterba 221*91d68933SDavid Sterba v[ 8] = blake2b_IV[0]; 222*91d68933SDavid Sterba v[ 9] = blake2b_IV[1]; 223*91d68933SDavid Sterba v[10] = blake2b_IV[2]; 224*91d68933SDavid Sterba v[11] = blake2b_IV[3]; 225*91d68933SDavid Sterba v[12] = blake2b_IV[4] ^ S->t[0]; 226*91d68933SDavid Sterba v[13] = blake2b_IV[5] ^ S->t[1]; 227*91d68933SDavid Sterba v[14] = blake2b_IV[6] ^ S->f[0]; 228*91d68933SDavid Sterba v[15] = blake2b_IV[7] ^ S->f[1]; 229*91d68933SDavid Sterba 230*91d68933SDavid Sterba ROUND(0); 231*91d68933SDavid Sterba ROUND(1); 232*91d68933SDavid Sterba ROUND(2); 233*91d68933SDavid Sterba ROUND(3); 234*91d68933SDavid Sterba ROUND(4); 235*91d68933SDavid Sterba ROUND(5); 236*91d68933SDavid Sterba ROUND(6); 237*91d68933SDavid Sterba ROUND(7); 238*91d68933SDavid Sterba ROUND(8); 239*91d68933SDavid Sterba ROUND(9); 240*91d68933SDavid Sterba ROUND(10); 241*91d68933SDavid Sterba ROUND(11); 242*91d68933SDavid Sterba 243*91d68933SDavid Sterba for (i = 0; i < 8; ++i) 244*91d68933SDavid Sterba S->h[i] = S->h[i] ^ v[i] ^ v[i + 8]; 245*91d68933SDavid Sterba } 246*91d68933SDavid Sterba 247*91d68933SDavid Sterba #undef G 248*91d68933SDavid Sterba #undef ROUND 249*91d68933SDavid Sterba 250*91d68933SDavid Sterba static void blake2b_update(struct blake2b_state *S, const void *pin, size_t inlen) 251*91d68933SDavid Sterba { 252*91d68933SDavid Sterba const u8 *in = (const u8 *)pin; 253*91d68933SDavid Sterba 254*91d68933SDavid Sterba if (inlen > 0) { 255*91d68933SDavid Sterba size_t left = S->buflen; 256*91d68933SDavid Sterba size_t fill = BLAKE2B_BLOCKBYTES - left; 257*91d68933SDavid Sterba 258*91d68933SDavid Sterba if (inlen > fill) { 259*91d68933SDavid Sterba S->buflen = 0; 260*91d68933SDavid Sterba /* Fill buffer */ 261*91d68933SDavid Sterba memcpy(S->buf + left, in, fill); 262*91d68933SDavid Sterba blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES); 263*91d68933SDavid Sterba /* Compress */ 264*91d68933SDavid Sterba blake2b_compress(S, S->buf); 265*91d68933SDavid Sterba in += fill; 266*91d68933SDavid Sterba inlen -= fill; 267*91d68933SDavid Sterba while (inlen > BLAKE2B_BLOCKBYTES) { 268*91d68933SDavid Sterba blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES); 269*91d68933SDavid Sterba blake2b_compress(S, in); 270*91d68933SDavid Sterba in += BLAKE2B_BLOCKBYTES; 271*91d68933SDavid Sterba inlen -= BLAKE2B_BLOCKBYTES; 272*91d68933SDavid Sterba } 273*91d68933SDavid Sterba } 274*91d68933SDavid Sterba memcpy(S->buf + S->buflen, in, inlen); 275*91d68933SDavid Sterba S->buflen += inlen; 276*91d68933SDavid Sterba } 277*91d68933SDavid Sterba } 278*91d68933SDavid Sterba 279*91d68933SDavid Sterba static void blake2b_final(struct blake2b_state *S, void *out, size_t outlen) 280*91d68933SDavid Sterba { 281*91d68933SDavid Sterba u8 buffer[BLAKE2B_OUTBYTES] = {0}; 282*91d68933SDavid Sterba size_t i; 283*91d68933SDavid Sterba 284*91d68933SDavid Sterba blake2b_increment_counter(S, S->buflen); 285*91d68933SDavid Sterba blake2b_set_lastblock(S); 286*91d68933SDavid Sterba /* Padding */ 287*91d68933SDavid Sterba memset(S->buf + S->buflen, 0, BLAKE2B_BLOCKBYTES - S->buflen); 288*91d68933SDavid Sterba blake2b_compress(S, S->buf); 289*91d68933SDavid Sterba 290*91d68933SDavid Sterba /* Output full hash to temp buffer */ 291*91d68933SDavid Sterba for (i = 0; i < 8; ++i) 292*91d68933SDavid Sterba put_unaligned_le64(S->h[i], buffer + sizeof(S->h[i]) * i); 293*91d68933SDavid Sterba 294*91d68933SDavid Sterba memcpy(out, buffer, S->outlen); 295*91d68933SDavid Sterba memzero_explicit(buffer, sizeof(buffer)); 296*91d68933SDavid Sterba } 297*91d68933SDavid Sterba 298*91d68933SDavid Sterba struct digest_tfm_ctx { 299*91d68933SDavid Sterba u8 key[BLAKE2B_KEYBYTES]; 300*91d68933SDavid Sterba unsigned int keylen; 301*91d68933SDavid Sterba }; 302*91d68933SDavid Sterba 303*91d68933SDavid Sterba static int digest_setkey(struct crypto_shash *tfm, const u8 *key, 304*91d68933SDavid Sterba unsigned int keylen) 305*91d68933SDavid Sterba { 306*91d68933SDavid Sterba struct digest_tfm_ctx *mctx = crypto_shash_ctx(tfm); 307*91d68933SDavid Sterba 308*91d68933SDavid Sterba if (keylen == 0 || keylen > BLAKE2B_KEYBYTES) { 309*91d68933SDavid Sterba crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); 310*91d68933SDavid Sterba return -EINVAL; 311*91d68933SDavid Sterba } 312*91d68933SDavid Sterba 313*91d68933SDavid Sterba memcpy(mctx->key, key, keylen); 314*91d68933SDavid Sterba mctx->keylen = keylen; 315*91d68933SDavid Sterba 316*91d68933SDavid Sterba return 0; 317*91d68933SDavid Sterba } 318*91d68933SDavid Sterba 319*91d68933SDavid Sterba static int digest_init(struct shash_desc *desc) 320*91d68933SDavid Sterba { 321*91d68933SDavid Sterba struct digest_tfm_ctx *mctx = crypto_shash_ctx(desc->tfm); 322*91d68933SDavid Sterba struct blake2b_state *state = shash_desc_ctx(desc); 323*91d68933SDavid Sterba const int digestsize = crypto_shash_digestsize(desc->tfm); 324*91d68933SDavid Sterba 325*91d68933SDavid Sterba if (mctx->keylen == 0) 326*91d68933SDavid Sterba blake2b_init(state, digestsize); 327*91d68933SDavid Sterba else 328*91d68933SDavid Sterba blake2b_init_key(state, digestsize, mctx->key, mctx->keylen); 329*91d68933SDavid Sterba return 0; 330*91d68933SDavid Sterba } 331*91d68933SDavid Sterba 332*91d68933SDavid Sterba static int digest_update(struct shash_desc *desc, const u8 *data, 333*91d68933SDavid Sterba unsigned int length) 334*91d68933SDavid Sterba { 335*91d68933SDavid Sterba struct blake2b_state *state = shash_desc_ctx(desc); 336*91d68933SDavid Sterba 337*91d68933SDavid Sterba blake2b_update(state, data, length); 338*91d68933SDavid Sterba return 0; 339*91d68933SDavid Sterba } 340*91d68933SDavid Sterba 341*91d68933SDavid Sterba static int digest_final(struct shash_desc *desc, u8 *out) 342*91d68933SDavid Sterba { 343*91d68933SDavid Sterba struct blake2b_state *state = shash_desc_ctx(desc); 344*91d68933SDavid Sterba const int digestsize = crypto_shash_digestsize(desc->tfm); 345*91d68933SDavid Sterba 346*91d68933SDavid Sterba blake2b_final(state, out, digestsize); 347*91d68933SDavid Sterba return 0; 348*91d68933SDavid Sterba } 349*91d68933SDavid Sterba 350*91d68933SDavid Sterba static struct shash_alg blake2b_algs[] = { 351*91d68933SDavid Sterba { 352*91d68933SDavid Sterba .base.cra_name = "blake2b-160", 353*91d68933SDavid Sterba .base.cra_driver_name = "blake2b-160-generic", 354*91d68933SDavid Sterba .base.cra_priority = 100, 355*91d68933SDavid Sterba .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, 356*91d68933SDavid Sterba .base.cra_blocksize = BLAKE2B_BLOCKBYTES, 357*91d68933SDavid Sterba .base.cra_ctxsize = sizeof(struct digest_tfm_ctx), 358*91d68933SDavid Sterba .base.cra_module = THIS_MODULE, 359*91d68933SDavid Sterba .digestsize = BLAKE2B_160_DIGEST_SIZE, 360*91d68933SDavid Sterba .setkey = digest_setkey, 361*91d68933SDavid Sterba .init = digest_init, 362*91d68933SDavid Sterba .update = digest_update, 363*91d68933SDavid Sterba .final = digest_final, 364*91d68933SDavid Sterba .descsize = sizeof(struct blake2b_state), 365*91d68933SDavid Sterba }, { 366*91d68933SDavid Sterba .base.cra_name = "blake2b-256", 367*91d68933SDavid Sterba .base.cra_driver_name = "blake2b-256-generic", 368*91d68933SDavid Sterba .base.cra_priority = 100, 369*91d68933SDavid Sterba .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, 370*91d68933SDavid Sterba .base.cra_blocksize = BLAKE2B_BLOCKBYTES, 371*91d68933SDavid Sterba .base.cra_ctxsize = sizeof(struct digest_tfm_ctx), 372*91d68933SDavid Sterba .base.cra_module = THIS_MODULE, 373*91d68933SDavid Sterba .digestsize = BLAKE2B_256_DIGEST_SIZE, 374*91d68933SDavid Sterba .setkey = digest_setkey, 375*91d68933SDavid Sterba .init = digest_init, 376*91d68933SDavid Sterba .update = digest_update, 377*91d68933SDavid Sterba .final = digest_final, 378*91d68933SDavid Sterba .descsize = sizeof(struct blake2b_state), 379*91d68933SDavid Sterba }, { 380*91d68933SDavid Sterba .base.cra_name = "blake2b-384", 381*91d68933SDavid Sterba .base.cra_driver_name = "blake2b-384-generic", 382*91d68933SDavid Sterba .base.cra_priority = 100, 383*91d68933SDavid Sterba .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, 384*91d68933SDavid Sterba .base.cra_blocksize = BLAKE2B_BLOCKBYTES, 385*91d68933SDavid Sterba .base.cra_ctxsize = sizeof(struct digest_tfm_ctx), 386*91d68933SDavid Sterba .base.cra_module = THIS_MODULE, 387*91d68933SDavid Sterba .digestsize = BLAKE2B_384_DIGEST_SIZE, 388*91d68933SDavid Sterba .setkey = digest_setkey, 389*91d68933SDavid Sterba .init = digest_init, 390*91d68933SDavid Sterba .update = digest_update, 391*91d68933SDavid Sterba .final = digest_final, 392*91d68933SDavid Sterba .descsize = sizeof(struct blake2b_state), 393*91d68933SDavid Sterba }, { 394*91d68933SDavid Sterba .base.cra_name = "blake2b-512", 395*91d68933SDavid Sterba .base.cra_driver_name = "blake2b-512-generic", 396*91d68933SDavid Sterba .base.cra_priority = 100, 397*91d68933SDavid Sterba .base.cra_flags = CRYPTO_ALG_OPTIONAL_KEY, 398*91d68933SDavid Sterba .base.cra_blocksize = BLAKE2B_BLOCKBYTES, 399*91d68933SDavid Sterba .base.cra_ctxsize = sizeof(struct digest_tfm_ctx), 400*91d68933SDavid Sterba .base.cra_module = THIS_MODULE, 401*91d68933SDavid Sterba .digestsize = BLAKE2B_512_DIGEST_SIZE, 402*91d68933SDavid Sterba .setkey = digest_setkey, 403*91d68933SDavid Sterba .init = digest_init, 404*91d68933SDavid Sterba .update = digest_update, 405*91d68933SDavid Sterba .final = digest_final, 406*91d68933SDavid Sterba .descsize = sizeof(struct blake2b_state), 407*91d68933SDavid Sterba } 408*91d68933SDavid Sterba }; 409*91d68933SDavid Sterba 410*91d68933SDavid Sterba static int __init blake2b_mod_init(void) 411*91d68933SDavid Sterba { 412*91d68933SDavid Sterba BUILD_BUG_ON(sizeof(struct blake2b_param) != BLAKE2B_OUTBYTES); 413*91d68933SDavid Sterba 414*91d68933SDavid Sterba return crypto_register_shashes(blake2b_algs, ARRAY_SIZE(blake2b_algs)); 415*91d68933SDavid Sterba } 416*91d68933SDavid Sterba 417*91d68933SDavid Sterba static void __exit blake2b_mod_fini(void) 418*91d68933SDavid Sterba { 419*91d68933SDavid Sterba crypto_unregister_shashes(blake2b_algs, ARRAY_SIZE(blake2b_algs)); 420*91d68933SDavid Sterba } 421*91d68933SDavid Sterba 422*91d68933SDavid Sterba subsys_initcall(blake2b_mod_init); 423*91d68933SDavid Sterba module_exit(blake2b_mod_fini); 424*91d68933SDavid Sterba 425*91d68933SDavid Sterba MODULE_AUTHOR("David Sterba <kdave@kernel.org>"); 426*91d68933SDavid Sterba MODULE_DESCRIPTION("BLAKE2b generic implementation"); 427*91d68933SDavid Sterba MODULE_LICENSE("GPL"); 428*91d68933SDavid Sterba MODULE_ALIAS_CRYPTO("blake2b-160"); 429*91d68933SDavid Sterba MODULE_ALIAS_CRYPTO("blake2b-160-generic"); 430*91d68933SDavid Sterba MODULE_ALIAS_CRYPTO("blake2b-256"); 431*91d68933SDavid Sterba MODULE_ALIAS_CRYPTO("blake2b-256-generic"); 432*91d68933SDavid Sterba MODULE_ALIAS_CRYPTO("blake2b-384"); 433*91d68933SDavid Sterba MODULE_ALIAS_CRYPTO("blake2b-384-generic"); 434*91d68933SDavid Sterba MODULE_ALIAS_CRYPTO("blake2b-512"); 435*91d68933SDavid Sterba MODULE_ALIAS_CRYPTO("blake2b-512-generic"); 436