1 /* SPDX-License-Identifier: GPL-2.0-or-later * << 2 /* 1 /* 3 * Crypto engine API 2 * Crypto engine API 4 * 3 * 5 * Copyright (c) 2016 Baolin Wang <baolin.wang 4 * Copyright (c) 2016 Baolin Wang <baolin.wang@linaro.org> >> 5 * >> 6 * This program is free software; you can redistribute it and/or modify it >> 7 * under the terms of the GNU General Public License as published by the Free >> 8 * Software Foundation; either version 2 of the License, or (at your option) >> 9 * any later version. >> 10 * 6 */ 11 */ 7 #ifndef _CRYPTO_ENGINE_H 12 #ifndef _CRYPTO_ENGINE_H 8 #define _CRYPTO_ENGINE_H 13 #define _CRYPTO_ENGINE_H 9 14 10 #include <crypto/aead.h> !! 15 #include <linux/crypto.h> 11 #include <crypto/akcipher.h> !! 16 #include <linux/list.h> >> 17 #include <linux/kernel.h> >> 18 #include <linux/kthread.h> >> 19 #include <crypto/algapi.h> 12 #include <crypto/hash.h> 20 #include <crypto/hash.h> 13 #include <crypto/kpp.h> << 14 #include <crypto/skcipher.h> << 15 #include <linux/types.h> << 16 << 17 struct crypto_engine; << 18 struct device; << 19 21 >> 22 #define ENGINE_NAME_LEN 30 20 /* 23 /* 21 * struct crypto_engine_op - crypto hardware e !! 24 * struct crypto_engine - crypto hardware engine 22 * @do_one_request: do encryption for current !! 25 * @name: the engine name >> 26 * @idling: the engine is entering idle state >> 27 * @busy: request pump is busy >> 28 * @running: the engine is on working >> 29 * @cur_req_prepared: current request is prepared >> 30 * @list: link with the global crypto engine list >> 31 * @queue_lock: spinlock to syncronise access to request queue >> 32 * @queue: the crypto queue of the engine >> 33 * @rt: whether this queue is set to run as a realtime task >> 34 * @prepare_crypt_hardware: a request will soon arrive from the queue >> 35 * so the subsystem requests the driver to prepare the hardware >> 36 * by issuing this call >> 37 * @unprepare_crypt_hardware: there are currently no more requests on the >> 38 * queue so the subsystem notifies the driver that it may relax the >> 39 * hardware by issuing this call >> 40 * @prepare_cipher_request: do some prepare if need before handle the current request >> 41 * @unprepare_cipher_request: undo any work done by prepare_cipher_request() >> 42 * @cipher_one_request: do encryption for current request >> 43 * @prepare_hash_request: do some prepare if need before handle the current request >> 44 * @unprepare_hash_request: undo any work done by prepare_hash_request() >> 45 * @hash_one_request: do hash for current request >> 46 * @kworker: kthread worker struct for request pump >> 47 * @pump_requests: work struct for scheduling work to the request pump >> 48 * @priv_data: the engine private data >> 49 * @cur_req: the current request which is on processing 23 */ 50 */ 24 struct crypto_engine_op { !! 51 struct crypto_engine { 25 int (*do_one_request)(struct crypto_en !! 52 char name[ENGINE_NAME_LEN]; 26 void *areq); !! 53 bool idling; 27 }; !! 54 bool busy; 28 !! 55 bool running; 29 struct aead_engine_alg { !! 56 bool cur_req_prepared; 30 struct aead_alg base; !! 57 31 struct crypto_engine_op op; !! 58 struct list_head list; 32 }; !! 59 spinlock_t queue_lock; 33 !! 60 struct crypto_queue queue; 34 struct ahash_engine_alg { !! 61 struct device *dev; 35 struct ahash_alg base; !! 62 36 struct crypto_engine_op op; !! 63 bool rt; 37 }; !! 64 38 !! 65 int (*prepare_crypt_hardware)(struct crypto_engine *engine); 39 struct akcipher_engine_alg { !! 66 int (*unprepare_crypt_hardware)(struct crypto_engine *engine); 40 struct akcipher_alg base; !! 67 41 struct crypto_engine_op op; !! 68 int (*prepare_cipher_request)(struct crypto_engine *engine, 42 }; !! 69 struct ablkcipher_request *req); 43 !! 70 int (*unprepare_cipher_request)(struct crypto_engine *engine, 44 struct kpp_engine_alg { !! 71 struct ablkcipher_request *req); 45 struct kpp_alg base; !! 72 int (*prepare_hash_request)(struct crypto_engine *engine, 46 struct crypto_engine_op op; !! 73 struct ahash_request *req); 47 }; !! 74 int (*unprepare_hash_request)(struct crypto_engine *engine, 48 !! 75 struct ahash_request *req); 49 struct skcipher_engine_alg { !! 76 int (*cipher_one_request)(struct crypto_engine *engine, 50 struct skcipher_alg base; !! 77 struct ablkcipher_request *req); 51 struct crypto_engine_op op; !! 78 int (*hash_one_request)(struct crypto_engine *engine, 52 }; !! 79 struct ahash_request *req); 53 !! 80 54 int crypto_transfer_aead_request_to_engine(str !! 81 struct kthread_worker *kworker; 55 str !! 82 struct kthread_work pump_requests; 56 int crypto_transfer_akcipher_request_to_engine !! 83 57 !! 84 void *priv_data; >> 85 struct crypto_async_request *cur_req; >> 86 }; >> 87 >> 88 int crypto_transfer_cipher_request(struct crypto_engine *engine, >> 89 struct ablkcipher_request *req, >> 90 bool need_pump); >> 91 int crypto_transfer_cipher_request_to_engine(struct crypto_engine *engine, >> 92 struct ablkcipher_request *req); >> 93 int crypto_transfer_hash_request(struct crypto_engine *engine, >> 94 struct ahash_request *req, bool need_pump); 58 int crypto_transfer_hash_request_to_engine(str 95 int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine, 59 !! 96 struct ahash_request *req); 60 int crypto_transfer_kpp_request_to_engine(stru !! 97 void crypto_finalize_cipher_request(struct crypto_engine *engine, 61 stru !! 98 struct ablkcipher_request *req, int err); 62 int crypto_transfer_skcipher_request_to_engine << 63 << 64 void crypto_finalize_aead_request(struct crypt << 65 struct aead_ << 66 void crypto_finalize_akcipher_request(struct c << 67 struct a << 68 void crypto_finalize_hash_request(struct crypt 99 void crypto_finalize_hash_request(struct crypto_engine *engine, 69 struct ahash 100 struct ahash_request *req, int err); 70 void crypto_finalize_kpp_request(struct crypto << 71 struct kpp_re << 72 void crypto_finalize_skcipher_request(struct c << 73 struct s << 74 int crypto_engine_start(struct crypto_engine * 101 int crypto_engine_start(struct crypto_engine *engine); 75 int crypto_engine_stop(struct crypto_engine *e 102 int crypto_engine_stop(struct crypto_engine *engine); 76 struct crypto_engine *crypto_engine_alloc_init 103 struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt); 77 struct crypto_engine *crypto_engine_alloc_init !! 104 int crypto_engine_exit(struct crypto_engine *engine); 78 << 79 << 80 << 81 void crypto_engine_exit(struct crypto_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 105 107 #endif /* _CRYPTO_ENGINE_H */ 106 #endif /* _CRYPTO_ENGINE_H */ 108 107
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.