我已經試過了,解密工作正常。這裏是我的代碼:
struct crypto_cipher *tfm;
int i;
u8 pkey[32] ={0xc1,0xb2,0x33,0x34,5,6,7,8,9,0xa,0xb,0xc,0xd,0xe,0xf,0x11,
0xc3,0xb4,0x32,0x34,5,6,7,8,9,0xa,0xb,0xc1,0xd,0xe1,0xf2,0x12};
u8 dest[32];
u8 dest2[32];
u8 src[32]= {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,30,31,32,33,34,35,36,37,38,39,40,51,52};
tfm = crypto_alloc_cipher("aes", 4, CRYPTO_ALG_ASYNC);
crypto_cipher_setkey(tfm, pkey, 32);
crypto_cipher_encrypt_one(tfm, dest, src);
crypto_cipher_encrypt_one(tfm, &dest[16], &src[16]);
crypto_cipher_decrypt_one(tfm, dest2, dest);
crypto_cipher_decrypt_one(tfm, &dest2[16], &dest[16]);
for (i=0; i<32; i++)
{
pr_info("%x ", dest2[i]);
}
crypto_free_cipher(tfm);
的printk的結果是預期和dest2陣列只是同SRC陣列。
你傳遞給alloc-cipher的參數是什麼? (主要關心的是,如果你把它放入使用IV的東西,可能需要一直設置,如果你沒有設置它,它會使用內存中的任何值,每次調用都會有所不同) – Foon
即時傳遞3個參數給crypto_alloc_cipher, 1.算法名稱 2. U32型和 3. U32掩模 如crypto_alloc_cipher( 「AES」,4,32), 即時傳遞這些相同的參數在這兩個加密和decyrption處理這個功能,是有什麼不正確的,如果是的話,你可以糾正它。 – Aliasgar
plz幫助傢伙....... – Aliasgar