1 /* $OpenBSD: getentropy_win.c,v 1.5 2016/08/07 03:27:21 tb Exp $ */
4 * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org>
5 * Copyright (c) 2014, Bob Beck <beck@obtuse.com>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 * Emulation of getentropy(2) as documented at:
20 * http://man.openbsd.org/getentropy.2
26 #include <sys/types.h>
30 int getentropy(void *buf
, size_t len
);
33 * On Windows, CryptGenRandom is supposed to be a well-seeded
34 * cryptographically strong random number generator.
37 getentropy(void *buf
, size_t len
)
46 if (CryptAcquireContext(&provider
, NULL
, NULL
, PROV_RSA_FULL
,
47 CRYPT_VERIFYCONTEXT
) == 0)
49 if (CryptGenRandom(provider
, len
, buf
) == 0) {
50 CryptReleaseContext(provider
, 0);
53 CryptReleaseContext(provider
, 0);