// SPDX-License-Identifier: GPL-2.0-or-later/* * Cryptographic API for algorithms (i.e., low-level API). * * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au> */#include<crypto/algapi.h>#include<linux/err.h>#include<linux/errno.h>#include<linux/fips.h>#include<linux/init.h>#include<linux/kernel.h>#include<linux/list.h>#include<linux/module.h>#include<linux/rtnetlink.h>#include<linux/slab.h>#include<linux/string.h>#include"internal.h"staticLIST_HEAD(crypto_template_list);staticinlinevoidcrypto_check_module_sig(structmodule*mod){if(fips_enabled&&mod&&!module_sig_ok(mod))panic("Module %s signature verification failed in FIPS mode\n",module_name(mod));}staticintcrypto_check_alg(structcrypto_alg*alg){crypto_check_module_sig(alg->cra_module);if(!alg->cra_name[0]||!alg->cra_driver_name[0])return-EINVAL;if(alg->cra_alignmask&(alg->cra_alignmask+1))return-EINVAL;/* General maximums for all algs. */if(alg->cra_alignmask>MAX_ALGAPI_ALIGNMASK)return-EINVAL;if(alg->cra_blocksize>MAX_ALGAPI_BLOCKSIZE)return-EINVAL;/* Lower maximums for specific alg types. */if(!alg->cra_type&&(alg->cra_flags&CRYPTO_ALG_TYPE_MASK)==CRYPTO_ALG_TYPE_CIPHER){if(alg->cra_alignmask>MAX_CIPHER_ALIGNMASK)return-EINVAL;if(alg->cra_blocksize>MAX_CIPHER_BLOCKSIZE)return-EINVAL;}if(alg->cra_priority<0)return-EINVAL;refcount_set(&alg->cra_refcnt,1);return0;}staticvoidcrypto_free_instance(structcrypto_instance*inst){if(!inst->alg.cra_type->free){inst->tmpl->free(inst);return;}inst->alg.cra_type->free(inst);}staticvoidcrypto_destroy_instance(structcrypto_alg*alg){structcrypto_instance*inst=(void*)alg;structcrypto_template*tmpl=inst->tmpl;crypto_free_instance(inst);crypto_tmpl_put(tmpl);}/* * This function adds a spawn to the list secondary_spawns which