Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 Crypto Engine
0004 =============
0005 
0006 Overview
0007 --------
0008 The crypto engine (CE) API is a crypto queue manager.
0009 
0010 Requirement
0011 -----------
0012 You must put, at the start of your transform context your_tfm_ctx, the structure
0013 crypto_engine:
0014 
0015 ::
0016 
0017         struct your_tfm_ctx {
0018                 struct crypto_engine engine;
0019                 ...
0020         };
0021 
0022 The crypto engine only manages asynchronous requests in the form of
0023 crypto_async_request. It cannot know the underlying request type and thus only
0024 has access to the transform structure. It is not possible to access the context
0025 using container_of. In addition, the engine knows nothing about your
0026 structure "``struct your_tfm_ctx``". The engine assumes (requires) the placement
0027 of the known member ``struct crypto_engine`` at the beginning.
0028 
0029 Order of operations
0030 -------------------
0031 You are required to obtain a struct crypto_engine via ``crypto_engine_alloc_init()``.
0032 Start it via ``crypto_engine_start()``. When finished with your work, shut down the
0033 engine using ``crypto_engine_stop()`` and destroy the engine with
0034 ``crypto_engine_exit()``.
0035 
0036 Before transferring any request, you have to fill the context enginectx by
0037 providing functions for the following:
0038 
0039 * ``prepare_crypt_hardware``: Called once before any prepare functions are
0040   called.
0041 
0042 * ``unprepare_crypt_hardware``: Called once after all unprepare functions have
0043   been called.
0044 
0045 * ``prepare_cipher_request``/``prepare_hash_request``: Called before each
0046   corresponding request is performed. If some processing or other preparatory
0047   work is required, do it here.
0048 
0049 * ``unprepare_cipher_request``/``unprepare_hash_request``: Called after each
0050   request is handled. Clean up / undo what was done in the prepare function.
0051 
0052 * ``cipher_one_request``/``hash_one_request``: Handle the current request by
0053   performing the operation.
0054 
0055 Note that these functions access the crypto_async_request structure
0056 associated with the received request. You are able to retrieve the original
0057 request by using:
0058 
0059 ::
0060 
0061         container_of(areq, struct yourrequesttype_request, base);
0062 
0063 When your driver receives a crypto_request, you must to transfer it to
0064 the crypto engine via one of:
0065 
0066 * crypto_transfer_aead_request_to_engine()
0067 
0068 * crypto_transfer_akcipher_request_to_engine()
0069 
0070 * crypto_transfer_hash_request_to_engine()
0071 
0072 * crypto_transfer_kpp_request_to_engine()
0073 
0074 * crypto_transfer_skcipher_request_to_engine()
0075 
0076 At the end of the request process, a call to one of the following functions is needed:
0077 
0078 * crypto_finalize_aead_request()
0079 
0080 * crypto_finalize_akcipher_request()
0081 
0082 * crypto_finalize_hash_request()
0083 
0084 * crypto_finalize_kpp_request()
0085 
0086 * crypto_finalize_skcipher_request()