diff options
author | Arnaldo Carvalho de Melo <acme@ghostprotocols.net> | 2005-08-09 23:12:30 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2005-08-29 18:49:40 -0400 |
commit | c4365c9235f80128c3c3d5993074173941b1c1f0 (patch) | |
tree | f507b8360bab9f4c86050d75bb7372aa28ce890e | |
parent | d8c97a9451068dd9f7b838a240bb6db894133a5e (diff) |
[RANDOM]: Introduce secure_dccp_sequence_number
Code contributed by Stephen Hemminger.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/char/random.c | 34 | ||||
-rw-r--r-- | include/linux/random.h | 2 |
2 files changed, 36 insertions, 0 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index 6b11d6b2129f..7999da25fe40 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c | |||
@@ -1589,6 +1589,40 @@ u32 secure_tcpv6_port_ephemeral(const __u32 *saddr, const __u32 *daddr, __u16 dp | |||
1589 | EXPORT_SYMBOL(secure_tcpv6_port_ephemeral); | 1589 | EXPORT_SYMBOL(secure_tcpv6_port_ephemeral); |
1590 | #endif | 1590 | #endif |
1591 | 1591 | ||
1592 | #if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE) | ||
1593 | /* Similar to secure_tcp_sequence_number but generate a 48 bit value | ||
1594 | * bit's 32-47 increase every key exchange | ||
1595 | * 0-31 hash(source, dest) | ||
1596 | */ | ||
1597 | u64 secure_dccp_sequence_number(__u32 saddr, __u32 daddr, | ||
1598 | __u16 sport, __u16 dport) | ||
1599 | { | ||
1600 | struct timeval tv; | ||
1601 | u64 seq; | ||
1602 | __u32 hash[4]; | ||
1603 | struct keydata *keyptr = get_keyptr(); | ||
1604 | |||
1605 | hash[0] = saddr; | ||
1606 | hash[1] = daddr; | ||
1607 | hash[2] = (sport << 16) + dport; | ||
1608 | hash[3] = keyptr->secret[11]; | ||
1609 | |||
1610 | seq = half_md4_transform(hash, keyptr->secret); | ||
1611 | seq |= ((u64)keyptr->count) << (32 - HASH_BITS); | ||
1612 | |||
1613 | do_gettimeofday(&tv); | ||
1614 | seq += tv.tv_usec + tv.tv_sec * 1000000; | ||
1615 | seq &= (1ull << 48) - 1; | ||
1616 | #if 0 | ||
1617 | printk("dccp init_seq(%lx, %lx, %d, %d) = %d\n", | ||
1618 | saddr, daddr, sport, dport, seq); | ||
1619 | #endif | ||
1620 | return seq; | ||
1621 | } | ||
1622 | |||
1623 | EXPORT_SYMBOL(secure_dccp_sequence_number); | ||
1624 | #endif | ||
1625 | |||
1592 | #endif /* CONFIG_INET */ | 1626 | #endif /* CONFIG_INET */ |
1593 | 1627 | ||
1594 | 1628 | ||
diff --git a/include/linux/random.h b/include/linux/random.h index cc6703449916..7b2adb3322d5 100644 --- a/include/linux/random.h +++ b/include/linux/random.h | |||
@@ -59,6 +59,8 @@ extern __u32 secure_tcp_sequence_number(__u32 saddr, __u32 daddr, | |||
59 | __u16 sport, __u16 dport); | 59 | __u16 sport, __u16 dport); |
60 | extern __u32 secure_tcpv6_sequence_number(__u32 *saddr, __u32 *daddr, | 60 | extern __u32 secure_tcpv6_sequence_number(__u32 *saddr, __u32 *daddr, |
61 | __u16 sport, __u16 dport); | 61 | __u16 sport, __u16 dport); |
62 | extern u64 secure_dccp_sequence_number(__u32 saddr, __u32 daddr, | ||
63 | __u16 sport, __u16 dport); | ||
62 | 64 | ||
63 | #ifndef MODULE | 65 | #ifndef MODULE |
64 | extern struct file_operations random_fops, urandom_fops; | 66 | extern struct file_operations random_fops, urandom_fops; |