加密引擎

概述

加密引擎 (CE) API 是一個加密佇列管理器。

要求

您必須在轉換上下文 `your_tfm_ctx` 的開頭放置 `crypto_engine` 結構體。

struct your_tfm_ctx {
        struct crypto_engine engine;
        ...
};

加密引擎僅管理 `crypto_async_request` 形式的非同步請求。它無法知道底層的請求型別,因此只能訪問轉換結構體。無法使用 `container_of` 訪問上下文。此外,引擎對您的結構體 “struct your_tfm_ctx” 一無所知。引擎假定(要求)已知成員 struct crypto_engine 放置在開頭。

操作順序

您需要透過 crypto_engine_alloc_init() 獲取一個 `struct crypto_engine`。透過 crypto_engine_start() 啟動它。完成工作後,使用 crypto_engine_stop() 關閉引擎,並使用 crypto_engine_exit() 銷燬引擎。

在傳輸任何請求之前,您必須透過為以下函式提供實現來填充上下文 `enginectx`:

  • prepare_crypt_hardware:在呼叫任何準備函式之前呼叫一次。

  • unprepare_crypt_hardware:在所有解除準備函式呼叫完畢後呼叫一次。

  • prepare_cipher_request/prepare_hash_request:在執行每個相應請求之前呼叫。如果需要進行一些處理或其他準備工作,請在此處完成。

  • unprepare_cipher_request/unprepare_hash_request:在處理每個請求之後呼叫。清理/撤銷在準備函式中完成的工作。

  • cipher_one_request/hash_one_request:透過執行操作來處理當前請求。

請注意,這些函式訪問與接收到的請求相關聯的 `crypto_async_request` 結構體。您可以使用以下方式檢索原始請求:

container_of(areq, struct yourrequesttype_request, base);

當您的驅動程式收到 `crypto_request` 時,您必須透過以下函式之一將其傳輸到加密引擎:

  • crypto_transfer_aead_request_to_engine()

  • crypto_transfer_akcipher_request_to_engine()

  • crypto_transfer_hash_request_to_engine()

  • crypto_transfer_kpp_request_to_engine()

  • crypto_transfer_skcipher_request_to_engine()

在請求處理結束時,需要呼叫以下函式之一:

  • crypto_finalize_aead_request()

  • crypto_finalize_akcipher_request()

  • crypto_finalize_hash_request()

  • crypto_finalize_kpp_request()

  • crypto_finalize_skcipher_request()