1 /* SCTP kernel reference Implementation
2 * Copyright (c) 1999-2001 Motorola, Inc.
3 * Copyright (c) 2001-2003 International Business Machines, Corp.
5 * This file is part of the SCTP kernel reference Implementation
7 * SCTP Checksum functions
9 * The SCTP reference implementation is free software;
10 * you can redistribute it and/or modify it under the terms of
11 * the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * The SCTP reference implementation is distributed in the hope that it
16 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17 * ************************
18 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with GNU CC; see the file COPYING. If not, write to
23 * the Free Software Foundation, 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
26 * Please send any bug reports or fixes you make to the
28 * lksctp developers <lksctp-developers@lists.sourceforge.net>
30 * Or submit a bug report through the following website:
31 * http://www.sf.net/projects/lksctp
33 * Written or modified by:
35 * Jon Grimm <jgrimm@us.ibm.com>
36 * Sridhar Samudrala <sri@us.ibm.com>
38 * Rewritten to use libcrc32c by:
39 * Vlad Yasevich <vladislav.yasevich@hp.com>
41 * Any bugs reported given to us we will try to fix... any fixes shared will
42 * be incorporated into the next SCTP release.
45 #include <linux/types.h>
46 #include <net/sctp/sctp.h>
47 #include <linux/crc32c.h>
49 static inline __u32
sctp_start_cksum(__u8
*buffer
, __u16 length
)
51 __u32 crc
= ~(__u32
) 0;
52 __u8 zero
[sizeof(__u32
)] = {0};
54 /* Optimize this routine to be SCTP specific, knowing how
55 * to skip the checksum field of the SCTP header.
58 /* Calculate CRC up to the checksum. */
59 crc
= crc32c(crc
, buffer
, sizeof(struct sctphdr
) - sizeof(__u32
));
61 /* Skip checksum field of the header. */
62 crc
= crc32c(crc
, zero
, sizeof(__u32
));
64 /* Calculate the rest of the CRC. */
65 crc
= crc32c(crc
, &buffer
[sizeof(struct sctphdr
)],
66 length
- sizeof(struct sctphdr
));
70 static inline __u32
sctp_update_cksum(__u8
*buffer
, __u16 length
, __u32 crc32
)
72 return crc32c(crc32
, buffer
, length
);
75 static inline __u32
sctp_end_cksum(__u32 crc32
)