kernel to/from NV
来源:互联网 发布:博卡软件使用手册 编辑:程序博客网 时间:2024/06/10 22:12
#include <stdio.h>
#include <sys/stat.h>
#include "include/trousers/tss.h"
#define CKERR if(result != TSS_SUCCESS) {perror("erro/n"); return 1;}
int main(){
TSS_HCONTEXT hContext;
TSS_HTPM hTPM;
TSS_HPOLICY hOwnerPolicy;
TSS_HNVSTORE hNVStore;
TSS_RESULT result;
TSS_HHASH hHash;
int i = 0;
BYTE *data;
BYTE *digest;
UINT32 len, len1 = 20;
FILE *file;
BYTE *buffer;
struct stat st;
int ret;
result = Tspi_Context_Create(&hContext); CKERR
result = Tspi_Context_Connect(hContext, NULL); CKERR
//result = Tspi_Context_GetTpmObject(hContext, &hTPM); CKERR
//result = Tspi_GetPolicyObject(hTPM, TSS_POLICY_USAGE, &hOwnerPolicy); CKERR
//result = Tspi_Policy_SetSecret(hOwnerPolicy, TSS_SECRET_MODE_POPUP, 0, NULL); CKERR
result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_NV, 0, &hNVStore); CKERR
result = Tspi_Context_CreateObject(hContext, TSS_OBJECT_TYPE_HASH, TSS_HASH_SHA1, &hHash); CKERR
result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_INDEX, 0, 1); CKERR
//result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_PERMISSIONS, 0, TPM_NV_PER_AUTHWRITE); CKERR
result = Tspi_SetAttribUint32(hNVStore, TSS_TSPATTRIB_NV_DATASIZE, 0, 20); CKERR
file = fopen("/boot/vmlinuz-2.6.30", "rb");
if(!file) {
perror("Open the file error/n");
return 0;
}
ret = stat("/boot/vmlinuz-2.6.30", &st);
if(ret) perror("stat error!/n");
len = st.st_size;
buffer =(BYTE *) malloc(len * sizeof(BYTE));
if(!buffer) perror("malloc error/n");
ret = fread(buffer, len, 1, file);
result = Tspi_Hash_UpdateHashValue(hHash, len, buffer); CKERR
result = Tspi_Hash_GetHashValue(hHash, &len, &data); CKERR
printf("The hash value is:/n");
for (; i < len; i++)
printf("%3x", data[i]);
printf("/n");
digest = (BYTE *) malloc(20 * sizeof(BYTE));
result = Tspi_NV_WriteValue(hNVStore, 0, 20, data); CKERR
result = Tspi_NV_ReadValue(hNVStore, 0, &len1, &digest); CKERR
printf("The readed hash value is:/n");
for (i=0; i < 20; i++)
printf("%3x", digest[i]);
printf("/n");
return 1;
}
- kernel to/from NV
- driver porting from Android to My kernel
- How to get kernel messages from Android?
- from linux kernel to kvm -- debug linux kernel by eclipse
- How to modify wifi NV
- How to Compile Linux Kernel from Source to Build Custom Kernel
- Update Linux Kernel from 2.4.29 to 2.6. 16.8
- How to instantiate I2C devices(From kernel-tree/Documentation/i2c)
- How to instantiate I2C devices[Doc-from-kernel]
- From kernel startup entry point to start_kernel (1)
- From kernel startup entry point to start_kernel (2)
- From kernel startup entry point to start_kernel (3)
- from linux kernel to kvm -- kinds of hypervisor
- How to stop kernel messages from flooding my console?
- How to remove unused kernel from fedora 25
- How to add a new key from kernel level to java level
- Building Kernel from source
- Three Steps Down the Stairs: From Win32 User-Land through Native API to Kernel
- phpMyadmin提示配置文件现在需要绝密的短语密码(blowfish_secret) 解决办法
- 计算机图形学的各个研究层次和研究方法详解
- 大家好!
- 不精确推理-确定性因子
- 使用Installshield 10.0制作安装包时,添加序列号检测
- kernel to/from NV
- 通过模糊逻辑组合证据
- Android中级教程之----Log图文详解(Log.v,Log.d,Log.i,Log.w,Log.e)!
- oracle删除数据文件
- Oracle检查点ckpt (checkpoint)
- 不确定性推理-不确定性证据
- Java输出JVM和操作系统的相关属性 zz
- asp.net 用继承方法实现页面判断session
- ALTER DATABASE 与 ALTER TABLESPACE OFFLINE的区别