内核加密机制
- linux 3.3.8
总体框架
仅显示关键结构
内核加密机制在内核中保存两个全局链表crypto_template_list和crypto_alg_list
crypto_template_list 保存所有的加密方式
- e.g cbc ecb
crypto_alg_list 保存所有的加密算法
- e.g md5 sha128 aes
crypto_template_list由各个算法通过crypto_register_template
函数添加到链表中
crypto_alg_list由各个算法通过crypto_register_alg
函数添加到链表中
数据结构说明
crypto_alg结构可以理解为真正保存加密接口的一个通用结构
struct list_head cra_users;
指向crypto_spawn结构所在的链表
union cra_u;
union { struct ablkcipher_alg ablkcipher; struct aead_alg aead; struct blkcipher_alg blkcipher; struct cipher_alg cipher; struct compress_alg compress; struct rng_alg rng; } cra_u;
保存实际算法实现的函数接口和算法相关信息
- blkcipher_alg
struct blkcipher_alg { int (* setkey) (struct crypto_tfm *tfm, const u8 *key,unsigned int keylen); int (* encrypt) (struct blkcipher_desc *desc,struct scatterlist *dst, struct scatterlist *src,unsigned int nbytes); int (* decrypt) (struct blkcipher_desc *desc,struct scatterlist *dst, struct scatterlist *src,unsigned int nbytes); const char * geniv; unsigned int min_keysize; unsigned int max_keysize; unsigned int ivsize; };
i