blob: d562ea17d99411b196e3e04e75b9424fc26e4f94 [file] [log] [blame]
Hook, Garyae400be2019-06-25 23:43:50 +00001.. SPDX-License-Identifier: GPL-2.0
Jonathan Neuschäfer5d2ded22019-08-08 18:30:11 +02002
Hook, Garyae400be2019-06-25 23:43:50 +00003Crypto Engine
Corentin LABBEce09a6c2018-01-26 20:15:29 +01004=============
5
6Overview
7--------
Hook, Garyae400be2019-06-25 23:43:50 +00008The crypto engine (CE) API is a crypto queue manager.
Corentin LABBEce09a6c2018-01-26 20:15:29 +01009
10Requirement
11-----------
Hook, Garyae400be2019-06-25 23:43:50 +000012You must put, at the start of your transform context your_tfm_ctx, the structure
13crypto_engine:
Mauro Carvalho Chehab2fab3012018-05-06 14:30:09 -030014
Hook, Garyae400be2019-06-25 23:43:50 +000015::
Mauro Carvalho Chehab2fab3012018-05-06 14:30:09 -030016
Hook, Garyae400be2019-06-25 23:43:50 +000017 struct your_tfm_ctx {
18 struct crypto_engine engine;
19 ...
20 };
21
22The crypto engine only manages asynchronous requests in the form of
23crypto_async_request. It cannot know the underlying request type and thus only
24has access to the transform structure. It is not possible to access the context
25using container_of. In addition, the engine knows nothing about your
26structure "``struct your_tfm_ctx``". The engine assumes (requires) the placement
27of the known member ``struct crypto_engine`` at the beginning.
Corentin LABBEce09a6c2018-01-26 20:15:29 +010028
29Order of operations
30-------------------
Hook, Garyae400be2019-06-25 23:43:50 +000031You are required to obtain a struct crypto_engine via ``crypto_engine_alloc_init()``.
32Start it via ``crypto_engine_start()``. When finished with your work, shut down the
33engine using ``crypto_engine_stop()`` and destroy the engine with
34``crypto_engine_exit()``.
Corentin LABBEce09a6c2018-01-26 20:15:29 +010035
Hook, Garyae400be2019-06-25 23:43:50 +000036Before transferring any request, you have to fill the context enginectx by
37providing functions for the following:
Corentin LABBEce09a6c2018-01-26 20:15:29 +010038
Hook, Garyae400be2019-06-25 23:43:50 +000039* ``prepare_crypt_hardware``: Called once before any prepare functions are
40 called.
Corentin LABBEce09a6c2018-01-26 20:15:29 +010041
Hook, Garyae400be2019-06-25 23:43:50 +000042* ``unprepare_crypt_hardware``: Called once after all unprepare functions have
43 been called.
Corentin LABBEce09a6c2018-01-26 20:15:29 +010044
Hook, Garyae400be2019-06-25 23:43:50 +000045* ``prepare_cipher_request``/``prepare_hash_request``: Called before each
46 corresponding request is performed. If some processing or other preparatory
47 work is required, do it here.
48
49* ``unprepare_cipher_request``/``unprepare_hash_request``: Called after each
50 request is handled. Clean up / undo what was done in the prepare function.
51
52* ``cipher_one_request``/``hash_one_request``: Handle the current request by
53 performing the operation.
54
55Note that these functions access the crypto_async_request structure
56associated with the received request. You are able to retrieve the original
57request by using:
58
59::
60
61 container_of(areq, struct yourrequesttype_request, base);
62
63When your driver receives a crypto_request, you must to transfer it to
64the crypto engine via one of:
65
Hook, Garyae400be2019-06-25 23:43:50 +000066* crypto_transfer_aead_request_to_engine()
67
68* crypto_transfer_akcipher_request_to_engine()
69
70* crypto_transfer_hash_request_to_engine()
71
Prabhjot Khurana1730c5a2021-10-20 11:35:34 +010072* crypto_transfer_kpp_request_to_engine()
73
Hook, Garyae400be2019-06-25 23:43:50 +000074* crypto_transfer_skcipher_request_to_engine()
75
76At the end of the request process, a call to one of the following functions is needed:
77
Hook, Garyae400be2019-06-25 23:43:50 +000078* crypto_finalize_aead_request()
79
80* crypto_finalize_akcipher_request()
81
82* crypto_finalize_hash_request()
83
Prabhjot Khurana1730c5a2021-10-20 11:35:34 +010084* crypto_finalize_kpp_request()
85
Hook, Garyae400be2019-06-25 23:43:50 +000086* crypto_finalize_skcipher_request()