nxt_random.c (0:a63ceefd6ab0) nxt_random.c (138:59fc46dd5e1d)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7
8#include <nxt_main.h>
9
10
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7
8#include <nxt_main.h>
9
10
11#if !(NXT_HAVE_ARC4RANDOM)
12
13/*
14 * The pseudorandom generator based on OpenBSD arc4random. Although it is
15 * usually stated that arc4random uses RC4 pseudorandom generation algorithm
16 * they are actually different in nxt_random_add().
17 */
18
19
20#define NXT_RANDOM_KEY_SIZE 128

--- 30 unchanged lines hidden (view full) ---

51
52static void
53nxt_random_stir(nxt_random_t *r)
54{
55 int fd;
56 ssize_t n;
57 struct timeval tv;
58 union {
11/*
12 * The pseudorandom generator based on OpenBSD arc4random. Although it is
13 * usually stated that arc4random uses RC4 pseudorandom generation algorithm
14 * they are actually different in nxt_random_add().
15 */
16
17
18#define NXT_RANDOM_KEY_SIZE 128

--- 30 unchanged lines hidden (view full) ---

49
50static void
51nxt_random_stir(nxt_random_t *r)
52{
53 int fd;
54 ssize_t n;
55 struct timeval tv;
56 union {
59 uint32_t value[3];
57 uint32_t value[4];
60 u_char bytes[NXT_RANDOM_KEY_SIZE];
61 } key;
62
63 n = 0;
64
65#if (NXT_HAVE_GETRANDOM)
66
67 /* Linux 3.17 getrandom(). */

--- 14 unchanged lines hidden (view full) ---

82 if (n != NXT_RANDOM_KEY_SIZE) {
83 (void) gettimeofday(&tv, NULL);
84
85 /* XOR with stack garbage. */
86
87 key.value[0] ^= tv.tv_usec;
88 key.value[1] ^= tv.tv_sec;
89 key.value[2] ^= nxt_pid;
58 u_char bytes[NXT_RANDOM_KEY_SIZE];
59 } key;
60
61 n = 0;
62
63#if (NXT_HAVE_GETRANDOM)
64
65 /* Linux 3.17 getrandom(). */

--- 14 unchanged lines hidden (view full) ---

80 if (n != NXT_RANDOM_KEY_SIZE) {
81 (void) gettimeofday(&tv, NULL);
82
83 /* XOR with stack garbage. */
84
85 key.value[0] ^= tv.tv_usec;
86 key.value[1] ^= tv.tv_sec;
87 key.value[2] ^= nxt_pid;
88 key.value[3] ^= nxt_thread_tid(NULL);
90 }
91
92 nxt_random_add(r, key.bytes, NXT_RANDOM_KEY_SIZE);
93
94 /* Drop the first 3072 bytes. */
95 for (n = 3072; n != 0; n--) {
96 (void) nxt_random_byte(r);
97 }

--- 99 unchanged lines hidden (view full) ---

197 }
198
199 nxt_log_error(NXT_LOG_NOTICE, thr->log, "arc4random unit test failed");
200
201 return NXT_ERROR;
202}
203
204#endif
89 }
90
91 nxt_random_add(r, key.bytes, NXT_RANDOM_KEY_SIZE);
92
93 /* Drop the first 3072 bytes. */
94 for (n = 3072; n != 0; n--) {
95 (void) nxt_random_byte(r);
96 }

--- 99 unchanged lines hidden (view full) ---

196 }
197
198 nxt_log_error(NXT_LOG_NOTICE, thr->log, "arc4random unit test failed");
199
200 return NXT_ERROR;
201}
202
203#endif
205
206#endif