@@ -62,36 +62,33 @@ MODULE_PARM_DESC(ahash_bufsize, "Maximum ahash buffer size");
static struct crypto_shash *ima_shash_tfm;
static struct crypto_ahash *ima_ahash_tfm;
-int __init ima_init_crypto(void)
+static int ima_alloc_shash(struct crypto_shash **tfm, const char *alg_name)
{
long rc;
- ima_shash_tfm = crypto_alloc_shash(hash_algo_name[ima_hash_algo], 0, 0);
- if (IS_ERR(ima_shash_tfm)) {
- rc = PTR_ERR(ima_shash_tfm);
- pr_err("Can not allocate %s (reason: %ld)\n",
- hash_algo_name[ima_hash_algo], rc);
+ *tfm = crypto_alloc_shash(alg_name, 0, 0);
+ if (IS_ERR(*tfm)) {
+ rc = PTR_ERR(*tfm);
+ pr_err("Can not allocate %s (reason: %ld)\n", alg_name, rc);
return rc;
}
return 0;
}
+int __init ima_init_crypto(void)
+{
+ return ima_alloc_shash(&ima_shash_tfm, hash_algo_name[ima_hash_algo]);
+}
+
static struct crypto_shash *ima_alloc_tfm(enum hash_algo algo)
{
struct crypto_shash *tfm = ima_shash_tfm;
- int rc;
if (algo < 0 || algo >= HASH_ALGO__LAST)
algo = ima_hash_algo;
- if (algo != ima_hash_algo) {
- tfm = crypto_alloc_shash(hash_algo_name[algo], 0, 0);
- if (IS_ERR(tfm)) {
- rc = PTR_ERR(tfm);
- pr_err("Can not allocate %s (reason: %d)\n",
- hash_algo_name[algo], rc);
- }
- }
+ if (algo != ima_hash_algo)
+ ima_alloc_shash(&tfm, hash_algo_name[algo]);
return tfm;
}
This is preparation for next commit. Signed-off-by: Petr Vorel <pvorel@suse.cz> --- security/integrity/ima/ima_crypto.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-)