簡體   English   中英

Linux Kernel 加密 API:“crypto_alloc_skcipher”未找到 skcipher 算法名稱

[英]Linux Kernel Crypto API : skcipher algorithm name not found by "crypto_alloc_skcipher"

我正在嘗試使用加密 API 制作 Linux kernel 驅動程序。

所以首先我有我自己開發的 skcipher 算法,它在加密 API 上成功注冊,我可以在注冊良好的密碼列表中看到它。

.base = {

/* Name used by the framework to find who is implementing what. */
    .cra_name = "cbc(aes)stackOverFlow",

/* Driver name. Can be used to request a specific implementation of an algorithm. */
    .cra_driver_name = "stackOverFlow-cbc-aes",

/* Priority is used when implementation auto-selection takes place:
* if there are several implementers, the one with the highest priority is chosen.
* By convention: HW engine > ASM/arch-optimized > plain C 
* */
    .cra_priority = 300,

/* Driver module */
    .cra_module = THIS_MODULE,

/* Size of the data blocks this algo operates on. */
    .cra_blocksize = AES_BLOCK_SIZE,

    .cra_flags = CRYPTO_ALG_INTERNAL | CRYPTO_ALG_TYPE_SKCIPHER,

/* Size of the context attached to an algorithm instance. 
* This value informs the kernel crypto API about the memory size
* needed to be allocated for the transformation context.
*/
    .cra_ctxsize = sizeof(struct crypto_aes_ctx),

/* Alignment mask for the input and output data buffer. */
    .cra_alignmask = 15,
},

/* constructor/destructor methods called every time an alg instance is created/destroyed. */
    .min_keysize = AES_MIN_KEY_SIZE,
    .max_keysize = AES_MAX_KEY_SIZE,
    .ivsize     = AES_BLOCK_SIZE,   

    .init = test_skcipher_cra_init,
    .exit = test_skcipher_cra_exit,

    .setkey = test_aes_setkey,
    .encrypt = test_cbc_aes_encrypt,
    .decrypt = test_cbc_aes_decrypt,


};

這是我的初始化 function 模塊:

static int __init test_skcipher_cra_init(struct crypto_skcipher *tfm){

int ret;

ret = crypto_register_skcipher(&test_cbc_aes_alg);
if (ret < 0){
    printk(KERN_ALERT "register failed %d", ret);
}
    
else{
    printk(KERN_INFO "SUCCESS crypto_register\n");

}

return ret;

}

因此,為了確保我的驅動程序正常工作,我使用實現用戶代碼(我從鏈接獲得)來加密一些數據: https://www.kernel.org/doc/html/v4.17/crypto/api -samples.html

但是,當我編譯所有內容並查看 kernel 日志消息時,我收到一條來自部分實現代碼的錯誤消息“無法分配 skcipher 句柄”

skcipher = crypto_alloc_skcipher("stackOverFlow-cbc-aes", 0, 0);
    if (IS_ERR(skcipher)) {
        pr_info("could not allocate skcipher handle\n");
        return PTR_ERR(skcipher);
    }

但是在crypto API中,我可以看到驅動:

name         : cbc(aes)stackOverFlow
driver       : stackOverFlow-cbc-aes
module       : kernel
priority     : 300
refcnt       : 1
selftest     : passed
internal     : yes
type         : skcipher
async        : no
blocksize    : 16
min keysize  : 16
max keysize  : 32
ivsize       : 16
chunksize    : 16
walksize     : 16

我真的多次嘗試修改算法中的標志和其他內容,但我不明白它一直向我顯示此消息。 所以我的問題是為什么它給了我這個錯誤並且我的加密驅動程序已經在加密 API 上注冊?

請注意,當我將名稱更改為 crypto_alloc_skcipher("cbc-aes-aesni", 0, 0) 這是 API 中已經存在的名稱之一時,一切正常。

我設法解決了這個問題,這是因為初始化算法 function 與初始化 function 模塊混淆的愚蠢錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM