[RFC][PATCH v3 2/9] crypto: Export public key algorithm information

Roberto Sassu roberto.sassu at huaweicloud.com
Thu Jul 20 15:32:38 UTC 2023


From: Roberto Sassu <roberto.sassu at huawei.com>

Export the public keys algorithm identifiers, so that user space can
reference them when passing data to the kernel.

Define and export the pub_key_algo_name array, so that kernel subsystems
can get the string associated to the public key algorithm identifier.

Signed-off-by: Roberto Sassu <roberto.sassu at huawei.com>
---
 crypto/Kconfig                    |  3 +++
 crypto/Makefile                   |  1 +
 crypto/pub_key_info.c             | 20 ++++++++++++++++++++
 include/crypto/pub_key_info.h     | 15 +++++++++++++++
 include/uapi/linux/pub_key_info.h | 22 ++++++++++++++++++++++
 5 files changed, 61 insertions(+)
 create mode 100644 crypto/pub_key_info.c
 create mode 100644 include/crypto/pub_key_info.h
 create mode 100644 include/uapi/linux/pub_key_info.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index 650b1b3620d..2558025461b 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1420,6 +1420,9 @@ endmenu
 config CRYPTO_HASH_INFO
 	bool
 
+config CRYPTO_PUB_KEY_INFO
+	bool
+
 if !KMSAN # avoid false positives from assembly
 if ARM
 source "arch/arm/crypto/Kconfig"
diff --git a/crypto/Makefile b/crypto/Makefile
index 953a7e105e5..fcdb5918e58 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -206,6 +206,7 @@ obj-$(CONFIG_XOR_BLOCKS) += xor.o
 obj-$(CONFIG_ASYNC_CORE) += async_tx/
 obj-$(CONFIG_ASYMMETRIC_KEY_TYPE) += asymmetric_keys/
 obj-$(CONFIG_CRYPTO_HASH_INFO) += hash_info.o
+obj-$(CONFIG_CRYPTO_PUB_KEY_INFO) += pub_key_info.o
 crypto_simd-y := simd.o
 obj-$(CONFIG_CRYPTO_SIMD) += crypto_simd.o
 
diff --git a/crypto/pub_key_info.c b/crypto/pub_key_info.c
new file mode 100644
index 00000000000..d12a08e5972
--- /dev/null
+++ b/crypto/pub_key_info.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 Huawei Technologies Duesseldorf GmbH
+ *
+ * Public key info: Public key algorithms information
+ */
+
+#include <linux/export.h>
+#include <crypto/pub_key_info.h>
+
+const char *const pub_key_algo_name[PKEY_ALGO__LAST] = {
+	[PKEY_ALGO_RSA]		= "rsa",
+	[PKEY_ALGO_ECDSA]	= "ecdsa",
+	[PKEY_ALGO_ECDSA_P192]	= "ecdsa-nist-p192",
+	[PKEY_ALGO_ECDSA_P256]	= "ecdsa-nist-p256",
+	[PKEY_ALGO_ECDSA_P384]	= "ecdsa-nist-p384",
+	[PKEY_ALGO_ECRDSA]	= "ecrdsa",
+	[PKEY_ALGO_SM2]		= "sm2",
+};
+EXPORT_SYMBOL_GPL(pub_key_algo_name);
diff --git a/include/crypto/pub_key_info.h b/include/crypto/pub_key_info.h
new file mode 100644
index 00000000000..ea411792778
--- /dev/null
+++ b/include/crypto/pub_key_info.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2023 Huawei Technologies Duesseldorf GmbH
+ *
+ * Public key info: Public key algorithms information
+ */
+
+#ifndef _CRYPTO_PUB_KEY_INFO_H
+#define _CRYPTO_PUB_KEY_INFO_H
+
+#include <uapi/linux/pub_key_info.h>
+
+extern const char *const pub_key_algo_name[PKEY_ALGO__LAST];
+
+#endif /* _CRYPTO_PUB_KEY_INFO_H */
diff --git a/include/uapi/linux/pub_key_info.h b/include/uapi/linux/pub_key_info.h
new file mode 100644
index 00000000000..a5595969156
--- /dev/null
+++ b/include/uapi/linux/pub_key_info.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2023 Huawei Technologies Duesseldorf GmbH
+ *
+ * Public key info: Public key algorithms information
+ */
+
+#ifndef _UAPI_LINUX_PUB_KEY_INFO_H
+#define _UAPI_LINUX_PUB_KEY_INFO_H
+
+enum pub_key_algo {
+	PKEY_ALGO_RSA,
+	PKEY_ALGO_ECDSA,
+	PKEY_ALGO_ECDSA_P192,
+	PKEY_ALGO_ECDSA_P256,
+	PKEY_ALGO_ECDSA_P384,
+	PKEY_ALGO_ECRDSA,
+	PKEY_ALGO_SM2,
+	PKEY_ALGO__LAST,
+};
+
+#endif /* _UAPI_LINUX_PUB_KEY_INFO_H */
-- 
2.34.1



More information about the Linux-security-module-archive mailing list