summaryrefslogtreecommitdiff
path: root/linux/crypto/sha256_generic.c
diff options
context:
space:
mode:
Diffstat (limited to 'linux/crypto/sha256_generic.c')
-rw-r--r--linux/crypto/sha256_generic.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/linux/crypto/sha256_generic.c b/linux/crypto/sha256_generic.c
index 0bd272f0..9326bfe7 100644
--- a/linux/crypto/sha256_generic.c
+++ b/linux/crypto/sha256_generic.c
@@ -24,13 +24,15 @@
#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)))