OSDN Git Service

import v0.2.5
[openpts/openpts.git] / include / openpts_tpm.h
1 /*
2  * This file is part of the OpenPTS project.
3  *
4  * The Initial Developer of the Original Code is International
5  * Business Machines Corporation. Portions created by IBM
6  * Corporation are Copyright (C) 2011 International Business
7  * Machines Corporation. All Rights Reserved.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the Common Public License as published by
11  * IBM Corporation; either version 1 of the License, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * Common Public License for more details.
18  *
19  * You should have received a copy of the Common Public License
20  * along with this program; if not, a copy can be viewed at
21  * http://www.opensource.org/licenses/cpl1.0.php.
22  */
23
24 /**
25  * \file include/openpts_tpm.h
26  * \brief  TPM(emu)/TSS
27  * @author Seiji Munetoh <munetoh@users.sourceforge.jp>
28  * @date 2011-02-15
29  * cleanup 
30  *
31  */
32
33 #ifndef INCLUDE_OPENPTS_TPM_H_
34 #define INCLUDE_OPENPTS_TPM_H_
35
36
37 #define MAX_PCRNUM   24  // TPM v1.2
38
39 // 20100614 support SHA1, SHA256, SHA512
40 #define MAX_DIGEST_SIZE    64
41 #define SHA1_DIGEST_SIZE   20
42 #define SHA256_DIGEST_SIZE 32
43 #define SHA512_DIGEST_SIZE 64
44
45 #define SHA1_BASE64_DIGEST_SIZE   28
46 #define SHA256_BASE64_DIGEST_SIZE 44
47 #define SHA512_BASE64_DIGEST_SIZE 88  // TODO(munetoh)
48
49
50 /**
51  * TPM (Emu) context
52  */
53 typedef struct {
54     BYTE pcr[MAX_PCRNUM][SHA1_DIGEST_SIZE]; /**< */
55     // TODO(munetoh) add AIK
56 } OPENPTS_TPM_CONTEXT;
57
58
59 /**
60  * OPENPTS_PCR 
61  * TODO(munetoh) change to OPENPTS_QUOTE
62  */
63 typedef struct {
64     /* PCRS */
65     int pcr_num;
66     int pcr_select[MAX_PCRNUM];
67     BYTE pcr[MAX_PCRNUM][MAX_DIGEST_SIZE];
68     int value_size;
69
70     int pcr_select_size;
71     BYTE *pcr_select_byte;
72
73     /* ValidationData ? */
74     /* Key */
75     BYTE *pubkey;
76     int pubkey_length;
77 } OPENPTS_PCRS;
78
79
80 /**
81  * Event Type
82  */
83 #define EV_COLLECTOR_START    0x80  // 128
84 #define EV_FILE_SCAN          0x84  // 132 by TDDL?
85 #define EV_FILE_SCAN_TSS      0x86  // 134 by Tspi_TPM_PcrExtend()
86
87 /**
88  * EV_COLLECTOR_START
89  */
90 typedef struct {
91     TSS_VERSION pts_version;  // PTS_VERSION
92     PTS_UUID collector_uuid;
93     PTS_UUID manifest_uuid;
94     BYTE     pcr_value[SHA1_DIGEST_SIZE];
95 } OPENPTS_EVENT_COLLECTOR_START;
96
97 /**
98  * EV_FILE_SCAN
99  */
100 typedef struct {
101     UINT32  file_mode;
102     UINT32  file_uid;
103     UINT32  file_gid;
104     UINT32  file_size;
105     BYTE    digest[SHA1_DIGEST_SIZE];
106     UINT32  filename_length;
107     BYTE    filename[1];
108 } OPENPTS_EVENT_FILE_SCAN;
109
110 /* tpm.c */
111 int resetTpm(OPENPTS_TPM_CONTEXT *tctx, int drtm);
112 int extendTpm(OPENPTS_TPM_CONTEXT *tctx, TSS_PCR_EVENT *event);
113 int extendTpm2(OPENPTS_TPM_CONTEXT *tctx, int index, BYTE* digest);
114 int checkTpmPcr(OPENPTS_TPM_CONTEXT *tctx, TSS_PCR_EVENT *event);
115 int checkTpmPcr2(OPENPTS_TPM_CONTEXT *tctx, int index, BYTE* digest);
116 int printTpm(OPENPTS_TPM_CONTEXT *tctx);
117 int getTpmPcrValue(OPENPTS_TPM_CONTEXT *tpm, int index, BYTE *digest);
118 int resetTpmPcr(OPENPTS_TPM_CONTEXT *tctx, int index);
119
120 /* tss.c */
121 int printTssKeyList(int ps_type);
122 int createTssSignKey(
123     PTS_UUID *uuid, int ps_type, char *filename, int force, int srk_password_mode);
124 int deleteTssKey(PTS_UUID *uuid, int ps_type);
125 int getTpmVersion(TSS_VERSION *version);
126 int getTssPubKey(
127     PTS_UUID *uuid,
128     int ps_type, int srk_password_mode, int resetdalock,
129     char *filename,
130     int *pubkey_length, BYTE **pubkey);
131 int quoteTss(
132     PTS_UUID *uuid,
133     int ps_type,
134     int srk_password_mode,
135     char *filename,
136     BYTE *nonce,
137     OPENPTS_PCRS *pcrs,
138     TSS_VALIDATION *validationData);
139 int quote2Tss(
140     PTS_UUID *uuid,
141     int ps_type,
142     int srk_password_mode,
143     char *filename,
144     BYTE *nonce,
145     OPENPTS_PCRS *pcrs,
146     TSS_VALIDATION *validationData);
147 int validateQuoteData(OPENPTS_PCRS *pcrs, TSS_VALIDATION *validationData);
148 int validatePcrCompositeV11(OPENPTS_PCRS *pcrs, TSS_VALIDATION *validationData);
149 int validatePcrCompositeV12(OPENPTS_PCRS *pcrs, TSS_VALIDATION *validationData);
150 int getRandom(BYTE *out, int size);
151 int extendEvent(TSS_PCR_EVENT* event);
152 int readPcr(int pcr_index, BYTE *pcr);
153 int getTpmStatus(TSS_FLAG flag, TSS_BOOL *value, int tpm_password_mode);
154 int setTpmStatus(TSS_FLAG flag, TSS_BOOL value, int tpm_password_mode);
155
156 #endif  // INCLUDE_OPENPTS_TPM_H_