util  Check-in [6b3b3fa87f]

Overview
Comment:switch from syscall to getrandom
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6b3b3fa87f45e77ca4ac432e1be5e5f3c58ffa063c473f61e7dce957abec4f82
User & Date: lexi on 2019-07-19 11:47:45
Other Links: manifest | tags
Context
2019-07-19
11:50
fix static assert check-in: da3eccdcfa user: lexi tags: trunk
11:47
switch from syscall to getrandom check-in: 6b3b3fa87f user: lexi tags: trunk
11:34
add mkpw check-in: 42ea2c7296 user: lexi tags: trunk
Changes

Modified mkpw.c from [a0f03f1e22] to [2857320b30].

    11     11    *  → mkpw is unlikely to be portable to non-POSIX
    12     12    *    systems, but should run fine on Linux as well
    13     13    *    as BSDs with getrandom() support.
    14     14    */
    15     15   
    16     16   #include <unistd.h>
    17     17   #include <sys/random.h>
           18  +#include <sys/syscall.h>
    18     19   #include <stddef.h>
    19     20   #include <stdint.h>
    20     21   #include <string.h>
    21     22   #define sz(a) ( sizeof (a) / sizeof (a) [0] )
    22     23   #define say(x) (write(2, (x), sizeof (x)))
    23     24   
    24     25   #ifdef _CLIPBOARD
................................................................................
   193    194   
   194    195   	char buf[len+1];
   195    196   	/* *buf = 0; */
   196    197   
   197    198   	unsigned char noise[len];
   198    199   	for (size_t i = 0; i<q; ++i) {
   199    200   		unsigned char* cur = noise;
   200         -		getrandom(noise, len, 0);
          201  +		syscall(SYS_getrandom, noise, len, 0);
          202  +		/* getrandom(noise, len, 0); // android doesnt like it */
   201    203   
   202    204   		for(char* ptr = buf; ptr < buf + len; ++ptr, ++cur) {
   203    205   			*ptr = tbl[*cur % chars]; /* such a waste of entropy… :( */
   204    206   		}
   205    207   
   206    208   		buf[len] = '\n';
   207    209   		write(1, buf, len + 1);