forked from microsoft/TSS.MSR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TpmExtensions.js.snips
123 lines (103 loc) · 3.35 KB
/
TpmExtensions.js.snips
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
This file contains source-code snippets that the code-generator inserts into the
appropriate class definition file.
*/
>> TPM_HANDLE
/** Represents TPM_RH.NULL reserved handle */
public static readonly NULL: TPM_HANDLE = new TPM_HANDLE(TPM_RH.NULL);
/** Represents TPM_RH.OWNER reserved handle */
public static readonly OWNER: TPM_HANDLE = new TPM_HANDLE(TPM_RH.OWNER);
/** Represents TPM_RH.ENDORSEMENT reserved handle */
public static readonly ENDORSEMENT: TPM_HANDLE = new TPM_HANDLE(TPM_RH.ENDORSEMENT);
/** Represents TPM_RH.PLATFORM reserved handle */
public static readonly PLATFORM: TPM_HANDLE = new TPM_HANDLE(TPM_RH.PLATFORM);
/** Authorization value associated with this handle object */
public authValue: Buffer = null;
/** Name of the TPM entity represented by this handle object */
public name: Buffer = null;
/** Creates a handle for a persistent object
* @param handleOffset Offset in the integer range reserved for persistent handles
* @return New TPM_HANDLE object
*/
public static persistent(handleOffset: number): TPM_HANDLE
{
return new TPM_HANDLE((TPM_HT.PERSISTENT << 24) + handleOffset);
};
/** Creates a TPM_HANDLE object for a PCR
* @param PcrIndex The PCR index
* @return New TPM_HANDLE object
*/
public static pcr(pcrIndex: number): TPM_HANDLE
{
return new TPM_HANDLE(pcrIndex);
}
/** Creates a TPM_HANDLE for an NV slot
* @param nvIndex The NV index
* @return New TPM_HANDLE object
*/
public static NV(nvIndex: number): TPM_HANDLE
{
return new TPM_HANDLE((TPM_HT.NV_INDEX << 24) + nvIndex);
};
/** Creates a password session handle with the associated authorization value
* @param authValue The authorization value
* @return New TPM_HANDLE object
*/
public static pwSession(authValue: Buffer): TPM_HANDLE
{
let pwapHandle: TPM_HANDLE = new TPM_HANDLE(TPM_RH.RS_PW);
pwapHandle.authValue = authValue;
return pwapHandle;
}
/** @return This handle type */
public getType(): TPM_HT
{
return (this.handle >> 24) as TPM_HT;
};
/** @return TPM name of this handle */
public getName(): Buffer
{
switch (this.getType())
{
case 0:
case 2:
case 3:
case 0x40:
this.name = this.toBytes();
return this.name;
case 1:
case 0x80:
case 0x81:
return this.name;
default:
throw new Error("TPM_HANDLE.getName(): Unknown handle type");
}
}
>> TPMT_PUBLIC
/** @return The TPM name (alg-prepended hash of the public area) of this object */
public getName(): Buffer
{
let pub = this.toBytes();
let pubHash = Crypto.hash(this.nameAlg, pub);
let algBuf = new Buffer(2);
algBuf.writeInt16BE(this.nameAlg, 0);
return Buffer.concat([algBuf, pubHash]);
}
>> TPMT_TK_HASHCHECK
/** @deprecated Use default ctor instead */
public static nullTicket(): TPMT_TK_HASHCHECK
{
return new TPMT_TK_HASHCHECK(new TPM_HANDLE(TPM_RH.OWNER));
}
>> TPMT_SYM_DEF
/** @deprecated Use default ctor instead */
public static nullObject(): TPMT_SYM_DEF
{
return new TPMT_SYM_DEF(TPM_ALG_ID.NULL, 0, TPM_ALG_ID.NULL);
}
>> TPMT_SYM_DEF_OBJECT
/** @deprecated Use default ctor instead */
public static nullObject(): TPMT_SYM_DEF_OBJECT
{
return new TPMT_SYM_DEF_OBJECT(TPM_ALG_ID.NULL, 0, TPM_ALG_ID.NULL);
}