#include <linux/crypto.h> #include <linux/err.h> #include <linux/scatterlist.h> #include <crypto/skcipher.h> #define AES_KEY_SIZE 16 #define AES_BLOCK_SIZE 16 static struct crypto_skcipher *tfm; static int aes_init(void) { tfm = crypto_alloc_skcipher("aes", 0, 0); if (IS_ERR...
return crypto_alloc_tfm(alg_name, &crypto_skcipher_type2, type, mask); } EXPORT_SYMBOL_GPL(crypto_alloc_skcipher);int crypto_has_skcipher2(const char *alg_name, u32 type, u32 mask) { return crypto_type_has_alg(alg_name, &crypto_skcipher_type2, ...
crypto core是最基本骨架 ,它提供crypto的核心组件(包括crypto_alg,crypto_template的管理,cryptd内核线程等);基于crypto core,内核实现了8类常用的算法,DRBG伪随机数算法,Hash算法,SKCIPHER对称加解密算法,AKCIPHER非对称加解密算法,AEAD认证加密算法,HMAC算法,COMPRESS压缩算法,KPP密钥协商算法。 一些用于secure的硬件模块...
crypto core是最基本骨架 ,它提供crypto的核心组件(包括crypto_alg,crypto_template的管理,cryptd内核线程等);基于crypto core,内核实现了8类常用的算法,DRBG伪随机数算法,Hash算法,SKCIPHER对称加解密算法,AKCIPHER非对称加解密算法,AEAD认证加密算法,HMAC算法,COMPRESS压缩算法,KPP密钥协商算法。 一些用于secure的硬件模块...
cryptd_tfm = cryptd_alloc_skcipher(salg->ialg_name, CRYPTO_ALG_INTERNAL, CRYPTO_ALG_INTERNAL);if(IS_ERR(cryptd_tfm))returnPTR_ERR(cryptd_tfm); ctx->cryptd_tfm = cryptd_tfm; reqsize = crypto_skcipher_reqsize(cryptd_skcipher_child(cryptd_tfm)); ...
@@ -2154,7 +2157,8 @@ static int crypt_alloc_tfms_skcipher(struct crypt_config *cc, char *ciphermode) return -ENOMEM;for (i = 0; i < cc->tfms_count; i++) { cc->cipher_tfm.tfms[i] = crypto_alloc_skcipher(ciphermode, 0, 0); ...
crypto_skcipher_encrypt(req); skcipher_request_free(req); crypto_free_cipher(tfm); } 以上代码使用AES算法对输入的明文进行加密。它首先使用crypto_alloc_cipher函数分配一个AES算法的密码接口,并且使用crypto_cipher_setkey函数设置密钥。然后,它通过sg_set_buf函数将输入的明文和输出的密文绑定到scatterlist结构体...
staticintasync_chainiv_givencrypt_first(struct skcipher_givcrypt_request *req){structcrypto_ablkcipher*geniv=skcipher_givcrypt_reqtfm(req);structasync_chainiv_ctx*ctx=crypto_ablkcipher_ctx(geniv);interr =0;if(test_and_set_bit(CHAINIV_STATE_INUSE, &ctx->state))gotoout;if(crypto_ablkciphe...
Kernel crypto中基本所有操作都是围绕着几个核心数据结构展开:struct crypto_alg,struct crypto_template,struct crypto_instance,struct crypto_tfm,struct crypto_type。其他算法都可以基于它们做扩展。例如struct skcipher_alg,struct shash_alg都是继承自struct crypto_alg,见下图2.1: ...
printk(KERN_ERR"skcipher_request_allocfailed\n");return;} sg_init_one(&sg_in,input,AES_BLOCK_SIZE);sg_init_one(&sg_out,output,AES_BLOCK_SIZE);skcipher_request_set_crypt(req,&sg_in,&sg_out,AES_BLOCK_SIZE,NULL);ret=crypto_skcipher_encrypt(req);if(ret){ printk(KERN_ERR"crypto_...