af_alg_check.c
#include#include #include #include #include #include int main() { int sockfd = socket(AF_ALG, SOCK_SEQPACKET, 0); if(sockfd == -1) { if(errno == EAFNOSUPPORT) { printf("#define AF_ALG_UNAVAILABLEn"); } else { printf("socket api occurs other errorsn"); } } else { printf("#define AF_ALG_AVAILABLEn"); } close(sockfd); return 0; }
编译并运行
# gcc af_alg_check.c -o af_alg_check # ./af_alg_check #define AF_ALG_AVAILABLE
打印“#define AF_ALG_AVAILABLE” 说明socket支持AF_ALG协议;
打印“#define AF_ALG_UNAVAILABLE” 说明socket不支持AF_ALG协议。
实现自己的内核态密码模块接口使用github上示例代码完成内核态密码模块
# git clone https://github.com/Ed-Yang/crypto-examples.git # cd crypto-examples/ # cd aes-example # make # sudo dmesg -C # sudo insmod aes-example.ko # sudo rmmod aes-example.ko # sudo dmesg实现Netlink AF_ALG协议调用内核态密码模块里的对称加密
使用github上示例代码完成加密算法的调用
# git clone https://github.com/nibrunie/af_alg-examples.git # cd af_alg-examples # make cc -Wall -Werror -o basic_cipher examples/basic_cipher.c -lcrypto # ./basic_cipher e353779c1079aeb82708942dbe77181a
使用 # cat /proc/crypto 查看内核态密码模块支持的算法名称
使用libkcapi库完成内核态密码模块的调用libkcapi - Linux Kernel Crypto API User Space Interface Library. The Linux kernel exports a Netlink interface of type AF_ALG to allow user space to utilize the kernel crypto API. libkcapi uses this Netlink interface and exports easy to use APIs so that a developer does not need to consider the low-level Netlink interface handling.
# git clone https://github.com/smuellerDD/libkcapi.git # cd libkcapi # ./configure # make # make install



