]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - linux/crypto/sha256_generic.c
Move c_src dirs back to toplevel
[bcachefs-tools-debian] / linux / crypto / sha256_generic.c
index 0bd272f0eed3b7c75058d935c182a9f75134dc41..9326bfe7eabdc3a35cbe180c3394529a0a77115b 100644 (file)
 #include <asm/unaligned.h>
 
 #include <linux/crypto.h>
-#include <crypto/internal/hash.h>
+#include <crypto/hash.h>
 
 #include <sodium/crypto_hash_sha256.h>
 
+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)))