[PATCH 05/16] integrity: Export a function to retrieve hash algo used in digital signature

Vivek Goyal vgoyal at redhat.com
Tue Sep 10 17:44:20 EDT 2013


A function to retrieve hash algo used in digital signature.

Signed-off-by: Vivek Goyal <vgoyal at redhat.com>
---
 security/integrity/digsig.c    | 26 ++++++++++++++++++++++++++
 security/integrity/integrity.h |  7 +++++++
 2 files changed, 33 insertions(+)

diff --git a/security/integrity/digsig.c b/security/integrity/digsig.c
index f1259bd..153cff4 100644
--- a/security/integrity/digsig.c
+++ b/security/integrity/digsig.c
@@ -16,6 +16,8 @@
 #include <linux/rbtree.h>
 #include <linux/key-type.h>
 #include <linux/digsig.h>
+#include <crypto/hash.h>
+#include <crypto/public_key.h>
 
 #include "integrity.h"
 
@@ -27,6 +29,30 @@ static const char *keyring_name[INTEGRITY_KEYRING_MAX] = {
 	"_ima",
 };
 
+int integrity_digsig_get_hash_algo(char *sig)
+{
+	uint8_t hash_algo;
+
+	if (sig[0] == 1) {
+		hash_algo = ((struct signature_hdr *)sig)->hash;
+		switch (hash_algo) {
+		case 0:
+			return PKEY_HASH_SHA1;
+		case 1:
+			return PKEY_HASH_SHA256;
+		default:
+			return -ENOPKG;
+		}
+	} else if (sig[0] == 2 ) {
+		hash_algo = ((struct signature_v2_hdr *)sig)->hash_algo;
+		if (hash_algo >= PKEY_HASH__LAST)
+			return -ENOPKG;
+		return hash_algo;
+	}
+
+	return -EBADMSG;
+}
+
 /* Get size of digital signature */
 int integrity_get_digsig_size(char *sig)
 {
diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h
index 130eb3b..284bb8d 100644
--- a/security/integrity/integrity.h
+++ b/security/integrity/integrity.h
@@ -15,6 +15,7 @@
 #include <linux/integrity.h>
 #include <crypto/sha.h>
 #include <linux/key.h>
+#include <crypto/public_key.h>
 
 /* iint action cache flags */
 #define IMA_MEASURE		0x00000001
@@ -105,8 +106,14 @@ int integrity_digsig_verify_keyring(struct key *keyring, const char *sig,
 			int siglen, const char *digest, int digestlen);
 extern int integrity_get_digsig_size(char *sig);
 
+extern int integrity_digsig_get_hash_algo(char *sig);
 #else
 
+static inline int integrity_digsig_get_hash_algo(char *sig)
+{
+	return -EOPNOTSUPP;
+}
+
 static inline int integrity_digsig_verify(const unsigned int id,
 					  const char *sig, int siglen,
 					  const char *digest, int digestlen)
-- 
1.8.3.1




More information about the kexec mailing list