Linux Kernel(Android) 加密算法汇总(三)-应用程序调用内核加密算法接口
2015-10-09 20:05
736 查看
于Linux Kernel(Android) 加密算法总结(cipher、compress、digest)文章中。介绍了怎样在内核中增加三种不同类型的内核加密算法, 并给出了在内核模块中怎样调用他们的实例。
本文将主要介绍,怎样在应用程序空间中(user space) 调用内核空间(kernel space)加密模块提供的加密算法API。
方法一:通过调用crypto: af_alg - User-space interface for Crypto API, Herbert Xu <herbert@gondor.apana.org.au> 2010年,给内核2.6.X 接口实现
详细情况请參考Linux Kernel(Android) 加密算法总结(二)- A netlink-based user-space crypto API
以下依据以上方法实现应用程序调用内核加密算法接口演示样例:
该方法经过在内核层实现与CPU加密模块。或者硬件加密卡对接,并为上层应用程序提供接口的方式。能够实现硬件加密。
应用程序调用内核 hash
hash.c
Andrid.mk
编译完毕后在
adb push testhash /system/bin/
adb shell chmod a+x /system/bin/testhash
adb shell testhash
验证输出结果.
本文将主要介绍,怎样在应用程序空间中(user space) 调用内核空间(kernel space)加密模块提供的加密算法API。
方法一:通过调用crypto: af_alg - User-space interface for Crypto API, Herbert Xu <herbert@gondor.apana.org.au> 2010年,给内核2.6.X 接口实现
详细情况请參考Linux Kernel(Android) 加密算法总结(二)- A netlink-based user-space crypto API
以下依据以上方法实现应用程序调用内核加密算法接口演示样例:
该方法经过在内核层实现与CPU加密模块。或者硬件加密卡对接,并为上层应用程序提供接口的方式。能够实现硬件加密。
应用程序调用内核 hash
hash.c
<span style="font-size:18px;">#include <stdio.h> #include <sys/socket.h> #include <linux/if_alg.h> #ifndef AF_ALG #define AF_ALG 38 #define SOL_ALG 279 #endif int main(void) { int opfd; int tfmfd; struct sockaddr_alg sa = { .salg_family = AF_ALG, .salg_type = "hash", .salg_name = "sha1" }; char buf[20]; int i; tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0); bind(tfmfd, (struct sockaddr *)&sa, sizeof(sa)); opfd = accept(tfmfd, NULL, 0); write(opfd, "abc", 3); read(opfd, buf, 20); for (i = 0; i < 20; i++) { printf("%02x", (unsigned char)buf[i]); } printf("\n"); close(opfd); close(tfmfd); return 0; }</span>
Andrid.mk
<span style="font-size:18px;">LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := testhash LOCAL_MODULE_TAGS := optional LOCAL_SRC_FILES := \ hash.c include $(BUILD_EXECUTABLE)</span>
编译完毕后在
adb push testhash /system/bin/
adb shell chmod a+x /system/bin/testhash
adb shell testhash
验证输出结果.
相关文章推荐
- linux进程内存分析
- CentOS-Desktop版service network restart报错
- linux基础
- linux curl 命令详解,以及实例
- Alerta在CentOS6.6安装全过程
- ubutun 下编译linux内核并添加为新的启动项
- Linux中查看CPU、内存等硬件信息
- Linux 编程学习笔记----过程管理和项目发展(在)
- Linux中几个进程查看命令总结 ps, top, htop, vmstat
- CentOS文件浏览器设置
- linux文件处理命令
- linux下tar.gz、tar、bz2、zip等解压缩、压缩命令小结
- linux下解压命令大全
- 每天一个linux命令(61):wget命令
- Linux C++编译 错误:‘std::tr1’尚未声明
- How do I remove all partitions, data and create clean empty hard disk under Linux operating systems?
- Centos Swoole安装
- Linux负载均衡软件LVS(概念篇)
- linux svn authorization failed错误
- Linux下复制粘贴快捷键