| 318 | } |
| 319 | |
| 320 | static void web_random_bytes(unsigned char *buf, size_t len) { |
| 321 | int fd = open("/dev/urandom", O_RDONLY); |
| 322 | if (fd >= 0) { |
| 323 | size_t off = 0; |
| 324 | while (off < len) { |
| 325 | ssize_t n = read(fd, buf + off, len - off); |
| 326 | if (n < 0 && errno == EINTR) continue; |
| 327 | if (n <= 0) break; |
| 328 | off += (size_t)n; |
| 329 | } |
| 330 | close(fd); |
| 331 | if (off == len) return; |
| 332 | } |
| 333 | uint64_t x = (uint64_t)time(NULL) ^ ((uint64_t)getpid() << 32); |
| 334 | for (size_t i = 0; i < len; i++) { |
| 335 | x = x * 6364136223846793005ULL + 1; |
| 336 | buf[i] = (unsigned char)(x >> 32); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | static char *web_base64(const unsigned char *data, size_t len) { |
| 341 | static const char tab[] = |
no outgoing calls
no test coverage detected