aboutsummaryrefslogtreecommitdiff
path: root/include/odp/api/spec/chksum.h
blob: 800aab2c20a96e5a26896714bb0aada211b0ca1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 2017-2018 Linaro Limited
 */

/**
 * @file
 *
 * ODP checksum functions.
 */

#ifndef ODP_API_SPEC_CHKSUM_H_
#define ODP_API_SPEC_CHKSUM_H_
#include <odp/visibility_begin.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <odp/api/std_types.h>

/** @defgroup odp_chksum ODP CHECKSUM
 *  Checksum functions.
 *  @{
 */

/**
 * Ones' complement sum of 16-bit words
 *
 * Calculates 16-bit ones' complement sum over the data. In case of odd number
 * of bytes, calculation uses a zero byte as padding at the end. This algorithm
 * may be used as part of e.g. IPv4/UDP/TCP checksum generation and checking.
 *
 * @param data       Pointer to data. Data address must be 16-bit aligned
 *                   in minimum.
 * @param data_len   Data length in bytes. In case of an odd number, calculation
 *                   includes one byte of padding.
 *
 * @return Ones' complement sum
 */
uint16_t odp_chksum_ones_comp16(const void *data, uint32_t data_len);

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#include <odp/visibility_end.h>
#endif