OLD | NEW |
1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009-2010 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Contains the implementation of class Tpm | 5 // Contains the implementation of class Tpm |
6 | 6 |
7 #include "tpm.h" | 7 #include "tpm.h" |
8 | 8 |
9 #include <base/file_util.h> | 9 #include <base/file_util.h> |
10 #include <base/platform_thread.h> | 10 #include <base/platform_thread.h> |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 password_sync_lock_.Acquire(); | 578 password_sync_lock_.Acquire(); |
579 owner_password_.assign(owner_password.begin(), owner_password.end()); | 579 owner_password_.assign(owner_password.begin(), owner_password.end()); |
580 password_sync_lock_.Release(); | 580 password_sync_lock_.Release(); |
581 | 581 |
582 file_util::WriteFile(FilePath(kTpmOwnedFile), NULL, 0); | 582 file_util::WriteFile(FilePath(kTpmOwnedFile), NULL, 0); |
583 } | 583 } |
584 | 584 |
585 return took_ownership; | 585 return took_ownership; |
586 } | 586 } |
587 | 587 |
| 588 bool Tpm::GetRandomData(size_t length, chromeos::Blob* data) { |
| 589 TSS_HCONTEXT context_handle; |
| 590 if (!OpenAndConnectTpm(&context_handle)) { |
| 591 LOG(ERROR) << "Could not open the TPM"; |
| 592 return false; |
| 593 } |
| 594 |
| 595 TSS_HTPM tpm_handle; |
| 596 if (!GetTpm(context_handle, &tpm_handle)) { |
| 597 LOG(ERROR) << "Could not get a handle to the TPM."; |
| 598 Tspi_Context_Close(context_handle); |
| 599 return false; |
| 600 } |
| 601 |
| 602 TSS_RESULT result; |
| 603 SecureBlob random(length); |
| 604 BYTE* tpm_data = NULL; |
| 605 if ((result = Tspi_TPM_GetRandom(tpm_handle, random.size(), &tpm_data))) { |
| 606 LOG(ERROR) << "Could not get random data from the TPM: " << result; |
| 607 Tspi_Context_Close(context_handle); |
| 608 return false; |
| 609 } |
| 610 memcpy(random.data(), tpm_data, random.size()); |
| 611 Tspi_Context_FreeMemory(context_handle, tpm_data); |
| 612 chromeos::SecureMemset(tpm_data, 0, random.size()); |
| 613 Tspi_Context_Close(context_handle); |
| 614 data->swap(random); |
| 615 return true; |
| 616 } |
| 617 |
588 } // namespace tpm_init | 618 } // namespace tpm_init |
OLD | NEW |