[RFC,01/10] crypto: Export public key algorithm information
Commit Message
From: Roberto Sassu <roberto.sassu@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@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
@@ -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"
@@ -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
new file mode 100644
@@ -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);
new file mode 100644
@@ -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 */
new file mode 100644
@@ -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 */