Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2000-05-03 19:39:10 +0400
committerCorinna Vinschen <corinna@vinschen.de>2000-05-03 19:39:10 +0400
commit1c0c369b36c1ddf4af25052b311a48597b5fdb3f (patch)
tree9494b26d7f33d8ae4797968d7459c1a2acb7ca89 /winsup/cygwin/fhandler_random.cc
parent49d64538cd20abeabd5678b28db05da6fda5e17a (diff)
* Makefile.in: Add dependencies for fhandler_random.o
* fhandler.h: Add device type FH_RANDOM. Add class fhandler_dev_random. * fhandler_random.cc: New file. Implementation of fhandler_dev_random. * hinfo.cc (build_fhandler): Add case for FH_RANDOM. * path.cc: Add device names for random devices to windows_device_names. (get_device_number): Add if branch for random devices. (win32_device_name): Add device name generation for random devices. winsup.h: Include <wincrypt.h>.
Diffstat (limited to 'winsup/cygwin/fhandler_random.cc')
-rw-r--r--winsup/cygwin/fhandler_random.cc92
1 files changed, 92 insertions, 0 deletions
diff --git a/winsup/cygwin/fhandler_random.cc b/winsup/cygwin/fhandler_random.cc
new file mode 100644
index 000000000..6ea72fa0d
--- /dev/null
+++ b/winsup/cygwin/fhandler_random.cc
@@ -0,0 +1,92 @@
+/* fhandler_dev_random.cc: code to access /dev/random
+
+ Copyright 2000 Cygnus Solutions.
+
+ Written by Corinna Vinschen (vinschen@cygnus.com)
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license. Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#include <errno.h>
+#include "winsup.h"
+
+#define RANDOM 8
+#define URANDOM 9
+
+fhandler_dev_random::fhandler_dev_random (const char *name, int nunit)
+ : fhandler_base (FH_RANDOM, name),
+ unit(nunit),
+ crypt_prov((HCRYPTPROV)NULL)
+{
+ set_cb (sizeof *this);
+}
+
+int
+fhandler_dev_random::open (const char *, int flags, mode_t)
+{
+ set_flags (flags);
+ return 1;
+}
+
+int
+fhandler_dev_random::write (const void *, size_t len)
+{
+ return len;
+}
+
+int
+fhandler_dev_random::read (void *ptr, size_t len)
+{
+ if (!len)
+ return 0;
+ if (!crypt_prov
+ && !CryptAcquireContext (&crypt_prov, NULL, MS_DEF_PROV,
+ PROV_RSA_FULL, 0)
+ && !CryptAcquireContext (&crypt_prov, NULL, MS_DEF_PROV,
+ PROV_RSA_FULL, CRYPT_NEWKEYSET))
+ {
+ __seterrno ();
+ return -1;
+ }
+ if (!CryptGenRandom (crypt_prov, len, (BYTE *)ptr))
+ {
+ __seterrno ();
+ return -1;
+ }
+ return len;
+}
+
+off_t
+fhandler_dev_random::lseek (off_t, int)
+{
+ return 0;
+}
+
+int
+fhandler_dev_random::close (void)
+{
+ if (crypt_prov)
+ while (!CryptReleaseContext (crypt_prov, 0)
+ && GetLastError () == ERROR_BUSY)
+ Sleep(10);
+ return 0;
+}
+
+int
+fhandler_dev_random::dup (fhandler_base *child)
+{
+ fhandler_dev_random *fhr = (fhandler_dev_random *) child;
+ fhr->unit = unit;
+ fhr->crypt_prov = (HCRYPTPROV)NULL;
+ return 0;
+}
+
+void
+fhandler_dev_random::dump ()
+{
+ paranoid_printf("here, fhandler_dev_random");
+}
+