1 /* SPDX-License-Identifier: GPL-2.0-or-later * 1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* 2 /* 3 * Crypto engine API 3 * Crypto engine API 4 * 4 * 5 * Copyright (c) 2016 Baolin Wang <baolin.wang 5 * Copyright (c) 2016 Baolin Wang <baolin.wang@linaro.org> 6 */ 6 */ 7 #ifndef _CRYPTO_ENGINE_H 7 #ifndef _CRYPTO_ENGINE_H 8 #define _CRYPTO_ENGINE_H 8 #define _CRYPTO_ENGINE_H 9 9 >> 10 #include <linux/crypto.h> >> 11 #include <linux/list.h> >> 12 #include <linux/kthread.h> >> 13 #include <linux/spinlock.h> >> 14 #include <linux/types.h> >> 15 >> 16 #include <crypto/algapi.h> 10 #include <crypto/aead.h> 17 #include <crypto/aead.h> 11 #include <crypto/akcipher.h> 18 #include <crypto/akcipher.h> 12 #include <crypto/hash.h> 19 #include <crypto/hash.h> 13 #include <crypto/kpp.h> << 14 #include <crypto/skcipher.h> 20 #include <crypto/skcipher.h> 15 #include <linux/types.h> !! 21 #include <crypto/kpp.h> 16 22 17 struct crypto_engine; << 18 struct device; 23 struct device; 19 24 >> 25 #define ENGINE_NAME_LEN 30 20 /* 26 /* 21 * struct crypto_engine_op - crypto hardware e !! 27 * struct crypto_engine - crypto hardware engine 22 * @do_one_request: do encryption for current !! 28 * @name: the engine name >> 29 * @idling: the engine is entering idle state >> 30 * @busy: request pump is busy >> 31 * @running: the engine is on working >> 32 * @retry_support: indication that the hardware allows re-execution >> 33 * of a failed backlog request >> 34 * crypto-engine, in head position to keep order >> 35 * @list: link with the global crypto engine list >> 36 * @queue_lock: spinlock to synchronise access to request queue >> 37 * @queue: the crypto queue of the engine >> 38 * @rt: whether this queue is set to run as a realtime task >> 39 * @prepare_crypt_hardware: a request will soon arrive from the queue >> 40 * so the subsystem requests the driver to prepare the hardware >> 41 * by issuing this call >> 42 * @unprepare_crypt_hardware: there are currently no more requests on the >> 43 * queue so the subsystem notifies the driver that it may relax the >> 44 * hardware by issuing this call >> 45 * @do_batch_requests: execute a batch of requests. Depends on multiple >> 46 * requests support. >> 47 * @kworker: kthread worker struct for request pump >> 48 * @pump_requests: work struct for scheduling work to the request pump >> 49 * @priv_data: the engine private data >> 50 * @cur_req: the current request which is on processing 23 */ 51 */ 24 struct crypto_engine_op { !! 52 struct crypto_engine { 25 int (*do_one_request)(struct crypto_en !! 53 char name[ENGINE_NAME_LEN]; 26 void *areq); !! 54 bool idling; 27 }; !! 55 bool busy; >> 56 bool running; 28 57 29 struct aead_engine_alg { !! 58 bool retry_support; 30 struct aead_alg base; << 31 struct crypto_engine_op op; << 32 }; << 33 59 34 struct ahash_engine_alg { !! 60 struct list_head list; 35 struct ahash_alg base; !! 61 spinlock_t queue_lock; 36 struct crypto_engine_op op; !! 62 struct crypto_queue queue; 37 }; !! 63 struct device *dev; 38 64 39 struct akcipher_engine_alg { !! 65 bool rt; 40 struct akcipher_alg base; !! 66 41 struct crypto_engine_op op; !! 67 int (*prepare_crypt_hardware)(struct crypto_engine *engine); >> 68 int (*unprepare_crypt_hardware)(struct crypto_engine *engine); >> 69 int (*do_batch_requests)(struct crypto_engine *engine); >> 70 >> 71 >> 72 struct kthread_worker *kworker; >> 73 struct kthread_work pump_requests; >> 74 >> 75 void *priv_data; >> 76 struct crypto_async_request *cur_req; 42 }; 77 }; 43 78 44 struct kpp_engine_alg { !! 79 /* 45 struct kpp_alg base; !! 80 * struct crypto_engine_op - crypto hardware engine operations 46 struct crypto_engine_op op; !! 81 * @prepare_request: do some preparation if needed before handling the current request >> 82 * @unprepare_request: undo any work done by prepare_request() >> 83 * @do_one_request: do encryption for current request >> 84 */ >> 85 struct crypto_engine_op { >> 86 int (*prepare_request)(struct crypto_engine *engine, >> 87 void *areq); >> 88 int (*unprepare_request)(struct crypto_engine *engine, >> 89 void *areq); >> 90 int (*do_one_request)(struct crypto_engine *engine, >> 91 void *areq); 47 }; 92 }; 48 93 49 struct skcipher_engine_alg { !! 94 struct crypto_engine_ctx { 50 struct skcipher_alg base; << 51 struct crypto_engine_op op; 95 struct crypto_engine_op op; 52 }; 96 }; 53 97 54 int crypto_transfer_aead_request_to_engine(str 98 int crypto_transfer_aead_request_to_engine(struct crypto_engine *engine, 55 str 99 struct aead_request *req); 56 int crypto_transfer_akcipher_request_to_engine 100 int crypto_transfer_akcipher_request_to_engine(struct crypto_engine *engine, 57 101 struct akcipher_request *req); 58 int crypto_transfer_hash_request_to_engine(str 102 int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine, 59 103 struct ahash_request *req); 60 int crypto_transfer_kpp_request_to_engine(stru 104 int crypto_transfer_kpp_request_to_engine(struct crypto_engine *engine, 61 stru 105 struct kpp_request *req); 62 int crypto_transfer_skcipher_request_to_engine 106 int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine, 63 107 struct skcipher_request *req); 64 void crypto_finalize_aead_request(struct crypt 108 void crypto_finalize_aead_request(struct crypto_engine *engine, 65 struct aead_ 109 struct aead_request *req, int err); 66 void crypto_finalize_akcipher_request(struct c 110 void crypto_finalize_akcipher_request(struct crypto_engine *engine, 67 struct a 111 struct akcipher_request *req, int err); 68 void crypto_finalize_hash_request(struct crypt 112 void crypto_finalize_hash_request(struct crypto_engine *engine, 69 struct ahash 113 struct ahash_request *req, int err); 70 void crypto_finalize_kpp_request(struct crypto 114 void crypto_finalize_kpp_request(struct crypto_engine *engine, 71 struct kpp_re 115 struct kpp_request *req, int err); 72 void crypto_finalize_skcipher_request(struct c 116 void crypto_finalize_skcipher_request(struct crypto_engine *engine, 73 struct s 117 struct skcipher_request *req, int err); 74 int crypto_engine_start(struct crypto_engine * 118 int crypto_engine_start(struct crypto_engine *engine); 75 int crypto_engine_stop(struct crypto_engine *e 119 int crypto_engine_stop(struct crypto_engine *engine); 76 struct crypto_engine *crypto_engine_alloc_init 120 struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt); 77 struct crypto_engine *crypto_engine_alloc_init 121 struct crypto_engine *crypto_engine_alloc_init_and_set(struct device *dev, 78 122 bool retry_support, 79 123 int (*cbk_do_batch)(struct crypto_engine *engine), 80 124 bool rt, int qlen); 81 void crypto_engine_exit(struct crypto_engine * !! 125 int crypto_engine_exit(struct crypto_engine *engine); 82 << 83 int crypto_engine_register_aead(struct aead_en << 84 void crypto_engine_unregister_aead(struct aead << 85 int crypto_engine_register_aeads(struct aead_e << 86 void crypto_engine_unregister_aeads(struct aea << 87 << 88 int crypto_engine_register_ahash(struct ahash_ << 89 void crypto_engine_unregister_ahash(struct aha << 90 int crypto_engine_register_ahashes(struct ahas << 91 void crypto_engine_unregister_ahashes(struct a << 92 int coun << 93 << 94 int crypto_engine_register_akcipher(struct akc << 95 void crypto_engine_unregister_akcipher(struct << 96 << 97 int crypto_engine_register_kpp(struct kpp_engi << 98 void crypto_engine_unregister_kpp(struct kpp_e << 99 << 100 int crypto_engine_register_skcipher(struct skc << 101 void crypto_engine_unregister_skcipher(struct << 102 int crypto_engine_register_skciphers(struct sk << 103 int count << 104 void crypto_engine_unregister_skciphers(struct << 105 int co << 106 126 107 #endif /* _CRYPTO_ENGINE_H */ 127 #endif /* _CRYPTO_ENGINE_H */ 108 128
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.