Chromium Code Reviews| Index: gpu/command_buffer/common/mailbox.cc |
| diff --git a/gpu/command_buffer/common/mailbox.cc b/gpu/command_buffer/common/mailbox.cc |
| index 8d8393fa63c0a647a992c98d6619156e01e75a92..21602ab6d4df291b19348f365d9d266abce12663 100644 |
| --- a/gpu/command_buffer/common/mailbox.cc |
| +++ b/gpu/command_buffer/common/mailbox.cc |
| @@ -7,6 +7,7 @@ |
| #include <string.h> |
| #include "base/logging.h" |
| +#include "base/rand_util.h" |
| namespace gpu { |
| @@ -31,4 +32,28 @@ void Mailbox::SetName(const int8* n) { |
| memcpy(name, n, sizeof(name)); |
| } |
| +Mailbox Mailbox::Generate() { |
| + Mailbox result; |
| + // Generates cryptographically-secure bytes. |
| + base::RandBytes(result.name, sizeof(result.name)); |
|
awong
2014/02/26 19:19:22
Use crypto::RandBytes() instead?
|
| +#if !defined(NDEBUG) |
| + int8 value = 1; |
| + for (size_t i = 1; i < sizeof(result.name); ++i) |
| + value ^= result.name[i]; |
| + result.name[0] = value; |
| +#endif |
| + return result; |
| +} |
| + |
| +bool Mailbox::Verify() const { |
| +#if !defined(NDEBUG) |
| + int8 value = 1; |
| + for (size_t i = 0; i < sizeof(name); ++i) |
| + value ^= name[i]; |
| + return value == 0; |
| +#else |
| + return true; |
| +#endif |
| +} |
| + |
| } // namespace gpu |