zoukankan      html  css  js  c++  java
  • TPM 程序设计基础 2-2 :tpm_func.c 以及 spnam_check.c 分析

    前言

    前文 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
    ", 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)
    {
        ......
    }
    
  • 相关阅读:
    【STL】各容器成员对比表
    C/C++ 笔试、面试题目大汇总2
    运维
    Docker_基础运用
    IntelliJ_idea_Ultimate_2018.1_windows
    python_IED工具下载(pycharm)_windows版
    排序_归并排序_递归
    递归_汉诺塔问题
    递归_变位字
    递归_三角数字和阶乘
  • 原文地址:https://www.cnblogs.com/Yogile/p/12808883.html
Copyright © 2011-2022 走看看