[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haiku-bugs
Subject:    [haiku-bugs] Re: [Haiku] #14937: Tiny chunks of entropy from /dev/urandom
From:       "Haiku" <trac () haiku-os ! org>
Date:       2019-02-28 18:13:54
Message-ID: 060.36dc2bed3b01204084d609e6788dd815 () haiku-os ! org
[Download RAW message or body]

--==============96302791595056922=MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

#14937: Tiny chunks of entropy from /dev/urandom
-------------------------+----------------------------
   Reporter:  kallisti5  |      Owner:  nobody
       Type:  bug        |     Status:  new
   Priority:  normal     |  Milestone:  Unscheduled
  Component:  Drivers    |    Version:  R1/Development
 Resolution:             |   Keywords:  urandom
 Blocked By:             |   Blocking:
Has a Patch:  0          |   Platform:  All
-------------------------+----------------------------
Description changed by kallisti5:

Old description:

> /dev/urandom on Haiku seems to only offer up small 16 byte chunks of
> entropy.  This behaviour differs from other platforms.
>
> {{{
>
> #include <errno.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <string.h>
> #include <fcntl.h>
> #include <inttypes.h>
>
> int
> main() {
>         int len = 128;
>         int ret = 0;
>
>         uint8_t key[len];
>
>         int fd = open("/dev/urandom", O_RDONLY);
>         if (fd < 0) {
>                 fprintf(stderr, "Unable to open /dev/urandom!");
>                 return fd;
>         }
>
>         int attempts = 0;
>         while (ret < len) {
>                 ssize_t remaining = len - ret;
>                 ssize_t got = read(fd, key + ret, remaining);
>
>                 fprintf(stdout, "Attempt %d: Got %d, giving %d total!\n",
> attempts, got, ret);
>                 ret += got;
>                 if (attempts > 512) {
>                         fprintf(stderr, "Unable to get enough entropy
> from /dev/urandom!");
>                         close(fd);
>                         return -1;
>                 }
>                 attempts++;
>         }
>         close(fd);
>         return ret;
> }
> }}}
>
> Result on Haiku:
> {{{
> ~> ./a.out
> Attempt 0: Got 8, giving 0 total!
> Attempt 1: Got 16, giving 8 total!
> Attempt 2: Got 16, giving 24 total!
> Attempt 3: Got 16, giving 40 total!
> Attempt 4: Got 16, giving 56 total!
> Attempt 5: Got 16, giving 72 total!
> Attempt 6: Got 16, giving 88 total!
> Attempt 7: Got 16, giving 104 total!
> Attempt 8: Got 8, giving 120 total!
> }}}
>
> Result on Linux:
> {{{
> $ ./a.out
> Attempt 0: Got 128, giving 0 total!
> $ ./a.out
> Attempt 0: Got 128, giving 0 total!
> $ ./a.out
> Attempt 0: Got 128, giving 0 total!
> $ ./a.out
> Attempt 0: Got 128, giving 0 total!
> $ ./a.out
> Attempt 0: Got 128, giving 0 total!
> $ ./a.out
> Attempt 0: Got 128, giving 0 total!
> $ ./a.out
> Attempt 0: Got 128, giving 0 total!
> }}}

New description:

 /dev/urandom on Haiku seems to only offer up small 16 byte chunks of
 entropy.  This behaviour differs from other platforms.  I saw  this while
 working on WireGuard under Haiku.

 {{{
 #include <errno.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <string.h>
 #include <fcntl.h>
 #include <inttypes.h>


 int
 main() {
         int len = 128;
         int ret = 0;

         uint8_t key[len];

         int fd = open("/dev/urandom", O_RDONLY);
         if (fd < 0) {
                 fprintf(stderr, "Unable to open /dev/urandom!");
                 return fd;
         }

         int attempts = 0;
         while (ret < len) {
                 ssize_t remaining = len - ret;
                 ssize_t got = read(fd, key + ret, remaining);
                 ret += got;
                 if (attempts > 512) {
                         fprintf(stderr, "Unable to get enough entropy from
 /dev/urandom!");
                         close(fd);
                         return -1;
                 }
                 fprintf(stdout, "Attempt %d: Got %d, giving %d total!\n",
 attempts, got, ret);
                 attempts++;
         }
         close(fd);
         return ret;
 }
 }}}

 Result on Haiku:
 {{{
 ~> ./a.out
 Attempt 0: Got 8, giving 8 total!
 Attempt 1: Got 16, giving 24 total!
 Attempt 2: Got 16, giving 40 total!
 Attempt 3: Got 16, giving 56 total!
 Attempt 4: Got 16, giving 72 total!
 Attempt 5: Got 16, giving 88 total!
 Attempt 6: Got 16, giving 104 total!
 Attempt 7: Got 16, giving 120 total!
 Attempt 8: Got 8, giving 128 total!
 }}}

 Result on Linux:
 {{{
 $ ./a.out
 Attempt 0: Got 128, giving 128 total!
 $ ./a.out
 Attempt 0: Got 128, giving 128 total!
 $ ./a.out
 Attempt 0: Got 128, giving 128 total!
 $ ./a.out
 Attempt 0: Got 128, giving 128 total!
 $ ./a.out
 Attempt 0: Got 128, giving 128 total!
 $ ./a.out
 Attempt 0: Got 128, giving 128 total!
 $ ./a.out
 Attempt 0: Got 128, giving 128 total!
 }}}

--

-- 
Ticket URL: <https://dev.haiku-os.org/ticket/14937#comment:1>
Haiku <https://dev.haiku-os.org>
The Haiku operating system.

--==============96302791595056922==--

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic