You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/README.md
+85-5Lines changed: 85 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -236,8 +236,35 @@ TPM2.0 Key load example
236
236
Loading SRK: Storage 0x81000200 (282 bytes)
237
237
Reading 744 bytes from keyblob.bin
238
238
Loaded key to 0x80000001
239
+
240
+
./examples/keygen/keygen -sym=aescfb128
241
+
TPM2.0 Key generation example
242
+
Key Blob: keyblob.bin
243
+
Algorithm: SYMCIPHER
244
+
aescfb mode, 128 keybits
245
+
Template: Default
246
+
Use Parameter Encryption: NULL
247
+
Loading SRK: Storage 0x81000200 (282 bytes)
248
+
Symmetric template
249
+
Creating new SYMCIPHER key...
250
+
Created new key (pub 50, priv 142 bytes)
251
+
Wrote 198 bytes to keyblob.bin
252
+
253
+
$ ./examples/keygen/keyload
254
+
TPM2.0 Key load example
255
+
Key Blob: keyblob.bin
256
+
Use Parameter Encryption: NULL
257
+
Loading SRK: Storage 0x81000200 (282 bytes)
258
+
Reading 198 bytes from keyblob.bin
259
+
Reading the private part of the key
260
+
Loaded key to 0x80000001
261
+
239
262
```
240
263
264
+
When filename is not supplied, a default filename "keyblob.bin" is used, therefore `keyload` and `keygen` can be used without additional parameters for quick TPM 2.0 key generation demonstration.
265
+
266
+
To see the complete list of supported cryptographic algorithms and options by the `keygen` example, use one of the `--help` switches.
267
+
241
268
Example for importing a private key as TPM key blob and storing to disk, then loading from disk and loading into temporary TPM handle.
242
269
243
270
```
@@ -271,26 +298,79 @@ The `keyload` tool takes only one argument, the filename of the stored key. Beca
271
298
272
299
## Storing keys into the TPM's NVRAM
273
300
274
-
These examples demonstrates how to use the TPM as secure vault for keys. There are two programs, one to store a TPM key into the TPM's NVRAM and another to extract the key from the TPM's NVRAM. Both examples can use parameter encryption to protect from MITM attacks. The Non-volatile memory location is protected with a password authorization that is passed in encrypted form, when "-aes" or "-xor" is given on the commmand line.
301
+
These examples demonstrates how to use the TPM as a secure vault for keys. There are two programs, one to store a TPM key into the TPM's NVRAM and another to extract the key from the TPM's NVRAM. Both examples can use parameter encryption to protect from MITM attacks. The Non-volatile memory location is protected with a password authorization that is passed in encrypted form, when "-aes" is given on the command line.
275
302
276
303
Before running the examples, make sure there is a keyblob.bin generated using the keygen tool. The key can be of any type, RSA, ECC or symmetric. The example will store the private and public part. In case of a symmetric key the public part is meta data from the TPM. How to generate a key you can see above, in the description of the keygen example.
277
304
278
-
Typical output for storing and then reading an RSA key using parameter encryption:
305
+
Typical output for storing and then reading an RSA key with parameter encryption enabled:
279
306
280
307
```
308
+
281
309
$ ./examples/nvram/store -aes
310
+
Parameter Encryption: Enabled (AES CFB).
311
+
282
312
TPM2_StartAuthSession: sessionHandle 0x2000000
283
313
Reading 840 bytes from keyblob.bin
284
314
Storing key at TPM NV index 0x1800202 with password protection
315
+
285
316
Public part = 616 bytes
317
+
NV write of public part succeeded
318
+
286
319
Private part = 222 bytes
287
-
NV write succeeded
320
+
Stored 2-byte size marker before the private part
321
+
NV write of private part succeeded
322
+
323
+
324
+
$ ./examples/nvram/read -aes
325
+
Parameter Encryption: Enabled (AES CFB).
288
326
289
-
$ ./examples/nvram/read 616 222 -aes
290
327
TPM2_StartAuthSession: sessionHandle 0x2000000
291
328
Trying to read 616 bytes of public key part from NV
329
+
Successfully read public key part from NV
330
+
331
+
Trying to read size marker of the private key part from NV
332
+
Successfully read size marker from NV
333
+
334
+
Trying to read 222 bytes of private key part from NV
335
+
Successfully read private key part from NV
336
+
337
+
Extraction of key from NVRAM at index 0x1800202 succeeded
338
+
Loading SRK: Storage 0x81000200 (282 bytes)
339
+
Trying to load the key extracted from NVRAM
340
+
Loaded key to 0x80000001
341
+
342
+
```
343
+
344
+
The "read" example will try to load the extracted key, if both the public and private part of the key were stored in NVRAM. The "-aes" switches triggers the use of parameter encryption.
345
+
346
+
The examples can work with partial key material - private or public. This is achieved by using the "-priv" and "-pub" options.
347
+
348
+
Typical output of storing only the private key of RSA asymmetric key pair in NVRAM and without parameter encryption enabled.
349
+
350
+
```
351
+
352
+
$ ./examples/nvram/store -priv
353
+
Parameter Encryption: Not enabled (try -aes or -xor).
354
+
355
+
Reading 506 bytes from keyblob.bin
356
+
Reading the private part of the key
357
+
Storing key at TPM NV index 0x1800202 with password protection
358
+
359
+
Private part = 222 bytes
360
+
Stored 2-byte size marker before the private part
361
+
NV write of private part succeeded
362
+
363
+
$ ./examples/nvram/read -priv
364
+
Parameter Encryption: Not enabled (try -aes or -xor).
365
+
366
+
Trying to read size marker of the private key part from NV
367
+
Successfully read size marker from NV
368
+
292
369
Trying to read 222 bytes of private key part from NV
370
+
Successfully read private key part from NV
371
+
293
372
Extraction of key from NVRAM at index 0x1800202 succeeded
373
+
294
374
```
295
375
296
-
The read example takes as first argument the size of the public part and as second argument the private part. This information is given from the store example. The "-aes" swiches triggers the use of parameter encryption.
376
+
After successful key extraction using "read", the NV Index is destroyed. Therefore, to use "read" again, the "store" example must be run again as well.
0 commit comments