diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/arc4random/getentropy_win.c | 56 | ||||
-rw-r--r-- | src/lib/libcrypto/crypto/getentropy_win.c | 56 |
2 files changed, 112 insertions, 0 deletions
diff --git a/src/lib/libcrypto/arc4random/getentropy_win.c b/src/lib/libcrypto/arc4random/getentropy_win.c new file mode 100644 index 0000000000..4dde4a56b5 --- /dev/null +++ b/src/lib/libcrypto/arc4random/getentropy_win.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /* $OpenBSD: getentropy_win.c,v 1.1 2014/07/12 20:54:49 wouter Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org> | ||
5 | * Copyright (c) 2014, Bob Beck <beck@obtuse.com> | ||
6 | * | ||
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. | ||
10 | * | ||
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. | ||
18 | */ | ||
19 | |||
20 | #include <windows.h> | ||
21 | #include <errno.h> | ||
22 | #include <stdint.h> | ||
23 | #include <sys/types.h> | ||
24 | #include <wincrypt.h> | ||
25 | #include <process.h> | ||
26 | |||
27 | int getentropy(void *buf, size_t len); | ||
28 | |||
29 | /* | ||
30 | * On Windows, CryptGenRandom is supposed to be a well-seeded | ||
31 | * cryptographically strong random number generator. | ||
32 | */ | ||
33 | int | ||
34 | getentropy(void *buf, size_t len) | ||
35 | { | ||
36 | HCRYPTPROV provider; | ||
37 | |||
38 | if (len > 256) { | ||
39 | errno = EIO; | ||
40 | return -1; | ||
41 | } | ||
42 | |||
43 | if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, | ||
44 | CRYPT_VERIFYCONTEXT) != 0) | ||
45 | goto fail; | ||
46 | if (CryptGenRandom(provider, len, buf) != 0) { | ||
47 | CryptReleaseContext(provider, 0); | ||
48 | goto fail; | ||
49 | } | ||
50 | CryptReleaseContext(provider, 0); | ||
51 | return (0); | ||
52 | |||
53 | fail: | ||
54 | errno = EIO; | ||
55 | return (-1); | ||
56 | } | ||
diff --git a/src/lib/libcrypto/crypto/getentropy_win.c b/src/lib/libcrypto/crypto/getentropy_win.c new file mode 100644 index 0000000000..4dde4a56b5 --- /dev/null +++ b/src/lib/libcrypto/crypto/getentropy_win.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /* $OpenBSD: getentropy_win.c,v 1.1 2014/07/12 20:54:49 wouter Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org> | ||
5 | * Copyright (c) 2014, Bob Beck <beck@obtuse.com> | ||
6 | * | ||
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. | ||
10 | * | ||
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. | ||
18 | */ | ||
19 | |||
20 | #include <windows.h> | ||
21 | #include <errno.h> | ||
22 | #include <stdint.h> | ||
23 | #include <sys/types.h> | ||
24 | #include <wincrypt.h> | ||
25 | #include <process.h> | ||
26 | |||
27 | int getentropy(void *buf, size_t len); | ||
28 | |||
29 | /* | ||
30 | * On Windows, CryptGenRandom is supposed to be a well-seeded | ||
31 | * cryptographically strong random number generator. | ||
32 | */ | ||
33 | int | ||
34 | getentropy(void *buf, size_t len) | ||
35 | { | ||
36 | HCRYPTPROV provider; | ||
37 | |||
38 | if (len > 256) { | ||
39 | errno = EIO; | ||
40 | return -1; | ||
41 | } | ||
42 | |||
43 | if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, | ||
44 | CRYPT_VERIFYCONTEXT) != 0) | ||
45 | goto fail; | ||
46 | if (CryptGenRandom(provider, len, buf) != 0) { | ||
47 | CryptReleaseContext(provider, 0); | ||
48 | goto fail; | ||
49 | } | ||
50 | CryptReleaseContext(provider, 0); | ||
51 | return (0); | ||
52 | |||
53 | fail: | ||
54 | errno = EIO; | ||
55 | return (-1); | ||
56 | } | ||