this repo has no description
at trunk 27 lines 805 B view raw
1// Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) 2#include "cpython-data.h" 3#include "cpython-func.h" 4#include "cpython-types.h" 5 6#include "os.h" 7#include "runtime.h" 8 9namespace py { 10 11PY_EXPORT int _PyOS_URandom(void* buffer, Py_ssize_t size) { 12 // TODO(T41026101): use an interface that trades off not blocking for a 13 // potentially higher quality source of random bytes. 14 return _PyOS_URandomNonblock(buffer, size); 15} 16 17PY_EXPORT int _PyOS_URandomNonblock(void* buffer, Py_ssize_t size) { 18 if (size < 0) { 19 Thread::current()->raiseWithFmt(LayoutId::kValueError, 20 "negative argument not allowed"); 21 return -1; 22 } 23 bool success = OS::secureRandom(static_cast<byte*>(buffer), size); 24 return success ? 0 : -1; 25} 26 27} // namespace py