Skip to content

Instantly share code, notes, and snippets.

@chris-wood
Created September 27, 2016 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-wood/d0a4a61c2679ed8712547ae7d248f18c to your computer and use it in GitHub Desktop.
Save chris-wood/d0a4a61c2679ed8712547ae7d248f18c to your computer and use it in GitHub Desktop.
Linux kernel secure sequence generation
__u32 secure_tcp_sequence_number(__be32 saddr, __be32 daddr,
__be16 sport, __be16 dport)
{
u32 hash[MD5_DIGEST_WORDS];
net_secret_init();
hash[0] = (__force u32)saddr;
hash[1] = (__force u32)daddr;
hash[2] = ((__force u16)sport << 16) + (__force u16)dport;
hash[3] = net_secret[15];
md5_transform(hash, net_secret);
return seq_scale(hash[0]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment