Deleted Added
full compact
ip_id.c (126263) ip_id.c (133720)
1/* $OpenBSD: ip_id.c,v 1.2 1999/08/26 13:37:01 provos Exp $ */
2
3/*
4 * Copyright 1998 Niels Provos <provos@citi.umich.edu>
5 * All rights reserved.
6 *
7 * Theo de Raadt <deraadt@openbsd.org> came up with the idea of using
8 * such a mathematical system to generate more random (yet non-repeating)

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

29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
1/* $OpenBSD: ip_id.c,v 1.2 1999/08/26 13:37:01 provos Exp $ */
2
3/*
4 * Copyright 1998 Niels Provos <provos@citi.umich.edu>
5 * All rights reserved.
6 *
7 * Theo de Raadt <deraadt@openbsd.org> came up with the idea of using
8 * such a mathematical system to generate more random (yet non-repeating)

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

29 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
35 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 *
37 * $FreeBSD: head/sys/netinet/ip_id.c 126263 2004-02-26 03:53:54Z mlaier $
37 * $FreeBSD: head/sys/netinet/ip_id.c 133720 2004-08-14 15:32:40Z dwmalone $
38 */
39
40/*
41 * seed = random 15bit
42 * n = prime, g0 = generator to n,
43 * j = random so that gcd(j,n-1) == 1
44 * g = g0^j mod n will be a generator again.
45 *

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

52 * The transaction id is determined by:
53 * id[n] = seed xor (g^X[n] mod n)
54 *
55 * Effectivly the id is restricted to the lower 15 bits, thus
56 * yielding two different cycles by toggling the msb on and off.
57 * This avoids reuse issues caused by reseeding.
58 */
59
38 */
39
40/*
41 * seed = random 15bit
42 * n = prime, g0 = generator to n,
43 * j = random so that gcd(j,n-1) == 1
44 * g = g0^j mod n will be a generator again.
45 *

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

52 * The transaction id is determined by:
53 * id[n] = seed xor (g^X[n] mod n)
54 *
55 * Effectivly the id is restricted to the lower 15 bits, thus
56 * yielding two different cycles by toggling the msb on and off.
57 * This avoids reuse issues caused by reseeding.
58 */
59
60#include "opt_random_ip_id.h"
61#include "opt_pf.h"
62#include <sys/param.h>
63#include <sys/time.h>
64#include <sys/kernel.h>
65#include <sys/random.h>
66
60#include "opt_pf.h"
61#include <sys/param.h>
62#include <sys/time.h>
63#include <sys/kernel.h>
64#include <sys/random.h>
65
67#if defined(RANDOM_IP_ID) || defined(DEV_PF)
68#define RU_OUT 180 /* Time after wich will be reseeded */
69#define RU_MAX 30000 /* Uniq cycle, avoid blackjack prediction */
70#define RU_GEN 2 /* Starting generator */
71#define RU_N 32749 /* RU_N-1 = 2*2*3*2729 */
72#define RU_AGEN 7 /* determine ru_a as RU_AGEN^(2*rand) */
73#define RU_M 31104 /* RU_M = 2^7*3^5 - don't change */
74
75#define PFAC_N 3

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

204 /* Linear Congruential Generator */
205 ru_x = (ru_a*ru_x + ru_b) % RU_M;
206
207 ru_counter += i;
208
209 return (ru_seed ^ pmod(ru_g,ru_seed2 ^ ru_x,RU_N)) | ru_msb;
210}
211
66#define RU_OUT 180 /* Time after wich will be reseeded */
67#define RU_MAX 30000 /* Uniq cycle, avoid blackjack prediction */
68#define RU_GEN 2 /* Starting generator */
69#define RU_N 32749 /* RU_N-1 = 2*2*3*2729 */
70#define RU_AGEN 7 /* determine ru_a as RU_AGEN^(2*rand) */
71#define RU_M 31104 /* RU_M = 2^7*3^5 - don't change */
72
73#define PFAC_N 3

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

202 /* Linear Congruential Generator */
203 ru_x = (ru_a*ru_x + ru_b) % RU_M;
204
205 ru_counter += i;
206
207 return (ru_seed ^ pmod(ru_g,ru_seed2 ^ ru_x,RU_N)) | ru_msb;
208}
209
212#endif /* RANDOM_IP_ID || DEV_PF */