Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: tpm.cc

Issue 3116014: Add method to get random bytes from the TPM. (Closed) Base URL: http://src.chromium.org/git/tpm_init.git
Patch Set: Change int to size_t. Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tpm.h ('k') | tpm_init.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « tpm.h ('k') | tpm_init.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698