evictkey.c

来自「IBM开发的TPM的驱动, 有少量的例子可以供参考」· C语言 代码 · 共 78 行

C
78
字号
/****************************************************************************//*                                                                          *//*                                Evict Key                                 *//*                                                                          *//*                           Written by J. Kravitz                          *//*                                                                          *//*                     IBM Thomas J. Watson Research Center                 *//*                                                                          *//*                               Version 1.0                                *//*                                                                          *//*                         Last Revision 11 Feb 2004                        *//*                                                                          *//*                           Copyright (C) 2004 IBM                         *//*                                                                          *//****************************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <netinet/in.h>#include "tpmfunc.h"int main(int argc, char *argv[]){	int ret;	uint32_t handle;	unsigned char listbuff[1024];	uint32_t listlen;	int i;	int listsize;	int offset;	if (argc < 2) {		fprintf(stderr,			"Usage: evictkey <key handle in hex>| all\n");		exit(1);	}	TPM_setlog(0);	if (strcasecmp("all", argv[1]) == 0) {		/* must evict all keys */		ret =		    TPM_GetCapability(0x0000007, NULL, 0,				      (unsigned char *) listbuff,				      &listlen);		if (ret != 0) {			fprintf(stderr,				"Error %x from TPM_GetCapability\n", ret);			exit(1);		}		listsize = LOAD16(listbuff, 0);		offset = 2;		for (i = 0; i < listsize; ++i) {			handle = LOAD32(listbuff, offset);			ret = TPM_EvictKey(handle);			if (ret == 0)				printf("Evicted key handle %08X\n",				       handle);			else				printf				    ("Error %s attempting to Evict key handle %08X\n",				     TPM_GetErrMsg(ret), handle);			offset += 4;		}		exit(0);	}	ret = sscanf(argv[1], "%x", &handle);	if (ret != 1) {		fprintf(stderr, "Invalid argument '%s'\n", argv[1]);		exit(2);	}	ret = TPM_EvictKey(handle);	if (ret != 0) {		fprintf(stderr, "Error %s from TPM_EvictKey\n",			TPM_GetErrMsg(ret));		exit(1);	}	exit(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?