非對稱密碼演算法定義

struct akcipher_request

公鑰密碼請求

定義:

struct akcipher_request {
    struct crypto_async_request base;
    struct scatterlist *src;
    struct scatterlist *dst;
    unsigned int src_len;
    unsigned int dst_len;
    void *__ctx[] ;
};

成員

base

非同步加密請求的通用屬性

src

源資料

dst

目標資料

src_len

輸入緩衝區的大小

dst_len

dst 緩衝區的大小。它需要至少與預期的結果一樣大,具體取決於操作。 操作完成後,它將使用結果的實際大小進行更新。 如果發生錯誤,其中 dst sgl 大小不足,它將更新為操作所需的大小。

__ctx

私有上下文資料的開始

struct akcipher_alg

通用公鑰密碼演算法

定義:

struct akcipher_alg {
    int (*encrypt)(struct akcipher_request *req);
    int (*decrypt)(struct akcipher_request *req);
    int (*set_pub_key)(struct crypto_akcipher *tfm, const void *key, unsigned int keylen);
    int (*set_priv_key)(struct crypto_akcipher *tfm, const void *key, unsigned int keylen);
    unsigned int (*max_size)(struct crypto_akcipher *tfm);
    int (*init)(struct crypto_akcipher *tfm);
    void (*exit)(struct crypto_akcipher *tfm);
    struct crypto_alg base;
};

成員

encrypt

函式執行由公鑰演算法定義的加密操作。 如果發生錯誤,其中 dst_len 不足,req->dst_len 將更新為操作所需的大小

decrypt

函式執行由公鑰演算法定義的解密操作。 如果發生錯誤,其中 dst_len 不足,req->dst_len 將更新為操作所需的大小

set_pub_key

函式呼叫演算法特定的設定公鑰函式,該函式知道如何解碼和解釋 BER 編碼的公鑰和引數

set_priv_key

函式呼叫演算法特定的設定私鑰函式,該函式知道如何解碼和解釋 BER 編碼的私鑰和引數

max_size

函式返回給定金鑰所需的目標緩衝區大小。

init

初始化加密轉換物件。 此函式用於初始化加密轉換物件。 此函式僅在例項化時呼叫一次,就在轉換上下文分配之後。 如果加密硬體有一些特殊的軟體處理要求,此函式應檢查轉換的精確要求,並將任何軟體回退放在適當的位置。

exit

取消初始化加密轉換物件。 這是 init 的對應項,用於刪除在 init 中設定的各種更改。

base

通用加密 API 演算法資料結構

非對稱密碼 API

公鑰密碼 API 與 CRYPTO_ALG_TYPE_AKCIPHER 型別的演算法一起使用(在 /proc/crypto 中列為“akcipher”型別)

struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type, u32 mask)

分配 AKCIPHER tfm 控制代碼

引數

const char *alg_name

是公鑰演算法的 cra_name / name 或 cra_driver_name / 驅動程式名稱,例如“rsa”

u32 type

指定演算法的型別

u32 mask

指定演算法的掩碼

描述

為公鑰演算法分配一個控制代碼。 返回的 struct crypto_akcipher 是公鑰操作的任何後續 API 呼叫所需的控制代碼。

返回

成功時分配的控制代碼; 如果 IS_ERR() 為真

出錯,PTR_ERR() 返回錯誤程式碼。

void crypto_free_akcipher(struct crypto_akcipher *tfm)

釋放 AKCIPHER tfm 控制代碼

引數

struct crypto_akcipher *tfm

使用 crypto_alloc_akcipher() 分配的 AKCIPHER tfm 控制代碼

描述

如果 tfm 是 NULL 或錯誤指標,此函式不執行任何操作。

unsigned int crypto_akcipher_maxsize(struct crypto_akcipher *tfm)

獲取輸出緩衝區的長度

引數

struct crypto_akcipher *tfm

使用 crypto_alloc_akcipher() 分配的 AKCIPHER tfm 控制代碼

描述

函式返回給定金鑰所需的目標緩衝區大小。 函式假定金鑰已在轉換中設定。 如果在沒有 setkey 或 setkey 失敗的情況下呼叫此函式,您將最終得到 NULL 指標解引用。

int crypto_akcipher_encrypt(struct akcipher_request *req)

呼叫公鑰加密操作

引數

struct akcipher_request *req

非對稱金鑰請求

描述

函式為給定的公鑰演算法呼叫特定的公鑰加密操作

返回

成功時為零; 出錯時為錯誤程式碼

int crypto_akcipher_decrypt(struct akcipher_request *req)

呼叫公鑰解密操作

引數

struct akcipher_request *req

非對稱金鑰請求

描述

函式為給定的公鑰演算法呼叫特定的公鑰解密操作

返回

成功時為零; 出錯時為錯誤程式碼

int crypto_akcipher_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen)

呼叫設定公鑰操作

引數

struct crypto_akcipher *tfm

tfm 控制代碼

const void *key

BER 編碼的公鑰、演算法 OID、paramlen、BER 編碼的引數

unsigned int keylen

金鑰的長度(不包括其他資料)

描述

函式呼叫演算法特定的設定金鑰函式,該函式知道如何解碼和解釋編碼的金鑰和引數

返回

成功時為零; 出錯時為錯誤程式碼

int crypto_akcipher_set_priv_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen)

呼叫設定私鑰操作

引數

struct crypto_akcipher *tfm

tfm 控制代碼

const void *key

BER 編碼的私鑰、演算法 OID、paramlen、BER 編碼的引數

unsigned int keylen

金鑰的長度(不包括其他資料)

描述

函式呼叫演算法特定的設定金鑰函式,該函式知道如何解碼和解釋編碼的金鑰和引數

返回

成功時為零; 出錯時為錯誤程式碼

非對稱密碼請求控制代碼

struct akcipher_request *akcipher_request_alloc(struct crypto_akcipher *tfm, gfp_t gfp)

分配公鑰請求

引數

struct crypto_akcipher *tfm

使用 crypto_alloc_akcipher() 分配的 AKCIPHER tfm 控制代碼

gfp_t gfp

分配標誌

返回

成功時分配的控制代碼,出錯時為 NULL。

void akcipher_request_free(struct akcipher_request *req)

清零並釋放公鑰請求

引數

struct akcipher_request *req

要釋放的請求

void akcipher_request_set_callback(struct akcipher_request *req, u32 flgs, crypto_completion_t cmpl, void *data)

設定非同步回撥。

引數

struct akcipher_request *req

將為其設定回撥的請求

u32 flgs

指定例項,如果操作可能積壓

crypto_completion_t cmpl

將被呼叫的回撥

void *data

呼叫者使用的私有資料

描述

當給定請求的非同步操作完成時,將呼叫回撥。

void akcipher_request_set_crypt(struct akcipher_request *req, struct scatterlist *src, struct scatterlist *dst, unsigned int src_len, unsigned int dst_len)

設定請求引數

引數

struct akcipher_request *req

公鑰請求

struct scatterlist *src

指向輸入散列表的指標

struct scatterlist *dst

指向輸出散列表的指標

unsigned int src_len

要處理的 src 輸入散列表的大小

unsigned int dst_len

dst 輸出散列表的大小

描述

設定加密操作所需的引數