18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ciCrypto Engine 48c2ecf20Sopenharmony_ci============= 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ciOverview 78c2ecf20Sopenharmony_ci-------- 88c2ecf20Sopenharmony_ciThe crypto engine (CE) API is a crypto queue manager. 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciRequirement 118c2ecf20Sopenharmony_ci----------- 128c2ecf20Sopenharmony_ciYou must put, at the start of your transform context your_tfm_ctx, the structure 138c2ecf20Sopenharmony_cicrypto_engine: 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci:: 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci struct your_tfm_ctx { 188c2ecf20Sopenharmony_ci struct crypto_engine engine; 198c2ecf20Sopenharmony_ci ... 208c2ecf20Sopenharmony_ci }; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ciThe crypto engine only manages asynchronous requests in the form of 238c2ecf20Sopenharmony_cicrypto_async_request. It cannot know the underlying request type and thus only 248c2ecf20Sopenharmony_cihas access to the transform structure. It is not possible to access the context 258c2ecf20Sopenharmony_ciusing container_of. In addition, the engine knows nothing about your 268c2ecf20Sopenharmony_cistructure "``struct your_tfm_ctx``". The engine assumes (requires) the placement 278c2ecf20Sopenharmony_ciof the known member ``struct crypto_engine`` at the beginning. 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ciOrder of operations 308c2ecf20Sopenharmony_ci------------------- 318c2ecf20Sopenharmony_ciYou are required to obtain a struct crypto_engine via ``crypto_engine_alloc_init()``. 328c2ecf20Sopenharmony_ciStart it via ``crypto_engine_start()``. When finished with your work, shut down the 338c2ecf20Sopenharmony_ciengine using ``crypto_engine_stop()`` and destroy the engine with 348c2ecf20Sopenharmony_ci``crypto_engine_exit()``. 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ciBefore transferring any request, you have to fill the context enginectx by 378c2ecf20Sopenharmony_ciproviding functions for the following: 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci* ``prepare_crypt_hardware``: Called once before any prepare functions are 408c2ecf20Sopenharmony_ci called. 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci* ``unprepare_crypt_hardware``: Called once after all unprepare functions have 438c2ecf20Sopenharmony_ci been called. 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci* ``prepare_cipher_request``/``prepare_hash_request``: Called before each 468c2ecf20Sopenharmony_ci corresponding request is performed. If some processing or other preparatory 478c2ecf20Sopenharmony_ci work is required, do it here. 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci* ``unprepare_cipher_request``/``unprepare_hash_request``: Called after each 508c2ecf20Sopenharmony_ci request is handled. Clean up / undo what was done in the prepare function. 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci* ``cipher_one_request``/``hash_one_request``: Handle the current request by 538c2ecf20Sopenharmony_ci performing the operation. 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ciNote that these functions access the crypto_async_request structure 568c2ecf20Sopenharmony_ciassociated with the received request. You are able to retrieve the original 578c2ecf20Sopenharmony_cirequest by using: 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci:: 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci container_of(areq, struct yourrequesttype_request, base); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciWhen your driver receives a crypto_request, you must to transfer it to 648c2ecf20Sopenharmony_cithe crypto engine via one of: 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci* crypto_transfer_aead_request_to_engine() 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci* crypto_transfer_akcipher_request_to_engine() 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci* crypto_transfer_hash_request_to_engine() 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci* crypto_transfer_skcipher_request_to_engine() 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ciAt the end of the request process, a call to one of the following functions is needed: 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci* crypto_finalize_aead_request() 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci* crypto_finalize_akcipher_request() 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci* crypto_finalize_hash_request() 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci* crypto_finalize_skcipher_request() 83