1#include <crypto/hash.h>
2#include <linux/crypto.h>
5#include <linux/string.h>
18 struct crypto_shash *tfm;
19 struct shash_desc *shash;
23 if (!input || !digest)
27 tfm = crypto_alloc_shash(
"sha256", 0, 0);
29 pr_err(
"Erreur allocation tfm SHA-256\n");
34 desc_size =
sizeof(
struct shash_desc) + crypto_shash_descsize(tfm);
35 desc_buffer = kmalloc(desc_size, GFP_KERNEL);
37 crypto_free_shash(tfm);
41 shash = (
struct shash_desc *)desc_buffer;
45 ret = crypto_shash_digest(shash, input, strlen(input), digest);
48 crypto_free_shash(tfm);
77 if (!digest || !output) {
78 pr_err(
"hash_to_str: digest or output NULL\n");
84 sprintf(output + (i * 2),
"%02x", digest[i]);
#define SHA256_DIGEST_SIZE
bool are_hash_equals(const u8 *h1, const u8 *h2)
Compares two SHA-256 hashes for equality.
int hash_string(const char *input, u8 *digest)
Hashes a string using SHA-256.
void hash_to_str(const u8 *digest, char *output)
Converts a SHA-256 hash to a hexadecimal string.