X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=linux%2Fcrypto%2Fsha256_generic.c;h=9326bfe7eabdc3a35cbe180c3394529a0a77115b;hb=b5fd066153c40a70a29caa1ea7987723ab687763;hp=0bd272f0eed3b7c75058d935c182a9f75134dc41;hpb=a5b5eba7f788bb77cf57f9c94f3474a2d439ab0b;p=bcachefs-tools-debian diff --git a/linux/crypto/sha256_generic.c b/linux/crypto/sha256_generic.c index 0bd272f..9326bfe 100644 --- a/linux/crypto/sha256_generic.c +++ b/linux/crypto/sha256_generic.c @@ -24,13 +24,15 @@ #include #include -#include +#include #include +static struct shash_alg sha256_alg; + static int sha256_init(struct shash_desc *desc) { - crypto_hash_sha256_state *state = shash_desc_ctx(desc); + crypto_hash_sha256_state *state = (void *) desc->ctx; return crypto_hash_sha256_init(state); } @@ -38,28 +40,38 @@ static int sha256_init(struct shash_desc *desc) static int sha256_update(struct shash_desc *desc, const u8 *data, unsigned int len) { - crypto_hash_sha256_state *state = shash_desc_ctx(desc); + crypto_hash_sha256_state *state = (void *) desc->ctx; return crypto_hash_sha256_update(state, data, len); } static int sha256_final(struct shash_desc *desc, u8 *out) { - crypto_hash_sha256_state *state = shash_desc_ctx(desc); + crypto_hash_sha256_state *state = (void *) desc->ctx; return crypto_hash_sha256_final(state, out); } +static void *sha256_alloc_tfm(void) +{ + struct crypto_shash *tfm = kzalloc(sizeof(*tfm), GFP_KERNEL); + + if (!tfm) + return NULL; + + tfm->base.alg = &sha256_alg.base; + tfm->descsize = sizeof(crypto_hash_sha256_state); + return tfm; +} + static struct shash_alg sha256_alg = { .digestsize = crypto_hash_sha256_BYTES, .init = sha256_init, .update = sha256_update, .final = sha256_final, .descsize = sizeof(crypto_hash_sha256_state), - .base = { - .cra_name = "sha256", - .cra_flags = CRYPTO_ALG_TYPE_SHASH, - } + .base.cra_name = "sha256", + .base.alloc_tfm = sha256_alloc_tfm, }; __attribute__((constructor(110)))