XWOS API  4.0
XWOS C/C++ API参考手册
载入中...
搜索中...
未找到
crc32.c
浏览该文件的文档.
1
13#include <xwos/standard.h>
14#include <xwos/lib/xwbop.h>
15#include <xwos/lib/crc32.h>
16
17#if defined(XWLIBCFG_CRC32_0X04C11DB7) && (1 == XWLIBCFG_CRC32_0X04C11DB7)
22 [0] = 0x0,
23 [1] = 0x4C11DB7,
24 [2] = 0x9823B6E,
25 [3] = 0xD4326D9,
26 [4] = 0x130476DC,
27 [5] = 0x17C56B6B,
28 [6] = 0x1A864DB2,
29 [7] = 0x1E475005,
30 [8] = 0x2608EDB8,
31 [9] = 0x22C9F00F,
32 [10] = 0x2F8AD6D6,
33 [11] = 0x2B4BCB61,
34 [12] = 0x350C9B64,
35 [13] = 0x31CD86D3,
36 [14] = 0x3C8EA00A,
37 [15] = 0x384FBDBD,
38 [16] = 0x4C11DB70,
39 [17] = 0x48D0C6C7,
40 [18] = 0x4593E01E,
41 [19] = 0x4152FDA9,
42 [20] = 0x5F15ADAC,
43 [21] = 0x5BD4B01B,
44 [22] = 0x569796C2,
45 [23] = 0x52568B75,
46 [24] = 0x6A1936C8,
47 [25] = 0x6ED82B7F,
48 [26] = 0x639B0DA6,
49 [27] = 0x675A1011,
50 [28] = 0x791D4014,
51 [29] = 0x7DDC5DA3,
52 [30] = 0x709F7B7A,
53 [31] = 0x745E66CD,
54 [32] = 0x9823B6E0,
55 [33] = 0x9CE2AB57,
56 [34] = 0x91A18D8E,
57 [35] = 0x95609039,
58 [36] = 0x8B27C03C,
59 [37] = 0x8FE6DD8B,
60 [38] = 0x82A5FB52,
61 [39] = 0x8664E6E5,
62 [40] = 0xBE2B5B58,
63 [41] = 0xBAEA46EF,
64 [42] = 0xB7A96036,
65 [43] = 0xB3687D81,
66 [44] = 0xAD2F2D84,
67 [45] = 0xA9EE3033,
68 [46] = 0xA4AD16EA,
69 [47] = 0xA06C0B5D,
70 [48] = 0xD4326D90,
71 [49] = 0xD0F37027,
72 [50] = 0xDDB056FE,
73 [51] = 0xD9714B49,
74 [52] = 0xC7361B4C,
75 [53] = 0xC3F706FB,
76 [54] = 0xCEB42022,
77 [55] = 0xCA753D95,
78 [56] = 0xF23A8028,
79 [57] = 0xF6FB9D9F,
80 [58] = 0xFBB8BB46,
81 [59] = 0xFF79A6F1,
82 [60] = 0xE13EF6F4,
83 [61] = 0xE5FFEB43,
84 [62] = 0xE8BCCD9A,
85 [63] = 0xEC7DD02D,
86 [64] = 0x34867077,
87 [65] = 0x30476DC0,
88 [66] = 0x3D044B19,
89 [67] = 0x39C556AE,
90 [68] = 0x278206AB,
91 [69] = 0x23431B1C,
92 [70] = 0x2E003DC5,
93 [71] = 0x2AC12072,
94 [72] = 0x128E9DCF,
95 [73] = 0x164F8078,
96 [74] = 0x1B0CA6A1,
97 [75] = 0x1FCDBB16,
98 [76] = 0x18AEB13,
99 [77] = 0x54BF6A4,
100 [78] = 0x808D07D,
101 [79] = 0xCC9CDCA,
102 [80] = 0x7897AB07,
103 [81] = 0x7C56B6B0,
104 [82] = 0x71159069,
105 [83] = 0x75D48DDE,
106 [84] = 0x6B93DDDB,
107 [85] = 0x6F52C06C,
108 [86] = 0x6211E6B5,
109 [87] = 0x66D0FB02,
110 [88] = 0x5E9F46BF,
111 [89] = 0x5A5E5B08,
112 [90] = 0x571D7DD1,
113 [91] = 0x53DC6066,
114 [92] = 0x4D9B3063,
115 [93] = 0x495A2DD4,
116 [94] = 0x44190B0D,
117 [95] = 0x40D816BA,
118 [96] = 0xACA5C697,
119 [97] = 0xA864DB20,
120 [98] = 0xA527FDF9,
121 [99] = 0xA1E6E04E,
122 [100] = 0xBFA1B04B,
123 [101] = 0xBB60ADFC,
124 [102] = 0xB6238B25,
125 [103] = 0xB2E29692,
126 [104] = 0x8AAD2B2F,
127 [105] = 0x8E6C3698,
128 [106] = 0x832F1041,
129 [107] = 0x87EE0DF6,
130 [108] = 0x99A95DF3,
131 [109] = 0x9D684044,
132 [110] = 0x902B669D,
133 [111] = 0x94EA7B2A,
134 [112] = 0xE0B41DE7,
135 [113] = 0xE4750050,
136 [114] = 0xE9362689,
137 [115] = 0xEDF73B3E,
138 [116] = 0xF3B06B3B,
139 [117] = 0xF771768C,
140 [118] = 0xFA325055,
141 [119] = 0xFEF34DE2,
142 [120] = 0xC6BCF05F,
143 [121] = 0xC27DEDE8,
144 [122] = 0xCF3ECB31,
145 [123] = 0xCBFFD686,
146 [124] = 0xD5B88683,
147 [125] = 0xD1799B34,
148 [126] = 0xDC3ABDED,
149 [127] = 0xD8FBA05A,
150 [128] = 0x690CE0EE,
151 [129] = 0x6DCDFD59,
152 [130] = 0x608EDB80,
153 [131] = 0x644FC637,
154 [132] = 0x7A089632,
155 [133] = 0x7EC98B85,
156 [134] = 0x738AAD5C,
157 [135] = 0x774BB0EB,
158 [136] = 0x4F040D56,
159 [137] = 0x4BC510E1,
160 [138] = 0x46863638,
161 [139] = 0x42472B8F,
162 [140] = 0x5C007B8A,
163 [141] = 0x58C1663D,
164 [142] = 0x558240E4,
165 [143] = 0x51435D53,
166 [144] = 0x251D3B9E,
167 [145] = 0x21DC2629,
168 [146] = 0x2C9F00F0,
169 [147] = 0x285E1D47,
170 [148] = 0x36194D42,
171 [149] = 0x32D850F5,
172 [150] = 0x3F9B762C,
173 [151] = 0x3B5A6B9B,
174 [152] = 0x315D626,
175 [153] = 0x7D4CB91,
176 [154] = 0xA97ED48,
177 [155] = 0xE56F0FF,
178 [156] = 0x1011A0FA,
179 [157] = 0x14D0BD4D,
180 [158] = 0x19939B94,
181 [159] = 0x1D528623,
182 [160] = 0xF12F560E,
183 [161] = 0xF5EE4BB9,
184 [162] = 0xF8AD6D60,
185 [163] = 0xFC6C70D7,
186 [164] = 0xE22B20D2,
187 [165] = 0xE6EA3D65,
188 [166] = 0xEBA91BBC,
189 [167] = 0xEF68060B,
190 [168] = 0xD727BBB6,
191 [169] = 0xD3E6A601,
192 [170] = 0xDEA580D8,
193 [171] = 0xDA649D6F,
194 [172] = 0xC423CD6A,
195 [173] = 0xC0E2D0DD,
196 [174] = 0xCDA1F604,
197 [175] = 0xC960EBB3,
198 [176] = 0xBD3E8D7E,
199 [177] = 0xB9FF90C9,
200 [178] = 0xB4BCB610,
201 [179] = 0xB07DABA7,
202 [180] = 0xAE3AFBA2,
203 [181] = 0xAAFBE615,
204 [182] = 0xA7B8C0CC,
205 [183] = 0xA379DD7B,
206 [184] = 0x9B3660C6,
207 [185] = 0x9FF77D71,
208 [186] = 0x92B45BA8,
209 [187] = 0x9675461F,
210 [188] = 0x8832161A,
211 [189] = 0x8CF30BAD,
212 [190] = 0x81B02D74,
213 [191] = 0x857130C3,
214 [192] = 0x5D8A9099,
215 [193] = 0x594B8D2E,
216 [194] = 0x5408ABF7,
217 [195] = 0x50C9B640,
218 [196] = 0x4E8EE645,
219 [197] = 0x4A4FFBF2,
220 [198] = 0x470CDD2B,
221 [199] = 0x43CDC09C,
222 [200] = 0x7B827D21,
223 [201] = 0x7F436096,
224 [202] = 0x7200464F,
225 [203] = 0x76C15BF8,
226 [204] = 0x68860BFD,
227 [205] = 0x6C47164A,
228 [206] = 0x61043093,
229 [207] = 0x65C52D24,
230 [208] = 0x119B4BE9,
231 [209] = 0x155A565E,
232 [210] = 0x18197087,
233 [211] = 0x1CD86D30,
234 [212] = 0x29F3D35,
235 [213] = 0x65E2082,
236 [214] = 0xB1D065B,
237 [215] = 0xFDC1BEC,
238 [216] = 0x3793A651,
239 [217] = 0x3352BBE6,
240 [218] = 0x3E119D3F,
241 [219] = 0x3AD08088,
242 [220] = 0x2497D08D,
243 [221] = 0x2056CD3A,
244 [222] = 0x2D15EBE3,
245 [223] = 0x29D4F654,
246 [224] = 0xC5A92679,
247 [225] = 0xC1683BCE,
248 [226] = 0xCC2B1D17,
249 [227] = 0xC8EA00A0,
250 [228] = 0xD6AD50A5,
251 [229] = 0xD26C4D12,
252 [230] = 0xDF2F6BCB,
253 [231] = 0xDBEE767C,
254 [232] = 0xE3A1CBC1,
255 [233] = 0xE760D676,
256 [234] = 0xEA23F0AF,
257 [235] = 0xEEE2ED18,
258 [236] = 0xF0A5BD1D,
259 [237] = 0xF464A0AA,
260 [238] = 0xF9278673,
261 [239] = 0xFDE69BC4,
262 [240] = 0x89B8FD09,
263 [241] = 0x8D79E0BE,
264 [242] = 0x803AC667,
265 [243] = 0x84FBDBD0,
266 [244] = 0x9ABC8BD5,
267 [245] = 0x9E7D9662,
268 [246] = 0x933EB0BB,
269 [247] = 0x97FFAD0C,
270 [248] = 0xAFB010B1,
271 [249] = 0xAB710D06,
272 [250] = 0xA6322BDF,
273 [251] = 0xA2F33668,
274 [252] = 0xBCB4666D,
275 [253] = 0xB8757BDA,
276 [254] = 0xB5365D03,
277 [255] = 0xB1F740B4,
278};
279#endif
280
281#if defined(XWLIBCFG_CRC32_0XEDB88320) && (1 == XWLIBCFG_CRC32_0XEDB88320)
286 [0] = 0x0,
287 [1] = 0x77073096,
288 [2] = 0xEE0E612C,
289 [3] = 0x990951BA,
290 [4] = 0x76DC419,
291 [5] = 0x706AF48F,
292 [6] = 0xE963A535,
293 [7] = 0x9E6495A3,
294 [8] = 0xEDB8832,
295 [9] = 0x79DCB8A4,
296 [10] = 0xE0D5E91E,
297 [11] = 0x97D2D988,
298 [12] = 0x9B64C2B,
299 [13] = 0x7EB17CBD,
300 [14] = 0xE7B82D07,
301 [15] = 0x90BF1D91,
302 [16] = 0x1DB71064,
303 [17] = 0x6AB020F2,
304 [18] = 0xF3B97148,
305 [19] = 0x84BE41DE,
306 [20] = 0x1ADAD47D,
307 [21] = 0x6DDDE4EB,
308 [22] = 0xF4D4B551,
309 [23] = 0x83D385C7,
310 [24] = 0x136C9856,
311 [25] = 0x646BA8C0,
312 [26] = 0xFD62F97A,
313 [27] = 0x8A65C9EC,
314 [28] = 0x14015C4F,
315 [29] = 0x63066CD9,
316 [30] = 0xFA0F3D63,
317 [31] = 0x8D080DF5,
318 [32] = 0x3B6E20C8,
319 [33] = 0x4C69105E,
320 [34] = 0xD56041E4,
321 [35] = 0xA2677172,
322 [36] = 0x3C03E4D1,
323 [37] = 0x4B04D447,
324 [38] = 0xD20D85FD,
325 [39] = 0xA50AB56B,
326 [40] = 0x35B5A8FA,
327 [41] = 0x42B2986C,
328 [42] = 0xDBBBC9D6,
329 [43] = 0xACBCF940,
330 [44] = 0x32D86CE3,
331 [45] = 0x45DF5C75,
332 [46] = 0xDCD60DCF,
333 [47] = 0xABD13D59,
334 [48] = 0x26D930AC,
335 [49] = 0x51DE003A,
336 [50] = 0xC8D75180,
337 [51] = 0xBFD06116,
338 [52] = 0x21B4F4B5,
339 [53] = 0x56B3C423,
340 [54] = 0xCFBA9599,
341 [55] = 0xB8BDA50F,
342 [56] = 0x2802B89E,
343 [57] = 0x5F058808,
344 [58] = 0xC60CD9B2,
345 [59] = 0xB10BE924,
346 [60] = 0x2F6F7C87,
347 [61] = 0x58684C11,
348 [62] = 0xC1611DAB,
349 [63] = 0xB6662D3D,
350 [64] = 0x76DC4190,
351 [65] = 0x1DB7106,
352 [66] = 0x98D220BC,
353 [67] = 0xEFD5102A,
354 [68] = 0x71B18589,
355 [69] = 0x6B6B51F,
356 [70] = 0x9FBFE4A5,
357 [71] = 0xE8B8D433,
358 [72] = 0x7807C9A2,
359 [73] = 0xF00F934,
360 [74] = 0x9609A88E,
361 [75] = 0xE10E9818,
362 [76] = 0x7F6A0DBB,
363 [77] = 0x86D3D2D,
364 [78] = 0x91646C97,
365 [79] = 0xE6635C01,
366 [80] = 0x6B6B51F4,
367 [81] = 0x1C6C6162,
368 [82] = 0x856530D8,
369 [83] = 0xF262004E,
370 [84] = 0x6C0695ED,
371 [85] = 0x1B01A57B,
372 [86] = 0x8208F4C1,
373 [87] = 0xF50FC457,
374 [88] = 0x65B0D9C6,
375 [89] = 0x12B7E950,
376 [90] = 0x8BBEB8EA,
377 [91] = 0xFCB9887C,
378 [92] = 0x62DD1DDF,
379 [93] = 0x15DA2D49,
380 [94] = 0x8CD37CF3,
381 [95] = 0xFBD44C65,
382 [96] = 0x4DB26158,
383 [97] = 0x3AB551CE,
384 [98] = 0xA3BC0074,
385 [99] = 0xD4BB30E2,
386 [100] = 0x4ADFA541,
387 [101] = 0x3DD895D7,
388 [102] = 0xA4D1C46D,
389 [103] = 0xD3D6F4FB,
390 [104] = 0x4369E96A,
391 [105] = 0x346ED9FC,
392 [106] = 0xAD678846,
393 [107] = 0xDA60B8D0,
394 [108] = 0x44042D73,
395 [109] = 0x33031DE5,
396 [110] = 0xAA0A4C5F,
397 [111] = 0xDD0D7CC9,
398 [112] = 0x5005713C,
399 [113] = 0x270241AA,
400 [114] = 0xBE0B1010,
401 [115] = 0xC90C2086,
402 [116] = 0x5768B525,
403 [117] = 0x206F85B3,
404 [118] = 0xB966D409,
405 [119] = 0xCE61E49F,
406 [120] = 0x5EDEF90E,
407 [121] = 0x29D9C998,
408 [122] = 0xB0D09822,
409 [123] = 0xC7D7A8B4,
410 [124] = 0x59B33D17,
411 [125] = 0x2EB40D81,
412 [126] = 0xB7BD5C3B,
413 [127] = 0xC0BA6CAD,
414 [128] = 0xEDB88320,
415 [129] = 0x9ABFB3B6,
416 [130] = 0x3B6E20C,
417 [131] = 0x74B1D29A,
418 [132] = 0xEAD54739,
419 [133] = 0x9DD277AF,
420 [134] = 0x4DB2615,
421 [135] = 0x73DC1683,
422 [136] = 0xE3630B12,
423 [137] = 0x94643B84,
424 [138] = 0xD6D6A3E,
425 [139] = 0x7A6A5AA8,
426 [140] = 0xE40ECF0B,
427 [141] = 0x9309FF9D,
428 [142] = 0xA00AE27,
429 [143] = 0x7D079EB1,
430 [144] = 0xF00F9344,
431 [145] = 0x8708A3D2,
432 [146] = 0x1E01F268,
433 [147] = 0x6906C2FE,
434 [148] = 0xF762575D,
435 [149] = 0x806567CB,
436 [150] = 0x196C3671,
437 [151] = 0x6E6B06E7,
438 [152] = 0xFED41B76,
439 [153] = 0x89D32BE0,
440 [154] = 0x10DA7A5A,
441 [155] = 0x67DD4ACC,
442 [156] = 0xF9B9DF6F,
443 [157] = 0x8EBEEFF9,
444 [158] = 0x17B7BE43,
445 [159] = 0x60B08ED5,
446 [160] = 0xD6D6A3E8,
447 [161] = 0xA1D1937E,
448 [162] = 0x38D8C2C4,
449 [163] = 0x4FDFF252,
450 [164] = 0xD1BB67F1,
451 [165] = 0xA6BC5767,
452 [166] = 0x3FB506DD,
453 [167] = 0x48B2364B,
454 [168] = 0xD80D2BDA,
455 [169] = 0xAF0A1B4C,
456 [170] = 0x36034AF6,
457 [171] = 0x41047A60,
458 [172] = 0xDF60EFC3,
459 [173] = 0xA867DF55,
460 [174] = 0x316E8EEF,
461 [175] = 0x4669BE79,
462 [176] = 0xCB61B38C,
463 [177] = 0xBC66831A,
464 [178] = 0x256FD2A0,
465 [179] = 0x5268E236,
466 [180] = 0xCC0C7795,
467 [181] = 0xBB0B4703,
468 [182] = 0x220216B9,
469 [183] = 0x5505262F,
470 [184] = 0xC5BA3BBE,
471 [185] = 0xB2BD0B28,
472 [186] = 0x2BB45A92,
473 [187] = 0x5CB36A04,
474 [188] = 0xC2D7FFA7,
475 [189] = 0xB5D0CF31,
476 [190] = 0x2CD99E8B,
477 [191] = 0x5BDEAE1D,
478 [192] = 0x9B64C2B0,
479 [193] = 0xEC63F226,
480 [194] = 0x756AA39C,
481 [195] = 0x26D930A,
482 [196] = 0x9C0906A9,
483 [197] = 0xEB0E363F,
484 [198] = 0x72076785,
485 [199] = 0x5005713,
486 [200] = 0x95BF4A82,
487 [201] = 0xE2B87A14,
488 [202] = 0x7BB12BAE,
489 [203] = 0xCB61B38,
490 [204] = 0x92D28E9B,
491 [205] = 0xE5D5BE0D,
492 [206] = 0x7CDCEFB7,
493 [207] = 0xBDBDF21,
494 [208] = 0x86D3D2D4,
495 [209] = 0xF1D4E242,
496 [210] = 0x68DDB3F8,
497 [211] = 0x1FDA836E,
498 [212] = 0x81BE16CD,
499 [213] = 0xF6B9265B,
500 [214] = 0x6FB077E1,
501 [215] = 0x18B74777,
502 [216] = 0x88085AE6,
503 [217] = 0xFF0F6A70,
504 [218] = 0x66063BCA,
505 [219] = 0x11010B5C,
506 [220] = 0x8F659EFF,
507 [221] = 0xF862AE69,
508 [222] = 0x616BFFD3,
509 [223] = 0x166CCF45,
510 [224] = 0xA00AE278,
511 [225] = 0xD70DD2EE,
512 [226] = 0x4E048354,
513 [227] = 0x3903B3C2,
514 [228] = 0xA7672661,
515 [229] = 0xD06016F7,
516 [230] = 0x4969474D,
517 [231] = 0x3E6E77DB,
518 [232] = 0xAED16A4A,
519 [233] = 0xD9D65ADC,
520 [234] = 0x40DF0B66,
521 [235] = 0x37D83BF0,
522 [236] = 0xA9BCAE53,
523 [237] = 0xDEBB9EC5,
524 [238] = 0x47B2CF7F,
525 [239] = 0x30B5FFE9,
526 [240] = 0xBDBDF21C,
527 [241] = 0xCABAC28A,
528 [242] = 0x53B39330,
529 [243] = 0x24B4A3A6,
530 [244] = 0xBAD03605,
531 [245] = 0xCDD70693,
532 [246] = 0x54DE5729,
533 [247] = 0x23D967BF,
534 [248] = 0xB3667A2E,
535 [249] = 0xC4614AB8,
536 [250] = 0x5D681B02,
537 [251] = 0x2A6F2B94,
538 [252] = 0xB40BBE37,
539 [253] = 0xC30C8EA1,
540 [254] = 0x5A05DF1B,
541 [255] = 0x2D02EF8D,
542};
543#endif
544
545#if defined(SOCCFG_CRC32) && (1 == SOCCFG_CRC32)
546extern
548 bool refin, xwu32_t plynml, xwu32_t direction,
549 const xwu8_t stream[], xwsz_t * size);
550#else
551# define soc_crc32_cal(crc32, refin, plynml, direction, stream, size) (-EOPNOTSUPP)
552#endif
553
554static __xwlib_code
555void xwlib_crc32_swcal_ls(xwu32_t * crc32,
556 bool refin, const xwu32_t table[],
557 const xwu8_t stream[], xwsz_t * size);
558
559static __xwlib_code
560void xwlib_crc32_swcal_rs(xwu32_t * crc32,
561 bool refin, const xwu32_t table[],
562 const xwu8_t stream[], xwsz_t * size);
563
564static __xwlib_code
566 bool refin, xwu32_t plynml, xwu32_t direction,
567 const xwu8_t stream[], xwsz_t * size);
568
581static __xwlib_code
583 bool refin, const xwu32_t table[],
584 const xwu8_t stream[], xwsz_t * size)
585{
586 xwsz_t i;
587 xwu8_t index;
588 xwu8_t byte;
589 xwu32_t remainder = *crc32;
590
591 for (i = 0; i < *size; i++) {
592 if (refin) {
593 byte = xwbop_rbit8(stream[i]);
594 } else {
595 byte = stream[i];
596 }
597 index = ((xwu8_t)(remainder >> (xwu32_t)24) ^ byte);
598 remainder = table[index] ^ (remainder << 8);
599 }
600 *crc32 = remainder;
601 *size = 0;
602}
603
616static __xwlib_code
618 bool refin, const xwu32_t table[],
619 const xwu8_t stream[], xwsz_t * size)
620{
621 xwsz_t i;
622 xwu8_t index;
623 xwu8_t byte;
624 xwu32_t remainder = *crc32;
625
626 for (i = 0; i < *size; i++) {
627 if (refin) {
628 byte = xwbop_rbit8(stream[i]);
629 } else {
630 byte = stream[i];
631 }
632 index = ((xwu8_t)(remainder & (xwu32_t)0xFF) ^ byte);
633 remainder = table[index] ^ (remainder >> 8);
634 }
635 *crc32 = remainder;
636 *size = 0;
637}
638
655static __xwlib_code
657 bool refin, xwu32_t plynml, xwu32_t direction,
658 const xwu8_t stream[], xwsz_t * size)
659{
660 xwer_t rc;
661
662 // cppcheck-suppress [misra-c2012-16.6]
663 switch (plynml) {
664#if defined(XWLIBCFG_CRC32_0X04C11DB7) && (1 == XWLIBCFG_CRC32_0X04C11DB7)
665 case (xwu32_t)0x04C11DB7:
666 if ((xwu32_t)XWLIB_CRC32_LEFT_SHIFT == direction) {
668 stream, size);
669 } else {
671 stream, size);
672 }
673 rc = XWOK;
674 break;
675#endif
676
677#if defined(XWLIBCFG_CRC32_0XEDB88320) && (1 == XWLIBCFG_CRC32_0XEDB88320)
678 case (xwu32_t)0xEDB88320:
679 if ((xwu32_t)XWLIB_CRC32_RIGHT_SHIFT == direction) {
681 stream, size);
682 } else {
684 stream, size);
685 }
686 rc = XWOK;
687 break;
688#endif
689 default:
690 XWOS_UNUSED(crc32);
691 XWOS_UNUSED(refin);
692 XWOS_UNUSED(plynml);
693 XWOS_UNUSED(direction);
694 XWOS_UNUSED(stream);
695 XWOS_UNUSED(size);
696 rc = -EOPNOTSUPP;
697 break;
698 }
699 return rc;
700}
701
704 bool refin, bool refout,
705 xwu32_t plynml, xwu32_t direction,
706 const xwu8_t stream[], xwsz_t * size)
707{
708 xwer_t rc;
709 xwsz_t total;
710 xwsz_t pos;
711 xwu32_t res;
712
713 XWOS_VALIDATE((crc32), "nullptr", -EFAULT);
714 XWOS_VALIDATE((size), "nullptr", -EFAULT);
715
716 total = *size;
717 res = *crc32;
718 pos = 0;
719 /* 使用硬件计算部分CRC32校验值 */
720 rc = soc_crc32_cal(&res, refin, plynml, direction, &stream[0], size);
721 if (*size > 0) {
722 /* 使用软件计算剩余部分的CRC32校验值 */
723 pos = total - *size;
724 rc = xwlib_crc32_swcal(&res,
725 refin, plynml, direction,
726 &stream[pos], size);
727 pos = total - *size;
728 }
729 if (XWOK == rc) {
730 if (0 == *size) {
731 if (refout) {
732 res = xwbop_rbit32(res);
733 }
734 res = res ^ xorout;
735 }
736 *crc32 = res;
737 }
738 return rc;
739}
740
742xwu32_t xwlib_crc32_calms(const xwu8_t stream[], xwsz_t * size)
743{
744 xwu32_t result;
745
746 result = (xwu32_t)0xFFFFFFFF;
747 // cppcheck-suppress [misra-c2012-17.7]
748 xwlib_crc32_cal(&result, (xwu32_t)0xFFFFFFFF, false, false,
749 (xwu32_t)0xEDB88320, XWLIB_CRC32_RIGHT_SHIFT,
750 stream, size);
751 return result;
752}
xwer_t soc_crc32_cal(xwu32_t *crc32, bool refin, xwu32_t plynml, xwu32_t direction, const xwu8_t stream[], xwsz_t *size)
static xwer_t xwlib_crc32_swcal(xwu32_t *crc32, bool refin, xwu32_t plynml, xwu32_t direction, const xwu8_t stream[], xwsz_t *size)
软件方式计算一段数据的CRC32校验值
Definition crc32.c:656
static void xwlib_crc32_swcal_rs(xwu32_t *crc32, bool refin, const xwu32_t table[], const xwu8_t stream[], xwsz_t *size)
右移计算一段数据的CRC32校验值(直驱表法)
Definition crc32.c:617
static void xwlib_crc32_swcal_ls(xwu32_t *crc32, bool refin, const xwu32_t table[], const xwu8_t stream[], xwsz_t *size)
左移计算一段数据的CRC32校验值(直驱表法)
Definition crc32.c:582
XWOS通用库:CRC32
#define __xwlib_rodata
Definition compiler.h:211
#define __xwlib_code
Definition compiler.h:199
xwu32_t xwlib_crc32_calms(const xwu8_t stream[], xwsz_t *size)
用主流CRC32参数模型计算一段数据的校验值
Definition crc32.c:742
const xwu32_t xwlib_crc32tbl_0xedb88320[256]
CRC32多项式0XEDB88320的查询表
Definition crc32.c:285
const xwu32_t xwlib_crc32tbl_0x04c11db7[256]
CRC32多项式0x04C11DB7的查询表
Definition crc32.c:21
xwer_t xwlib_crc32_cal(xwu32_t *crc32, xwu32_t xorout, bool refin, bool refout, xwu32_t plynml, xwu32_t direction, const xwu8_t stream[], xwsz_t *size)
计算一段数据的CRC32校验值
Definition crc32.c:703
@ XWLIB_CRC32_RIGHT_SHIFT
Definition crc32.h:32
@ XWLIB_CRC32_LEFT_SHIFT
Definition crc32.h:31
#define EFAULT
Bad address
Definition errno.h:44
#define EOPNOTSUPP
Operation not supported on socket
Definition errno.h:115
#define XWOK
No error
Definition errno.h:182
signed long xwer_t
Definition type.h:554
unsigned long xwsz_t
Definition type.h:339
uint8_t xwu8_t
Definition type.h:194
uint32_t xwu32_t
Definition type.h:266
xwu8_t xwbop_rbit8(xwu8_t x)
xwu32_t xwbop_rbit32(xwu32_t x)
#define XWOS_VALIDATE(exp, errstr,...)
检查函数参数是否有效
Definition standard.h:76
#define XWOS_UNUSED(x)
Definition standard.h:66
XWOS通用库:位操作
XWOS的标准头文件