Hook, Gary | ae400be | 2019-06-25 23:43:50 +0000 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0 |
| 2 | Crypto Engine |
Corentin LABBE | ce09a6c | 2018-01-26 20:15:29 +0100 | [diff] [blame] | 3 | ============= |
| 4 | |
| 5 | Overview |
| 6 | -------- |
Hook, Gary | ae400be | 2019-06-25 23:43:50 +0000 | [diff] [blame] | 7 | The crypto engine (CE) API is a crypto queue manager. |
Corentin LABBE | ce09a6c | 2018-01-26 20:15:29 +0100 | [diff] [blame] | 8 | |
| 9 | Requirement |
| 10 | ----------- |
Hook, Gary | ae400be | 2019-06-25 23:43:50 +0000 | [diff] [blame] | 11 | You must put, at the start of your transform context your_tfm_ctx, the structure |
| 12 | crypto_engine: |
Mauro Carvalho Chehab | 2fab301 | 2018-05-06 14:30:09 -0300 | [diff] [blame] | 13 | |
Hook, Gary | ae400be | 2019-06-25 23:43:50 +0000 | [diff] [blame] | 14 | :: |
Mauro Carvalho Chehab | 2fab301 | 2018-05-06 14:30:09 -0300 | [diff] [blame] | 15 | |
Hook, Gary | ae400be | 2019-06-25 23:43:50 +0000 | [diff] [blame] | 16 | struct your_tfm_ctx { |
| 17 | struct crypto_engine engine; |
| 18 | ... |
| 19 | }; |
| 20 | |
| 21 | The crypto engine only manages asynchronous requests in the form of |
| 22 | crypto_async_request. It cannot know the underlying request type and thus only |
| 23 | has access to the transform structure. It is not possible to access the context |
| 24 | using container_of. In addition, the engine knows nothing about your |
| 25 | structure "``struct your_tfm_ctx``". The engine assumes (requires) the placement |
| 26 | of the known member ``struct crypto_engine`` at the beginning. |
Corentin LABBE | ce09a6c | 2018-01-26 20:15:29 +0100 | [diff] [blame] | 27 | |
| 28 | Order of operations |
| 29 | ------------------- |
Hook, Gary | ae400be | 2019-06-25 23:43:50 +0000 | [diff] [blame] | 30 | You are required to obtain a struct crypto_engine via ``crypto_engine_alloc_init()``. |
| 31 | Start it via ``crypto_engine_start()``. When finished with your work, shut down the |
| 32 | engine using ``crypto_engine_stop()`` and destroy the engine with |
| 33 | ``crypto_engine_exit()``. |
Corentin LABBE | ce09a6c | 2018-01-26 20:15:29 +0100 | [diff] [blame] | 34 | |
Hook, Gary | ae400be | 2019-06-25 23:43:50 +0000 | [diff] [blame] | 35 | Before transferring any request, you have to fill the context enginectx by |
| 36 | providing functions for the following: |
Corentin LABBE | ce09a6c | 2018-01-26 20:15:29 +0100 | [diff] [blame] | 37 | |
Hook, Gary | ae400be | 2019-06-25 23:43:50 +0000 | [diff] [blame] | 38 | * ``prepare_crypt_hardware``: Called once before any prepare functions are |
| 39 | called. |
Corentin LABBE | ce09a6c | 2018-01-26 20:15:29 +0100 | [diff] [blame] | 40 | |
Hook, Gary | ae400be | 2019-06-25 23:43:50 +0000 | [diff] [blame] | 41 | * ``unprepare_crypt_hardware``: Called once after all unprepare functions have |
| 42 | been called. |
Corentin LABBE | ce09a6c | 2018-01-26 20:15:29 +0100 | [diff] [blame] | 43 | |
Hook, Gary | ae400be | 2019-06-25 23:43:50 +0000 | [diff] [blame] | 44 | * ``prepare_cipher_request``/``prepare_hash_request``: Called before each |
| 45 | corresponding request is performed. If some processing or other preparatory |
| 46 | work is required, do it here. |
| 47 | |
| 48 | * ``unprepare_cipher_request``/``unprepare_hash_request``: Called after each |
| 49 | request is handled. Clean up / undo what was done in the prepare function. |
| 50 | |
| 51 | * ``cipher_one_request``/``hash_one_request``: Handle the current request by |
| 52 | performing the operation. |
| 53 | |
| 54 | Note that these functions access the crypto_async_request structure |
| 55 | associated with the received request. You are able to retrieve the original |
| 56 | request by using: |
| 57 | |
| 58 | :: |
| 59 | |
| 60 | container_of(areq, struct yourrequesttype_request, base); |
| 61 | |
| 62 | When your driver receives a crypto_request, you must to transfer it to |
| 63 | the crypto engine via one of: |
| 64 | |
| 65 | * crypto_transfer_ablkcipher_request_to_engine() |
| 66 | |
| 67 | * crypto_transfer_aead_request_to_engine() |
| 68 | |
| 69 | * crypto_transfer_akcipher_request_to_engine() |
| 70 | |
| 71 | * crypto_transfer_hash_request_to_engine() |
| 72 | |
| 73 | * crypto_transfer_skcipher_request_to_engine() |
| 74 | |
| 75 | At the end of the request process, a call to one of the following functions is needed: |
| 76 | |
| 77 | * crypto_finalize_ablkcipher_request() |
| 78 | |
| 79 | * crypto_finalize_aead_request() |
| 80 | |
| 81 | * crypto_finalize_akcipher_request() |
| 82 | |
| 83 | * crypto_finalize_hash_request() |
| 84 | |
| 85 | * crypto_finalize_skcipher_request() |