crypto_engine.rst 2.5 KB

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