News for hackers. Stuff that matters.
Re:Arc4random – randomization for all occasions by acqq on Saturday November 22, 2014 @05:23AM (#8645268)
Yes, getrandom is not an alternative arc4random implementation, it's a lower level interface. Even the programmers writing for Linux should actually locate arc4random implementation that they can use. And before somebody even considers calling getrandom directly he should evaluate how hard is to just implement getentropy from getrandom, it's harder than it looks at the start, if I correctly remember even Ted Tso's first attempt was wrong -- here's the better (I don't know if it's the last):

http://lwn.net/Articles/606552/

    int getentropy(void *buf, size_t buflen)
    {
            int     ret;

            if (buflen > 256)
                    goto failure;
            ret = getrandom(buf, buflen, 0);
            if (ret < 0)
                    return ret;
            if (ret == buflen)
                    return 0;
    failure:
            errno = EIO;
            return -1;
    }
Note the magical 256 number. It's important.

There are no comments on this comment yet.