From ebbfc41ad6ba1f381b86ea8286e71f476b01cdfb Mon Sep 17 00:00:00 2001 From: Vitaly Chikunov Date: Sat, 23 Mar 2019 04:41:52 +0300 Subject: [PATCH] ima-evm-utils: try to load digest by its alias Primary names of the algorithms are different for OpenSSL and Kernel. "Streebog" is a name of the hash algorithm in the Kernel Crypto API. "md_gost12_X" is the name used by most versions of OpenSSL, it's placed in pkey_hash_algo[] so that algo IDs are resolved to them. Allow to use both names. Signed-off-by: Vitaly Chikunov [zohar@linux.ibm.com: updated patch description based input from Vitaly] Signed-off-by: Mimi Zohar --- src/libimaevm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libimaevm.c b/src/libimaevm.c index bc7be1e..6783110 100644 --- a/src/libimaevm.c +++ b/src/libimaevm.c @@ -61,6 +61,7 @@ #include "imaevm.h" #include "hash_info.h" +/* Names that are primary for OpenSSL. */ const char *const pkey_hash_algo[PKEY_HASH__LAST] = { [PKEY_HASH_MD4] = "md4", [PKEY_HASH_MD5] = "md5", @@ -70,6 +71,12 @@ const char *const pkey_hash_algo[PKEY_HASH__LAST] = { [PKEY_HASH_SHA384] = "sha384", [PKEY_HASH_SHA512] = "sha512", [PKEY_HASH_SHA224] = "sha224", + [PKEY_HASH_STREEBOG_256] = "md_gost12_256", + [PKEY_HASH_STREEBOG_512] = "md_gost12_512", +}; + +/* Names that are primary for the kernel. */ +const char *const pkey_hash_algo_kern[PKEY_HASH__LAST] = { [PKEY_HASH_STREEBOG_256] = "streebog256", [PKEY_HASH_STREEBOG_512] = "streebog512", }; @@ -551,6 +558,11 @@ int get_hash_algo(const char *algo) !strcmp(algo, pkey_hash_algo[i])) return i; + for (i = 0; i < PKEY_HASH__LAST; i++) + if (pkey_hash_algo_kern[i] && + !strcmp(algo, pkey_hash_algo_kern[i])) + return i; + /* iterate over algorithms provided by kernel-headers */ for (i = 0; i < HASH_ALGO__LAST; i++) if (hash_algo_name[i] &&