[RFC][PATCH v3 3/9] crypto: Export signature encoding information

From: Roberto Sassu
Date: Thu Jul 20 2023 - 11:35:18 EST


From: Roberto Sassu <roberto.sassu@xxxxxxxxxx>

Export the signature encoding identifiers, so that user space can reference
them when passing data to the kernel.

Define and export the sig_enc_name array, so that kernel subsystems can get
the string associated to the signature encoding identifier.

Signed-off-by: Roberto Sassu <roberto.sassu@xxxxxxxxxx>
---
crypto/Kconfig | 3 +++
crypto/Makefile | 1 +
crypto/sig_enc_info.c | 16 ++++++++++++++++
include/crypto/sig_enc_info.h | 15 +++++++++++++++
include/uapi/linux/sig_enc_info.h | 18 ++++++++++++++++++
5 files changed, 53 insertions(+)
create mode 100644 crypto/sig_enc_info.c
create mode 100644 include/crypto/sig_enc_info.h
create mode 100644 include/uapi/linux/sig_enc_info.h

diff --git a/crypto/Kconfig b/crypto/Kconfig
index 2558025461b..ef6f1e4c5b4 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -1423,6 +1423,9 @@ config CRYPTO_HASH_INFO
config CRYPTO_PUB_KEY_INFO
bool

+config CRYPTO_SIG_ENC_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 fcdb5918e58..6d84fadfeda 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -207,6 +207,7 @@ 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
+obj-$(CONFIG_CRYPTO_SIG_ENC_INFO) += sig_enc_info.o
crypto_simd-y := simd.o
obj-$(CONFIG_CRYPTO_SIMD) += crypto_simd.o

diff --git a/crypto/sig_enc_info.c b/crypto/sig_enc_info.c
new file mode 100644
index 00000000000..649cf98385f
--- /dev/null
+++ b/crypto/sig_enc_info.c
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 Huawei Technologies Duesseldorf GmbH
+ *
+ * Sig enc info: Signature encoding information
+ */
+
+#include <linux/export.h>
+#include <crypto/sig_enc_info.h>
+
+const char *const sig_enc_name[SIG_ENC__LAST] = {
+ [SIG_ENC_PKCS1] = "pkcs1",
+ [SIG_ENC_X962] = "x962",
+ [SIG_ENC_RAW] = "raw",
+};
+EXPORT_SYMBOL_GPL(sig_enc_name);
diff --git a/include/crypto/sig_enc_info.h b/include/crypto/sig_enc_info.h
new file mode 100644
index 00000000000..6e28890a0e4
--- /dev/null
+++ b/include/crypto/sig_enc_info.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2023 Huawei Technologies Duesseldorf GmbH
+ *
+ * Sig enc info: Signature encoding information
+ */
+
+#ifndef _CRYPTO_SIG_ENC_INFO_H
+#define _CRYPTO_SIG_ENC_INFO_H
+
+#include <uapi/linux/sig_enc_info.h>
+
+extern const char *const sig_enc_name[SIG_ENC__LAST];
+
+#endif /* _CRYPTO_SIG_ENC_INFO_H */
diff --git a/include/uapi/linux/sig_enc_info.h b/include/uapi/linux/sig_enc_info.h
new file mode 100644
index 00000000000..0a2ac028bef
--- /dev/null
+++ b/include/uapi/linux/sig_enc_info.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2023 Huawei Technologies Duesseldorf GmbH
+ *
+ * Sig enc info: Signature encoding information
+ */
+
+#ifndef _UAPI_LINUX_SIG_ENC_INFO_H
+#define _UAPI_LINUX_SIG_ENC_INFO_H
+
+enum sig_enc_info {
+ SIG_ENC_PKCS1,
+ SIG_ENC_X962,
+ SIG_ENC_RAW,
+ SIG_ENC__LAST,
+};
+
+#endif /* _UAPI_LINUX_SIG_ENC_INFO_H */
--
2.34.1