1 // Copyright 2014 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. 4 5 #include <errno.h> 6 #include <unistd.h> 7 8 #include "base/logging.h" 9 #include "components/nacl/loader/nonsfi/irt_interfaces.h" 10 #include "components/nacl/loader/nonsfi/irt_util.h" 11 12 namespace nacl { 13 namespace nonsfi { 14 namespace { 15 16 // FD for urandom. 17 int secure_random_fd = -1; 18 19 int IrtGetRandomBytes(void* buf, size_t count, size_t* nread) { 20 DCHECK_NE(secure_random_fd, -1); 21 return CheckErrorWithResult(read(secure_random_fd, buf, count), 22 nread); 23 } 24 25 } // namespace 26 27 const nacl_irt_random kIrtRandom = { 28 IrtGetRandomBytes 29 }; 30 31 void SetUrandomFd(int fd) { 32 DCHECK_EQ(secure_random_fd, -1); 33 secure_random_fd = fd; 34 } 35 36 } // namespace nonsfi 37 } // namespace nacl 38