Commit ea593993 authored by Dmitry Kasatkin's avatar Dmitry Kasatkin Committed by Mimi Zohar

ima: support arbitrary hash algorithms in ima_calc_buffer_hash

ima_calc_buffer_hash will be used with different hash algorithms.
This patch provides support for arbitrary hash algorithms in
ima_calc_buffer_hash.
Signed-off-by: default avatarDmitry Kasatkin <d.kasatkin@samsung.com>
Signed-off-by: default avatarMimi Zohar <zohar@linux.vnet.ibm.com>
parent 723326b9
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/xattr.h> #include <linux/xattr.h>
#include <linux/evm.h> #include <linux/evm.h>
#include <crypto/hash_info.h>
#include "ima.h" #include "ima.h"
static const char *IMA_TEMPLATE_NAME = "ima"; static const char *IMA_TEMPLATE_NAME = "ima";
...@@ -54,6 +55,8 @@ int ima_store_template(struct ima_template_entry *entry, ...@@ -54,6 +55,8 @@ int ima_store_template(struct ima_template_entry *entry,
entry->template_len = sizeof(entry->template); entry->template_len = sizeof(entry->template);
if (!violation) { if (!violation) {
/* this function uses default algo */
hash.hdr.algo = HASH_ALGO_SHA1;
result = ima_calc_buffer_hash(&entry->template, result = ima_calc_buffer_hash(&entry->template,
entry->template_len, &hash.hdr); entry->template_len, &hash.hdr);
if (result < 0) { if (result < 0) {
......
...@@ -139,23 +139,39 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash) ...@@ -139,23 +139,39 @@ int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash)
/* /*
* Calculate the hash of a given buffer * Calculate the hash of a given buffer
*/ */
int ima_calc_buffer_hash(const void *buf, int len, struct ima_digest_data *hash) static int ima_calc_buffer_hash_tfm(const void *buf, int len,
struct ima_digest_data *hash,
struct crypto_shash *tfm)
{ {
struct { struct {
struct shash_desc shash; struct shash_desc shash;
char ctx[crypto_shash_descsize(ima_shash_tfm)]; char ctx[crypto_shash_descsize(tfm)];
} desc; } desc;
desc.shash.tfm = ima_shash_tfm; desc.shash.tfm = tfm;
desc.shash.flags = 0; desc.shash.flags = 0;
/* this function uses default algo */ hash->length = crypto_shash_digestsize(tfm);
hash->algo = ima_hash_algo;
hash->length = crypto_shash_digestsize(ima_shash_tfm);
return crypto_shash_digest(&desc.shash, buf, len, hash->digest); return crypto_shash_digest(&desc.shash, buf, len, hash->digest);
} }
int ima_calc_buffer_hash(const void *buf, int len, struct ima_digest_data *hash)
{
struct crypto_shash *tfm;
int rc;
tfm = ima_alloc_tfm(hash->algo);
if (IS_ERR(tfm))
return PTR_ERR(tfm);
rc = ima_calc_buffer_hash_tfm(buf, len, hash, tfm);
ima_free_tfm(tfm);
return rc;
}
static void __init ima_pcrread(int idx, u8 *pcr) static void __init ima_pcrread(int idx, u8 *pcr)
{ {
if (!ima_used_chip) if (!ima_used_chip)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment