crypto_engine.rst 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_cipher_request``/``prepare_hash_request``: Called before each
  31. corresponding request is performed. If some processing or other preparatory
  32. work is required, do it here.
  33. * ``unprepare_cipher_request``/``unprepare_hash_request``: Called after each
  34. request is handled. Clean up / undo what was done in the prepare function.
  35. * ``cipher_one_request``/``hash_one_request``: Handle the current request by
  36. performing the operation.
  37. Note that these functions access the crypto_async_request structure
  38. associated with the received request. You are able to retrieve the original
  39. request by using:
  40. ::
  41. container_of(areq, struct yourrequesttype_request, base);
  42. When your driver receives a crypto_request, you must to transfer it to
  43. the crypto engine via one of:
  44. * crypto_transfer_aead_request_to_engine()
  45. * crypto_transfer_akcipher_request_to_engine()
  46. * crypto_transfer_hash_request_to_engine()
  47. * crypto_transfer_kpp_request_to_engine()
  48. * crypto_transfer_skcipher_request_to_engine()
  49. At the end of the request process, a call to one of the following functions is needed:
  50. * crypto_finalize_aead_request()
  51. * crypto_finalize_akcipher_request()
  52. * crypto_finalize_hash_request()
  53. * crypto_finalize_kpp_request()
  54. * crypto_finalize_skcipher_request()