blob: 43d4b056aba0af9b7175ebf4d92d9f9a534a7ce6 [file] [log] [blame]
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <sys/random.h>
#include <assert.h>
#include <errno.h>
#include <zircon/syscalls.h>
#define MAX_LENGTH 256
static_assert(MAX_LENGTH <= ZX_CPRNG_DRAW_MAX_LEN, "");
int getentropy(void* buffer, size_t length) {
if (length > MAX_LENGTH) {
errno = EIO;
return -1;
}
_zx_cprng_draw(buffer, length);
return 0;
}