TPM 2.0中的tpm2_changeauth命令对应的源文件就是tpm2_changeauth.c,该文件位于tpm2-tools/tools/下,一共有423行(版本5.5)。
tpm2_changeauth的功能是更改TPM对象的授权值。为各种层级、NV索引、临时对象和持久性对象配置授权值。
下边用几篇文章的篇幅对tpm2_changeauth.c文件结合tpm2_changeauth命令进行深入的、完全的解析。
先来看第一段代码:
// Register this tool with tpm2_tool.c
TPM2_TOOL_REGISTER("changeauth", tpm2_tool_onstart, tpm2_tool_onrun,
tpm2_tool_onstop, NULL)
TPM2_TOOL_REGISTER是一个宏定义,在tpm2-tools/tools/tpm2_tool.h中,代码如下:
#define TPM2_TOOL_REGISTER(tool_name,tool_onstart,tool_onrun,tool_onstop,tool_onexit) \
static const tpm2_tool tool = { \
.name = tool_name, \
.onstart = tool_onstart, \
.onrun = tool_onrun, \
.onstop = tool_onstop, \
.onexit = tool_onexit, \
}; \