1 /* fhandler_dev_random.cc: code to access /dev/random
3 Copyright 2000 Cygnus Solutions.
5 Written by Corinna Vinschen (vinschen@cygnus.com)
7 This file is part of Cygwin.
9 This software is a copyrighted work licensed under the terms of the
10 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
19 fhandler_dev_random::fhandler_dev_random (const char *name, int nunit)
20 : fhandler_base (FH_RANDOM, name),
22 crypt_prov((HCRYPTPROV)NULL)
24 set_cb (sizeof *this);
28 fhandler_dev_random::open (const char *, int flags, mode_t)
35 fhandler_dev_random::write (const void *, size_t len)
41 fhandler_dev_random::read (void *ptr, size_t len)
46 && !CryptAcquireContext (&crypt_prov, NULL, MS_DEF_PROV, PROV_RSA_FULL,
47 CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET)
48 && !CryptAcquireContext (&crypt_prov, NULL, MS_DEF_PROV, PROV_RSA_FULL,
49 CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET
55 if (!CryptGenRandom (crypt_prov, len, (BYTE *)ptr))
64 fhandler_dev_random::lseek (off_t, int)
70 fhandler_dev_random::close (void)
73 while (!CryptReleaseContext (crypt_prov, 0)
74 && GetLastError () == ERROR_BUSY)
80 fhandler_dev_random::dup (fhandler_base *child)
82 fhandler_dev_random *fhr = (fhandler_dev_random *) child;
84 fhr->crypt_prov = (HCRYPTPROV)NULL;
89 fhandler_dev_random::dump ()
91 paranoid_printf("here, fhandler_dev_random");