1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/common/mailbox.h"
9 #include "base/logging.h"
10 #include "base/rand_util.h"
15 memset(name
, 0, sizeof(name
));
18 bool Mailbox::IsZero() const {
19 for (size_t i
= 0; i
< arraysize(name
); ++i
) {
26 void Mailbox::SetZero() {
27 memset(name
, 0, sizeof(name
));
30 void Mailbox::SetName(const int8
* n
) {
31 DCHECK(IsZero() || !memcmp(name
, n
, sizeof(name
)));
32 memcpy(name
, n
, sizeof(name
));
35 Mailbox
Mailbox::Generate() {
37 // Generates cryptographically-secure bytes.
38 base::RandBytes(result
.name
, sizeof(result
.name
));
41 for (size_t i
= 1; i
< sizeof(result
.name
); ++i
)
42 value
^= result
.name
[i
];
43 result
.name
[0] = value
;
48 bool Mailbox::Verify() const {
51 for (size_t i
= 0; i
< sizeof(name
); ++i
)