-
Notifications
You must be signed in to change notification settings - Fork 1
/
CommonCRC.h
158 lines (127 loc) · 4.27 KB
/
CommonCRC.h
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* Copyright (c) 2012 Apple, Inc. All Rights Reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _CC_COMMON_CRC_
#define _CC_COMMON_CRC_
#include <sys/cdefs.h>
#if !defined(COMMON_NUMERICS_H)
#include "CommonNumerics.h"
#endif
#include <Availability.h>
#include <stdint.h>
__BEGIN_DECLS
typedef struct _CNCRCRef_t *CNCRCRef;
enum {
kCN_CRC_8 = 10,
kCN_CRC_8_ICODE = 11,
kCN_CRC_8_ITU = 12,
kCN_CRC_8_ROHC = 13,
kCN_CRC_8_WCDMA = 14,
kCN_CRC_16 = 20,
kCN_CRC_16_CCITT_TRUE = 21,
kCN_CRC_16_CCITT_FALSE = 22,
kCN_CRC_16_USB = 23,
kCN_CRC_16_XMODEM = 24,
kCN_CRC_16_DECT_R = 25,
kCN_CRC_16_DECT_X = 26,
kCN_CRC_16_ICODE = 27,
kCN_CRC_16_VERIFONE = 28,
kCN_CRC_16_A = 29,
kCN_CRC_16_B = 30,
kCN_CRC_16_Fletcher = 31,
kCN_CRC_32_Adler = 40,
kCN_CRC_32 = 41,
kCN_CRC_32_CASTAGNOLI = 42,
kCN_CRC_32_BZIP2 = 43,
kCN_CRC_32_MPEG_2 = 44,
kCN_CRC_32_POSIX = 45,
kCN_CRC_32_XFER = 46,
kCN_CRC_64_ECMA_182 = 60,
};
typedef uint32_t CNcrc;
/*!
@function CNCRC
@abstract One-shot CRC function.
@param algorithm Designates the CRC algorithm to use.
@param in The data to be checksummed.
@param len The length of the data to be checksummed.
@param result The resulting checksum.
@result Possible error returns are kCNParamError and kCNUnimplemented.
*/
CNStatus
CNCRC(CNcrc algorithm, const void *in, size_t len, uint64_t *result)
__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_6_0);
/*!
@function CNCRCInit
@abstract Initialize a CNCRCRef.
@param algorithm Designates the CRC algorithm to use.
@param crcRef The resulting CNCRCRef.
@result Possible error returns are kCNParamError, kCNMemoryFailure and kCNUnimplemented.
*/
CNStatus
CNCRCInit(CNcrc algorithm, CNCRCRef *crcRef)
__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_6_0);
/*!
@function CNCRCRelease
@abstract Release a CNCRCRef.
@param crcRef The CNCRCRef to release.
@result kCNSuccess is always returned.
*/
CNStatus
CNCRCRelease(CNCRCRef crcRef)
__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_6_0);
/*!
@function CNCRCUpdate
@abstract Process data through the CRC function. This can be called multiple times
with a valid crcRef created using CNCRCInit().
@param crcRef The CNCRCRef to use.
@param in The data to be checksummed.
@param len The length of the data to be checksummed.
@result Possible error return is kCNParamError.
*/
CNStatus
CNCRCUpdate(CNCRCRef crcRef, const void *in, size_t len)
__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_6_0);
/*!
@function CNCRCFinal
@abstract Process remaining data through the CRC function and return the resulting checksum.
@param crcRef The CNCRCRef to use.
@param result The resulting checksum.
@result Possible error return is kCNParamError.
*/
CNStatus
CNCRCFinal(CNCRCRef crcRef, uint64_t *result)
__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_6_0);
/*!
@function CNCRCWeakTest
@abstract Perform a "weak" test of a checksum.
@param algorithm Designates the CRC algorithm to test.
@result Possible error return is kCNFailure.
*/
CNStatus
CNCRCWeakTest(CNcrc algorithm)
__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_6_0);
CNStatus
CNCRCDumpTable(CNcrc algorithm)
__OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_6_0);
__END_DECLS
#endif /* _CC_COMMON_CRC_ */