目录
2.5 skcipher_register_instance
2.5.2 crypto_register_instance
1. 简介
在加密框架中,将根据算法模式(即算法模板)和基础算法动态创建的算法定义为算法模板实例,数据结构为struct crypto_instance,在include\crypto\algapi.h中定义如下所示。
struct crypto_instance {
struct crypto_alg alg;
struct crypto_template *tmpl;
struct hlist_node list;
void *__ctx[] CRYPTO_MINALIGN_ATTR;
};
算法模板实例数据结构为struct crypto_instance各成员变量含义如下所示:
1) alg:算法模板实例对应的算法说明。
2) tmpl:算法模板实例使用的算法模板。
3) list:算法模板实例在算法模板的实例哈希链表中对应的节点。
4) __ctx:算法模板实例的上下文。当前只指向crypto_spawn,我个人理解可能是架构设计者考虑到未来扩展性,就将crypto_spawn与crypto_instance拆分开来了。
由算法模板实例数据结构定义,算法模板实例也是一种算法,如分组算法根据算法模板(如CBC模式)创建的块加密算法。
这个结构体是代表kernel通过template动态创建的算法实例,并且会与crypto_template相关联,可以看到这里的alg并不是个指针。它是通过template