The name sm3-256 is defined in hash_algo_name in hash_info, but the algorithm name implemented in sm3_generic.c is sm3, which will cause the sm3-256 algorithm to be not found in some application scenarios of the hash algorithm, and an ENOENT error will occur. For example, IMA, keys, and other subsystems that reference hash_algo_name cannot use the hash algorithm of sm3. This patch adds an alias name sm3-256 to sm3, which can better solve the above problems. Signed-off-by: Tianjia Zhang <tianjia.zhang@xxxxxxxxxxxxxxxxx> --- crypto/sm3_generic.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/crypto/sm3_generic.c b/crypto/sm3_generic.c index 3468975215ca..ded41031bd5f 100644 --- a/crypto/sm3_generic.c +++ b/crypto/sm3_generic.c @@ -163,7 +163,7 @@ int crypto_sm3_finup(struct shash_desc *desc, const u8 *data, } EXPORT_SYMBOL(crypto_sm3_finup); -static struct shash_alg sm3_alg = { +static struct shash_alg sm3_algs[2] = { { .digestsize = SM3_DIGEST_SIZE, .init = sm3_base_init, .update = crypto_sm3_update, @@ -176,16 +176,28 @@ static struct shash_alg sm3_alg = { .cra_blocksize = SM3_BLOCK_SIZE, .cra_module = THIS_MODULE, } -}; +}, { + .digestsize = SM3_DIGEST_SIZE, + .init = sm3_base_init, + .update = crypto_sm3_update, + .final = sm3_final, + .finup = crypto_sm3_finup, + .descsize = sizeof(struct sm3_state), + .base = { + .cra_name = "sm3-256", + .cra_blocksize = SM3_BLOCK_SIZE, + .cra_module = THIS_MODULE, + } +} }; static int __init sm3_generic_mod_init(void) { - return crypto_register_shash(&sm3_alg); + return crypto_register_shashes(sm3_algs, ARRAY_SIZE(sm3_algs)); } static void __exit sm3_generic_mod_fini(void) { - crypto_unregister_shash(&sm3_alg); + crypto_unregister_shashes(sm3_algs, ARRAY_SIZE(sm3_algs)); } subsys_initcall(sm3_generic_mod_init); @@ -196,3 +208,4 @@ MODULE_DESCRIPTION("SM3 Secure Hash Algorithm"); MODULE_ALIAS_CRYPTO("sm3"); MODULE_ALIAS_CRYPTO("sm3-generic"); +MODULE_ALIAS_CRYPTO("sm3-256"); -- 2.17.1