summaryrefslogtreecommitdiffstats
path: root/crypto/sm3.c
diff options
context:
space:
mode:
authorJoel Fernandes <joelagnelf@nvidia.com>2026-07-18 13:15:36 -0400
committerPaul E. McKenney <paulmck@kernel.org>2026-07-23 10:39:57 -0700
commit34ff636f322c6d5e4f0a52338fa63a7dff09a495 (patch)
tree7629759c1ec7148b95bc8ab3080df20a5ecd2273 /crypto/sm3.c
downloadlinux-stable-34ff636f322c6d5e4f0a52338fa63a7dff09a495.tar.gz
linux-stable-34ff636f322c6d5e4f0a52338fa63a7dff09a495.zip
scftorture: Count single_rpc offline failures in statistics outputgrafted
scf_torture_stats_print() aggregates each invoker thread's counters into a local scf_statistics structure before printing, but the n_single_rpc_ofl field is missing from the aggregation loop. As a result, the "single_rpc_ofl" value printed in the statistics line is always zero, even when smp_call_function_single() invocations for the RPC test have failed due to offline CPUs and been counted by the invoker threads. Add the missing accumulation so that the printed value reflects the actual counts. Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Diffstat (limited to 'crypto/sm3.c')
-rw-r--r--crypto/sm3.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/crypto/sm3.c b/crypto/sm3.c
new file mode 100644
index 000000000..05111a99b
--- /dev/null
+++ b/crypto/sm3.c
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * SM3 secure hash, as specified by OSCCA GM/T 0004-2012 SM3 and
+ * described at https://tools.ietf.org/html/draft-shen-sm3-hash-01
+ *
+ * Copyright (C) 2017 ARM Limited or its affiliates.
+ * Written by Gilad Ben-Yossef <gilad@benyossef.com>
+ * Copyright (C) 2021 Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
+ * Copyright 2026 Google LLC
+ */
+
+#include <crypto/internal/hash.h>
+#include <crypto/sm3.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+#define SM3_CTX(desc) ((struct sm3_ctx *)shash_desc_ctx(desc))
+
+static int crypto_sm3_init(struct shash_desc *desc)
+{
+ sm3_init(SM3_CTX(desc));
+ return 0;
+}
+
+static int crypto_sm3_update(struct shash_desc *desc,
+ const u8 *data, unsigned int len)
+{
+ sm3_update(SM3_CTX(desc), data, len);
+ return 0;
+}
+
+static int crypto_sm3_final(struct shash_desc *desc, u8 *out)
+{
+ sm3_final(SM3_CTX(desc), out);
+ return 0;
+}
+
+static int crypto_sm3_digest(struct shash_desc *desc,
+ const u8 *data, unsigned int len, u8 *out)
+{
+ sm3(data, len, out);
+ return 0;
+}
+
+static int crypto_sm3_export_core(struct shash_desc *desc, void *out)
+{
+ memcpy(out, SM3_CTX(desc), sizeof(struct sm3_ctx));
+ return 0;
+}
+
+static int crypto_sm3_import_core(struct shash_desc *desc, const void *in)
+{
+ memcpy(SM3_CTX(desc), in, sizeof(struct sm3_ctx));
+ return 0;
+}
+
+static struct shash_alg sm3_alg = {
+ .base.cra_name = "sm3",
+ .base.cra_driver_name = "sm3-lib",
+ .base.cra_priority = 300,
+ .base.cra_blocksize = SM3_BLOCK_SIZE,
+ .base.cra_module = THIS_MODULE,
+ .digestsize = SM3_DIGEST_SIZE,
+ .init = crypto_sm3_init,
+ .update = crypto_sm3_update,
+ .final = crypto_sm3_final,
+ .digest = crypto_sm3_digest,
+ .export_core = crypto_sm3_export_core,
+ .import_core = crypto_sm3_import_core,
+ .descsize = sizeof(struct sm3_ctx),
+};
+
+static int __init crypto_sm3_mod_init(void)
+{
+ return crypto_register_shash(&sm3_alg);
+}
+module_init(crypto_sm3_mod_init);
+
+static void __exit crypto_sm3_mod_exit(void)
+{
+ crypto_unregister_shash(&sm3_alg);
+}
+module_exit(crypto_sm3_mod_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Crypto API support for SM3");
+
+MODULE_ALIAS_CRYPTO("sm3");
+MODULE_ALIAS_CRYPTO("sm3-lib");