码迷,mamicode.com
首页 > 其他好文 > 详细

TPM 程序设计基础 2-2 :tpm_func.c 以及 spnam_check.c 分析

时间:2020-04-30 15:35:01      阅读:61      评论:0      收藏:0      [点我收藏+]

标签:spn   hand   调用   包含   char   文档   dex   ror   pass   

前言

前文 TPM 程序设计基础 2-1 :具体函数调用步骤及解析示例 简述了如何通过《TSS V1.2》文档来实现 C 语言 TPM 编程。

本文就包含了课设中所有调用 TPM 接口的 tpm_func.c 以及验证账户权限 spnam_check.c ,简述相应的函数的功能。

参考程序

  • 待课设验收后,给出参考程序。

tpm_func 代码结构

tpm_func.h

#ifndef TPM_FUNC_H
#define TPM_FUNC_H

void tpm_func_start();
void tpm_func_close();
int tpm_func_pcr_read_write_file();
int tpm_func_pcr_extra(UINT32 uint32_pcr_index, char *pcr_extra_string);
void tpm_func_pcr_reset();

#endif

tpm_func.c

#include .....
#include "tpm_func.h"

#define Debug(message, tResult) printf("%s : %s\n", message, (char *)Trspi_Error_String(tpm_handle.result))

/**
 * 结构体
 * 声明所有要用的 TPM 相关参数
 */
struct TPM_HANDLE {
    ......
}tpm_handle;

/**
 * 获取 TPM、上下文对象、PCR合成对象 句柄
 * 参数:无
 */
void tpm_func_start() 
{
    ......
}

/**
 * 释放 上下文对象 内存
 * 参数:无
 */
void tpm_func_close()
{
    ......
}

/**
 * 读取 TPM PCR 的值,每个 PCR 值为一行写入 ./logs/pcr_read.txt 文件
 * 参数:无
 * 返回值:-1,文件指针打开失败;0,成功。
 */
int tpm_func_pcr_read_write_file()
{
    ......
}

/**
 * 扩展指定的 PCR,再调用 tpm_func_pcr_read_write_file() 函数读取PCR、写入文件
 * 参数:
 * UINT32 uint32_pcr_index : 指定 PCR
 * char *pcr_extra_string : 扩展依据的内容
 */
int tpm_func_pcr_extra(UINT32 uint32_pcr_index, char *pcr_extra_string)
{
    ......
}

spnam_check 代码结构

spnam_check.h

#ifndef SPNAM_CHECK_H
#define SPNAM_CHECK_H

int spnam_check();

#endif

spnam_check.c

#define _XOPEN_SOURCE
#include ......

#include "spnam_check.h"

/**
 * 验证账户权限函数
 * 参数:char *name, char *passwd
 */
int spnam_check(char *name, char *passwd)
{
    ......
}

TPM 程序设计基础 2-2 :tpm_func.c 以及 spnam_check.c 分析

标签:spn   hand   调用   包含   char   文档   dex   ror   pass   

原文地址:https://www.cnblogs.com/Yogile/p/12808883.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!