18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Cryptographic API. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 68c2ecf20Sopenharmony_ci * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci#ifndef _CRYPTO_INTERNAL_H 98c2ecf20Sopenharmony_ci#define _CRYPTO_INTERNAL_H 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ci#include <crypto/algapi.h> 128c2ecf20Sopenharmony_ci#include <linux/completion.h> 138c2ecf20Sopenharmony_ci#include <linux/list.h> 148c2ecf20Sopenharmony_ci#include <linux/module.h> 158c2ecf20Sopenharmony_ci#include <linux/notifier.h> 168c2ecf20Sopenharmony_ci#include <linux/numa.h> 178c2ecf20Sopenharmony_ci#include <linux/refcount.h> 188c2ecf20Sopenharmony_ci#include <linux/rwsem.h> 198c2ecf20Sopenharmony_ci#include <linux/sched.h> 208c2ecf20Sopenharmony_ci#include <linux/types.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistruct crypto_instance; 238c2ecf20Sopenharmony_cistruct crypto_template; 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistruct crypto_larval { 268c2ecf20Sopenharmony_ci struct crypto_alg alg; 278c2ecf20Sopenharmony_ci struct crypto_alg *adult; 288c2ecf20Sopenharmony_ci struct completion completion; 298c2ecf20Sopenharmony_ci u32 mask; 308c2ecf20Sopenharmony_ci}; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ciextern struct list_head crypto_alg_list; 338c2ecf20Sopenharmony_ciextern struct rw_semaphore crypto_alg_sem; 348c2ecf20Sopenharmony_ciextern struct blocking_notifier_head crypto_chain; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#ifdef CONFIG_PROC_FS 378c2ecf20Sopenharmony_civoid __init crypto_init_proc(void); 388c2ecf20Sopenharmony_civoid __exit crypto_exit_proc(void); 398c2ecf20Sopenharmony_ci#else 408c2ecf20Sopenharmony_cistatic inline void crypto_init_proc(void) 418c2ecf20Sopenharmony_ci{ } 428c2ecf20Sopenharmony_cistatic inline void crypto_exit_proc(void) 438c2ecf20Sopenharmony_ci{ } 448c2ecf20Sopenharmony_ci#endif 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic inline unsigned int crypto_cipher_ctxsize(struct crypto_alg *alg) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci return alg->cra_ctxsize; 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistatic inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg) 528c2ecf20Sopenharmony_ci{ 538c2ecf20Sopenharmony_ci return alg->cra_ctxsize; 548c2ecf20Sopenharmony_ci} 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistruct crypto_alg *crypto_mod_get(struct crypto_alg *alg); 578c2ecf20Sopenharmony_cistruct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistruct crypto_larval *crypto_larval_alloc(const char *name, u32 type, u32 mask); 608c2ecf20Sopenharmony_civoid crypto_larval_kill(struct crypto_alg *alg); 618c2ecf20Sopenharmony_civoid crypto_alg_tested(const char *name, int err); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_civoid crypto_remove_spawns(struct crypto_alg *alg, struct list_head *list, 648c2ecf20Sopenharmony_ci struct crypto_alg *nalg); 658c2ecf20Sopenharmony_civoid crypto_remove_final(struct list_head *list); 668c2ecf20Sopenharmony_civoid crypto_shoot_alg(struct crypto_alg *alg); 678c2ecf20Sopenharmony_cistruct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, 688c2ecf20Sopenharmony_ci u32 mask); 698c2ecf20Sopenharmony_civoid *crypto_create_tfm_node(struct crypto_alg *alg, 708c2ecf20Sopenharmony_ci const struct crypto_type *frontend, int node); 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic inline void *crypto_create_tfm(struct crypto_alg *alg, 738c2ecf20Sopenharmony_ci const struct crypto_type *frontend) 748c2ecf20Sopenharmony_ci{ 758c2ecf20Sopenharmony_ci return crypto_create_tfm_node(alg, frontend, NUMA_NO_NODE); 768c2ecf20Sopenharmony_ci} 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistruct crypto_alg *crypto_find_alg(const char *alg_name, 798c2ecf20Sopenharmony_ci const struct crypto_type *frontend, 808c2ecf20Sopenharmony_ci u32 type, u32 mask); 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_civoid *crypto_alloc_tfm_node(const char *alg_name, 838c2ecf20Sopenharmony_ci const struct crypto_type *frontend, u32 type, u32 mask, 848c2ecf20Sopenharmony_ci int node); 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistatic inline void *crypto_alloc_tfm(const char *alg_name, 878c2ecf20Sopenharmony_ci const struct crypto_type *frontend, u32 type, u32 mask) 888c2ecf20Sopenharmony_ci{ 898c2ecf20Sopenharmony_ci return crypto_alloc_tfm_node(alg_name, frontend, type, mask, NUMA_NO_NODE); 908c2ecf20Sopenharmony_ci} 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ciint crypto_probing_notify(unsigned long val, void *v); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ciunsigned int crypto_alg_extsize(struct crypto_alg *alg); 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ciint crypto_type_has_alg(const char *name, const struct crypto_type *frontend, 978c2ecf20Sopenharmony_ci u32 type, u32 mask); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_cistatic inline struct crypto_alg *crypto_alg_get(struct crypto_alg *alg) 1008c2ecf20Sopenharmony_ci{ 1018c2ecf20Sopenharmony_ci refcount_inc(&alg->cra_refcnt); 1028c2ecf20Sopenharmony_ci return alg; 1038c2ecf20Sopenharmony_ci} 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_cistatic inline void crypto_alg_put(struct crypto_alg *alg) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci if (refcount_dec_and_test(&alg->cra_refcnt) && alg->cra_destroy) 1088c2ecf20Sopenharmony_ci alg->cra_destroy(alg); 1098c2ecf20Sopenharmony_ci} 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_cistatic inline int crypto_tmpl_get(struct crypto_template *tmpl) 1128c2ecf20Sopenharmony_ci{ 1138c2ecf20Sopenharmony_ci return try_module_get(tmpl->module); 1148c2ecf20Sopenharmony_ci} 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cistatic inline void crypto_tmpl_put(struct crypto_template *tmpl) 1178c2ecf20Sopenharmony_ci{ 1188c2ecf20Sopenharmony_ci module_put(tmpl->module); 1198c2ecf20Sopenharmony_ci} 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_cistatic inline int crypto_is_larval(struct crypto_alg *alg) 1228c2ecf20Sopenharmony_ci{ 1238c2ecf20Sopenharmony_ci return alg->cra_flags & CRYPTO_ALG_LARVAL; 1248c2ecf20Sopenharmony_ci} 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_cistatic inline int crypto_is_dead(struct crypto_alg *alg) 1278c2ecf20Sopenharmony_ci{ 1288c2ecf20Sopenharmony_ci return alg->cra_flags & CRYPTO_ALG_DEAD; 1298c2ecf20Sopenharmony_ci} 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_cistatic inline int crypto_is_moribund(struct crypto_alg *alg) 1328c2ecf20Sopenharmony_ci{ 1338c2ecf20Sopenharmony_ci return alg->cra_flags & (CRYPTO_ALG_DEAD | CRYPTO_ALG_DYING); 1348c2ecf20Sopenharmony_ci} 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_cistatic inline void crypto_notify(unsigned long val, void *v) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci blocking_notifier_call_chain(&crypto_chain, val, v); 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistatic inline void crypto_yield(u32 flags) 1428c2ecf20Sopenharmony_ci{ 1438c2ecf20Sopenharmony_ci if (flags & CRYPTO_TFM_REQ_MAY_SLEEP) 1448c2ecf20Sopenharmony_ci cond_resched(); 1458c2ecf20Sopenharmony_ci} 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci#endif /* _CRYPTO_INTERNAL_H */ 1488c2ecf20Sopenharmony_ci 149