1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - MATH - include
3   File:     math/crc.h
4 
5   Copyright 2003-2008 Nintendo. All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law. They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Date::            $
14   $Rev:$
15   $Author:$
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NITRO_MATH_CRC_H_
19 #define NITRO_MATH_CRC_H_
20 
21 #include <nitro/misc.h>
22 #include <nitro/types.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 //----------------------------------------------------------------------------
29 // Constant Definitions
30 //----------------------------------------------------------------------------
31 
32 #define MATH_CRC8_STANDARD_POLY     0x07
33 #define MATH_CRC8_STANDARD_INIT     0
34 
35 #define MATH_CRC16_STANDARD_POLY    0xa001      // Items that carry out bit inversion also invert generator polynomials.
36 #define MATH_CRC16_STANDARD_INIT    0
37 #define MATH_CRC16_CCITT_POLY       0x1021
38 #define MATH_CRC16_CCITT_INIT       0xffff
39 
40 #define MATH_CRC32_STANDARD_POLY    0xedb88320  // Items that carry out bit inversion also invert generator polynomials.
41 #define MATH_CRC32_STANDARD_INIT    0xffffffff
42 #define MATH_CRC32_POSIX_POLY       0x04c11db7
43 #define MATH_CRC32_POSIX_INIT       0
44 
45 //----------------------------------------------------------------------------
46 // Type Definitions
47 //----------------------------------------------------------------------------
48 
49 typedef u8 MATHCRC8Context;
50 typedef u16 MATHCRC16Context;
51 typedef u32 MATHCRC32Context;
52 
53 typedef struct MATHCRC8Table
54 {
55     u8      table[256];
56 }
57 MATHCRC8Table;
58 
59 typedef struct MATHCRC16Table
60 {
61     u16     table[256];
62 }
63 MATHCRC16Table;
64 
65 typedef struct MATHCRC32Table
66 {
67     u32     table[256];
68 }
69 MATHCRC32Table;
70 
71 //----------------------------------------------------------------------------
72 // Function Declarations
73 //----------------------------------------------------------------------------
74 
75 //----------------------------------------------------------------------------
76 // Inline Function Implementation
77 //----------------------------------------------------------------------------
78 
79 /*****************************************************************************/
80 /* CRC-8 Common                                                               */
81 /*****************************************************************************/
82 
83 /*---------------------------------------------------------------------------*
84   Name:         MATHi_CRC8InitTable
85 
86   Description:  Initializes the MATHCRC8Table structure used for requesting the CRC-8 value.
87 
88   Arguments:    table: MATHCRC8Table structure.
89                 poly:  Bit representation of the generator polynomial with the top bit removed.
90 
91   Returns:      None.
92  *---------------------------------------------------------------------------*/
93 void    MATHi_CRC8InitTable(MATHCRC8Table * table, u8 poly);
94 
95 /*---------------------------------------------------------------------------*
96   Name:         MATHi_CRC8InitTableRev
97 
98   Description:  Initializes the MATHCRC8Table structure used for requesting the CRC-8 value.
99                 The lower-order bit is handled as the higher-order digit.
100 
101   Arguments:    table: MATHCRC8Table structure.
102                 poly:  Inverted bit representation of the generator polynomial with the top bit removed.
103 
104 
105   Returns:      None.
106  *---------------------------------------------------------------------------*/
107 void    MATHi_CRC8InitTableRev(MATHCRC8Table * table, u8 poly);
108 
109 /*---------------------------------------------------------------------------*
110   Name:         MATHi_CRC8Init
111 
112   Description:  Initializes the MATHCRC8Context structure used for requesting the CRC-8 value.
113 
114   Arguments:    context:  MATHCRC8Context structure.
115                 init:    Initial value of CRC.
116 
117   Returns:      None.
118  *---------------------------------------------------------------------------*/
MATHi_CRC8Init(MATHCRC8Context * context,u8 init)119 static inline void MATHi_CRC8Init(MATHCRC8Context * context, u8 init)
120 {
121     *context = init;
122 }
123 
124 /*---------------------------------------------------------------------------*
125   Name:         MATHi_CRC8Update
126 
127   Description:  Updates the CRC-8 value with added data.
128 
129   Arguments:    table:   Pointer to the table for calculation, MATHCRC8Table.
130                 context:  MATHCRC8Context structure.
131                 input:   Pointer to input data.
132                 length:  Length of input data.
133 
134   Returns:      None.
135  *---------------------------------------------------------------------------*/
136 void
137 
138  MATHi_CRC8Update(const MATHCRC8Table * table, MATHCRC8Context * context, const void *input,
139                   u32 length);
140 
141 /*---------------------------------------------------------------------------*
142   Name:         MATHi_CRC8UpdateRev
143 
144   Description:  Updates the CRC-8 value with added data.
145                 The lower-order bit is handled as the higher-order digit.
146 
147   Arguments:    table:   Pointer to the table for calculation, MATHCRC8Table.
148                 context:  MATHCRC8Context structure.
149                 input:   Pointer to input data.
150                 length:  Length of input data.
151 
152   Returns:      None.
153  *---------------------------------------------------------------------------*/
154 static inline void
MATHi_CRC8UpdateRev(const MATHCRC8Table * table,MATHCRC8Context * context,const void * input,u32 length)155 MATHi_CRC8UpdateRev(const MATHCRC8Table * table, MATHCRC8Context * context, const void *input,
156                     u32 length)
157 {
158     MATHi_CRC8Update(table, context, input, length);
159 }
160 
161 /*---------------------------------------------------------------------------*
162   Name:         MATHi_CRC8GetHash
163 
164   Description:  Gets the final CRC-8 value.
165 
166   Arguments:    context:  MATHCRC8Context structure.
167 
168   Returns:      Calculation result
169  *---------------------------------------------------------------------------*/
MATHi_CRC8GetHash(MATHCRC8Context * context)170 static inline u8 MATHi_CRC8GetHash(MATHCRC8Context * context)
171 {
172     return (u8)*context;
173 }
174 
175 /*****************************************************************************/
176 /* CRC-8                                                                    */
177 /*****************************************************************************/
178 
179 /*---------------------------------------------------------------------------*
180   Name:         MATH_CRC8InitTable
181 
182   Description:  Initializes the MATHCRC8Table structure used for requesting the CRC-8 value.
183 
184   Arguments:    table: MATHCRC8Table structure.
185 
186   Returns:      None.
187  *---------------------------------------------------------------------------*/
MATH_CRC8InitTable(MATHCRC8Table * table)188 static inline void MATH_CRC8InitTable(MATHCRC8Table * table)
189 {
190     MATHi_CRC8InitTable(table, MATH_CRC8_STANDARD_POLY);
191 }
192 
193 /*---------------------------------------------------------------------------*
194   Name:         MATH_CRC8Init
195 
196   Description:  Initializes the MATHCRC8Context structure used for requesting the CRC-8 value.
197 
198   Arguments:    context:  MATHCRC8Context structure.
199 
200   Returns:      None.
201  *---------------------------------------------------------------------------*/
MATH_CRC8Init(MATHCRC8Context * context)202 static inline void MATH_CRC8Init(MATHCRC8Context * context)
203 {
204     MATHi_CRC8Init(context, MATH_CRC8_STANDARD_INIT);
205 }
206 
207 /*---------------------------------------------------------------------------*
208   Name:         MATH_CRC8Update
209 
210   Description:  Updates the CRC-8 value with added data.
211 
212   Arguments:    table:   Pointer to the table for calculation, MATHCRC8Table.
213                 context:  MATHCRC8Context structure.
214                 input:   Pointer to input data.
215                 length:  Length of input data.
216 
217   Returns:      None.
218  *---------------------------------------------------------------------------*/
219 static inline void
MATH_CRC8Update(const MATHCRC8Table * table,MATHCRC8Context * context,const void * input,u32 length)220 MATH_CRC8Update(const MATHCRC8Table * table, MATHCRC8Context * context, const void *input,
221                 u32 length)
222 {
223     MATHi_CRC8Update(table, context, input, length);
224 }
225 
226 /*---------------------------------------------------------------------------*
227   Name:         MATH_CRC8GetHash
228 
229   Description:  Gets the final CRC-8 value.
230 
231   Arguments:    context:  MATHCRC8Context structure.
232 
233   Returns:      Calculation result
234  *---------------------------------------------------------------------------*/
MATH_CRC8GetHash(MATHCRC8Context * context)235 static inline u8 MATH_CRC8GetHash(MATHCRC8Context * context)
236 {
237     return MATHi_CRC8GetHash(context);
238 }
239 
240 /*****************************************************************************/
241 /* CRC-16 Common                                                               */
242 /*****************************************************************************/
243 
244 /*---------------------------------------------------------------------------*
245   Name:         MATHi_CRC16InitTable
246 
247   Description:  Initializes the MATHCRC16Table structure used for requesting the CRC-16 value.
248 
249   Arguments:    table:  MATHCRC16Table structure.
250                 poly:  Bit representation of the generator polynomial with the top bit removed.
251 
252   Returns:      None.
253  *---------------------------------------------------------------------------*/
254 void    MATHi_CRC16InitTable(MATHCRC16Table * table, u16 poly);
255 
256 /*---------------------------------------------------------------------------*
257   Name:         MATHi_CRC16InitTableRev
258 
259   Description:  Initializes the MATHCRC16Table structure used for requesting the CRC-16 value.
260                 The lower-order bit is handled as the higher-order digit.
261 
262   Arguments:    table:  MATHCRC16Table structure.
263                 poly:  Inverted bit representation of the generator polynomial with the top bit removed.
264 
265 
266   Returns:      None.
267  *---------------------------------------------------------------------------*/
268 void    MATHi_CRC16InitTableRev(MATHCRC16Table * table, u16 poly);
269 
270 /*---------------------------------------------------------------------------*
271   Name:         MATHi_CRC16Init
272 
273   Description:  Initializes the MATHCRC16Context structure used for requesting the CRC-16 value.
274 
275   Arguments:    context:   MATHCRC16Context structure.
276                 init:    Initial value of CRC.
277 
278   Returns:      None.
279  *---------------------------------------------------------------------------*/
MATHi_CRC16Init(MATHCRC16Context * context,u16 init)280 static inline void MATHi_CRC16Init(MATHCRC16Context * context, u16 init)
281 {
282     *context = init;
283 }
284 
285 /*---------------------------------------------------------------------------*
286   Name:         MATHi_CRC16Update
287 
288   Description:  Updates the CRC-16 value with added data.
289 
290   Arguments:    table:   Pointer to the table for calculation, MATHCRC16Table.
291                 context:   MATHCRC16Context structure.
292                 input:   Pointer to input data.
293                 length:  Length of input data.
294 
295   Returns:      None.
296  *---------------------------------------------------------------------------*/
297 void
298 
299  MATHi_CRC16Update(const MATHCRC16Table * table, MATHCRC16Context * context, const void *input,
300                    u32 length);
301 
302 /*---------------------------------------------------------------------------*
303   Name:         MATHi_CRC16UpdateRev
304 
305   Description:  Updates the CRC-16 value with added data.
306                 The lower-order bit is handled as the higher-order digit.
307 
308   Arguments:    table:   Pointer to the table for calculation, MATHCRC16Table.
309                 context:   MATHCRC16Context structure.
310                 input:   Pointer to input data.
311                 length:  Length of input data.
312 
313   Returns:      None.
314  *---------------------------------------------------------------------------*/
315 void
316 
317  MATHi_CRC16UpdateRev(const MATHCRC16Table * table, MATHCRC16Context * context, const void *input,
318                       u32 length);
319 
320 /*---------------------------------------------------------------------------*
321   Name:         MATHi_CRC16GetHash
322 
323   Description:  Gets the final CRC-16 value.
324 
325   Arguments:    context:   MATHCRC16Context structure.
326 
327   Returns:      Calculation result
328  *---------------------------------------------------------------------------*/
MATHi_CRC16GetHash(MATHCRC16Context * context)329 static inline u16 MATHi_CRC16GetHash(MATHCRC16Context * context)
330 {
331     return (u16)*context;
332 }
333 
334 /*****************************************************************************/
335 /* CRC-16/CCITT(X.25)                                                        */
336 /*****************************************************************************/
337 
338 /*---------------------------------------------------------------------------*
339   Name:         MATH_CRC16CCITTInitTable
340 
341   Description:  Initializes the MATHCRC16Table structure used for requesting the CRC-16/CCITT values.
342 
343   Arguments:    table:  MATHCRC16Table structure.
344 
345   Returns:      None.
346  *---------------------------------------------------------------------------*/
MATH_CRC16CCITTInitTable(MATHCRC16Table * table)347 static inline void MATH_CRC16CCITTInitTable(MATHCRC16Table * table)
348 {
349     MATHi_CRC16InitTable(table, MATH_CRC16_CCITT_POLY);
350 }
351 
352 /*---------------------------------------------------------------------------*
353   Name:         MATH_CRC16CCITTInit
354 
355   Description:  Initializes the MATHCRC16Context structure used for requesting the CRC-16/CCITT values.
356 
357   Arguments:    context:   MATHCRC16Context structure.
358 
359   Returns:      None.
360  *---------------------------------------------------------------------------*/
MATH_CRC16CCITTInit(MATHCRC16Context * context)361 static inline void MATH_CRC16CCITTInit(MATHCRC16Context * context)
362 {
363     MATHi_CRC16Init(context, MATH_CRC16_CCITT_INIT);
364 }
365 
366 /*---------------------------------------------------------------------------*
367   Name:         MATH_CRC16CCITTUpdate
368 
369   Description:  Updates the CRC-16/CCITT values with added data.
370 
371   Arguments:    table:   Pointer to the table for calculation, MATHCRC16Table.
372                 context:   MATHCRC16Context structure.
373                 input:   Pointer to input data.
374                 length:  Length of input data.
375 
376   Returns:      None.
377  *---------------------------------------------------------------------------*/
378 static inline void
MATH_CRC16CCITTUpdate(const MATHCRC16Table * table,MATHCRC16Context * context,const void * input,u32 length)379 MATH_CRC16CCITTUpdate(const MATHCRC16Table * table, MATHCRC16Context * context, const void *input,
380                       u32 length)
381 {
382     MATHi_CRC16Update(table, context, input, length);
383 }
384 
385 /*---------------------------------------------------------------------------*
386   Name:         MATH_CRC16CCITTGetHash
387 
388   Description:  Gets the final CRC-16/CCITT values.
389 
390   Arguments:    context:   MATHCRC16Context structure.
391 
392   Returns:      Calculation result
393  *---------------------------------------------------------------------------*/
MATH_CRC16CCITTGetHash(MATHCRC16Context * context)394 static inline u16 MATH_CRC16CCITTGetHash(MATHCRC16Context * context)
395 {
396     return MATHi_CRC16GetHash(context);
397 }
398 
399 /*****************************************************************************/
400 /* CRC-16                                                                    */
401 /*****************************************************************************/
402 
403 /*---------------------------------------------------------------------------*
404   Name:         MATH_CRC16ARCInitTable
405 
406   Description:  Initializes the MATHCRC16Table structure used for requesting the CRC-16 value.
407 
408   Arguments:    table:  MATHCRC16Table structure.
409 
410   Returns:      None.
411  *---------------------------------------------------------------------------*/
MATH_CRC16InitTable(MATHCRC16Table * table)412 static inline void MATH_CRC16InitTable(MATHCRC16Table * table)
413 {
414     MATHi_CRC16InitTableRev(table, MATH_CRC16_STANDARD_POLY);
415 }
416 
417 /*---------------------------------------------------------------------------*
418   Name:         MATH_CRC16ARCInit
419 
420   Description:  Initializes the MATHCRC16Context structure used for requesting the CRC-16 value.
421 
422   Arguments:    context:   MATHCRC16Context structure.
423 
424   Returns:      None.
425  *---------------------------------------------------------------------------*/
MATH_CRC16Init(MATHCRC16Context * context)426 static inline void MATH_CRC16Init(MATHCRC16Context * context)
427 {
428     MATHi_CRC16Init(context, MATH_CRC16_STANDARD_INIT);
429 }
430 
431 /*---------------------------------------------------------------------------*
432   Name:         MATH_CRC16ARCUpdate
433 
434   Description:  Updates the CRC-16 value with added data.
435 
436   Arguments:    table:   Pointer to the table for calculation, MATHCRC16Table.
437                 context:   MATHCRC16Context structure.
438                 input:   Pointer to input data.
439                 length:  Length of input data.
440 
441   Returns:      None.
442  *---------------------------------------------------------------------------*/
443 static inline void
MATH_CRC16Update(const MATHCRC16Table * table,MATHCRC16Context * context,const void * input,u32 length)444 MATH_CRC16Update(const MATHCRC16Table * table, MATHCRC16Context * context, const void *input,
445                  u32 length)
446 {
447     MATHi_CRC16UpdateRev(table, context, input, length);
448 }
449 
450 /*---------------------------------------------------------------------------*
451   Name:         MATH_CRC16ARCGetHash
452 
453   Description:  Gets the final CRC-16 value.
454 
455   Arguments:    context:   MATHCRC16Context structure.
456 
457   Returns:      Calculation result
458  *---------------------------------------------------------------------------*/
MATH_CRC16GetHash(MATHCRC16Context * context)459 static inline u16 MATH_CRC16GetHash(MATHCRC16Context * context)
460 {
461     return MATHi_CRC16GetHash(context);
462 }
463 
464 /*****************************************************************************/
465 /* CRC-32 Common                                                               */
466 /*****************************************************************************/
467 
468 /*---------------------------------------------------------------------------*
469   Name:         MATHi_CRC32InitTable
470 
471   Description:  Initializes the MATHCRC32Table structure used for requesting the CRC-32 value.
472 
473   Arguments:    table:   MATHCRC32Table structure.
474                 poly:  Bit representation of the generator polynomial with the top bit removed.
475 
476   Returns:      None.
477  *---------------------------------------------------------------------------*/
478 void    MATHi_CRC32InitTable(MATHCRC32Table * table, u32 poly);
479 
480 /*---------------------------------------------------------------------------*
481   Name:         MATHi_CRC16InitTableRev
482 
483   Description:  Initializes the MATHCRC16Table structure used for requesting the CRC-32 value.
484                 The lower-order bit is handled as the higher-order digit.
485 
486   Arguments:    table:  MATHCRC16Table structure.
487                 poly:  Inverted bit representation of the generator polynomial with the top bit removed.
488 
489 
490   Returns:      None.
491  *---------------------------------------------------------------------------*/
492 void    MATHi_CRC32InitTableRev(MATHCRC32Table * table, u32 poly);
493 
494 /*---------------------------------------------------------------------------*
495   Name:         MATHi_CRC32Init
496 
497   Description:  Initializes the MATHCRC32Context structure used for requesting the CRC-32 value.
498 
499   Arguments:    context:   MATHCRC32Context structure.
500                 init:    Initial value of CRC.
501 
502   Returns:      None.
503  *---------------------------------------------------------------------------*/
MATHi_CRC32Init(MATHCRC32Context * context,u32 init)504 static inline void MATHi_CRC32Init(MATHCRC32Context * context, u32 init)
505 {
506     *context = init;
507 }
508 
509 /*---------------------------------------------------------------------------*
510   Name:         MATHi_CRC32Update
511 
512   Description:  Updates the CRC-32 value with added data.
513 
514   Arguments:    table:   Pointer to the table for calculation, MATHCRC32Table.
515                 context:   MATHCRC32Context structure.
516                 input:   Pointer to input data.
517                 length:  Length of input data.
518 
519   Returns:      None.
520  *---------------------------------------------------------------------------*/
521 void
522 
523  MATHi_CRC32Update(const MATHCRC32Table * table, MATHCRC32Context * context, const void *input,
524                    u32 length);
525 
526 /*---------------------------------------------------------------------------*
527   Name:         MATHi_CRC32UpdateRev
528 
529   Description:  Updates the CRC-32 value with added data.
530                 The lower-order bit is handled as the higher-order digit.
531 
532   Arguments:    table:   Pointer to the table for calculation, MATHCRC32Table.
533                 context:   MATHCRC32Context structure.
534                 input:   Pointer to input data.
535                 length:  Length of input data.
536 
537   Returns:      None.
538  *---------------------------------------------------------------------------*/
539 void
540 
541  MATHi_CRC32UpdateRev(const MATHCRC32Table * table, MATHCRC32Context * context, const void *input,
542                       u32 length);
543 
544 /*---------------------------------------------------------------------------*
545   Name:         MATHi_CRC32GetHash
546 
547   Description:  Gets the final CRC-32 value.
548 
549   Arguments:    context:   MATHCRC32Context structure.
550 
551   Returns:      Calculation result
552  *---------------------------------------------------------------------------*/
MATHi_CRC32GetHash(MATHCRC32Context * context)553 static inline u32 MATHi_CRC32GetHash(MATHCRC32Context * context)
554 {
555     return (u32)*context;
556 }
557 
558 /*****************************************************************************/
559 /* CRC-32                                                                    */
560 /*****************************************************************************/
561 
562 /*---------------------------------------------------------------------------*
563   Name:         MATH_CRC32InitTable
564 
565   Description:  Initializes the MATHCRC32Table structure used for requesting the CRC-32 value.
566 
567   Arguments:    table:   MATHCRC32Table structure.
568 
569   Returns:      None.
570  *---------------------------------------------------------------------------*/
MATH_CRC32InitTable(MATHCRC32Table * table)571 static inline void MATH_CRC32InitTable(MATHCRC32Table * table)
572 {
573     MATHi_CRC32InitTableRev(table, MATH_CRC32_STANDARD_POLY);
574 }
575 
576 /*---------------------------------------------------------------------------*
577   Name:         MATH_CRC32Init
578 
579   Description:  Initializes the MATHCRC32Context structure used for requesting the CRC-32 value.
580 
581   Arguments:    context:   MATHCRC32Context structure.
582 
583   Returns:      None.
584  *---------------------------------------------------------------------------*/
MATH_CRC32Init(MATHCRC32Context * context)585 static inline void MATH_CRC32Init(MATHCRC32Context * context)
586 {
587     MATHi_CRC32Init(context, MATH_CRC32_STANDARD_INIT);
588 }
589 
590 /*---------------------------------------------------------------------------*
591   Name:         MATH_CRC32Update
592 
593   Description:  Updates the CRC-32 value with added data.
594 
595   Arguments:    table:   Pointer to the table for calculation, MATHCRC32Table.
596                 context:   MATHCRC32Context structure.
597                 input:   Pointer to input data.
598                 length:  Length of input data.
599 
600   Returns:      None.
601  *---------------------------------------------------------------------------*/
602 static inline void
MATH_CRC32Update(const MATHCRC32Table * table,MATHCRC32Context * context,const void * input,u32 length)603 MATH_CRC32Update(const MATHCRC32Table * table, MATHCRC32Context * context, const void *input,
604                  u32 length)
605 {
606     MATHi_CRC32UpdateRev(table, context, input, length);
607 }
608 
609 /*---------------------------------------------------------------------------*
610   Name:         MATH_CRC32GetHash
611 
612   Description:  Gets the final CRC-32 value.
613 
614   Arguments:    context:   MATHCRC32Context structure.
615 
616   Returns:      Calculation result
617  *---------------------------------------------------------------------------*/
MATH_CRC32GetHash(MATHCRC32Context * context)618 static inline u32 MATH_CRC32GetHash(MATHCRC32Context * context)
619 {
620     return (u32)(~MATHi_CRC32GetHash(context));
621 }
622 
623 /*****************************************************************************/
624 /* CRC-32/POSIX 1003.2                                                       */
625 /*****************************************************************************/
626 
627 /*---------------------------------------------------------------------------*
628   Name:         MATH_CRC32POSIXInitTable
629 
630   Description:  Initializes the MATHCRC32Table structure used for requesting the CRC-32/POSIX value.
631 
632   Arguments:    table:   MATHCRC32Table structure.
633 
634   Returns:      None.
635  *---------------------------------------------------------------------------*/
MATH_CRC32POSIXInitTable(MATHCRC32Table * table)636 static inline void MATH_CRC32POSIXInitTable(MATHCRC32Table * table)
637 {
638     MATHi_CRC32InitTable(table, MATH_CRC32_POSIX_POLY);
639 }
640 
641 /*---------------------------------------------------------------------------*
642   Name:         MATH_CRC32POSIXInit
643 
644   Description:  Initializes the MATHCRC32Context structure used for requesting the CRC-32/POSIX value.
645 
646   Arguments:    context:   MATHCRC32Context structure.
647 
648   Returns:      None.
649  *---------------------------------------------------------------------------*/
MATH_CRC32POSIXInit(MATHCRC32Context * context)650 static inline void MATH_CRC32POSIXInit(MATHCRC32Context * context)
651 {
652     MATHi_CRC32Init(context, MATH_CRC32_POSIX_INIT);
653 }
654 
655 /*---------------------------------------------------------------------------*
656   Name:         MATH_CRC32POSIXUpdate
657 
658   Description:  Updates the CRC-32/POSIX values with added data.
659 
660   Arguments:    table:   Pointer to the table for calculation, MATHCRC32Table.
661                 context:   MATHCRC32Context structure.
662                 input:   Pointer to input data.
663                 length:  Length of input data.
664 
665   Returns:      None.
666  *---------------------------------------------------------------------------*/
667 static inline void
MATH_CRC32POSIXUpdate(const MATHCRC32Table * table,MATHCRC32Context * context,const void * input,u32 length)668 MATH_CRC32POSIXUpdate(const MATHCRC32Table * table, MATHCRC32Context * context, const void *input,
669                       u32 length)
670 {
671     MATHi_CRC32Update(table, context, input, length);
672 }
673 
674 /*---------------------------------------------------------------------------*
675   Name:         MATH_CRC32POSIXGetHash
676 
677   Description:  Gets the final CRC-32/POSIX values.
678 
679   Arguments:    context:   MATHCRC32Context structure.
680 
681   Returns:      Calculation result
682  *---------------------------------------------------------------------------*/
MATH_CRC32POSIXGetHash(MATHCRC32Context * context)683 static inline u32 MATH_CRC32POSIXGetHash(MATHCRC32Context * context)
684 {
685     return (u32)(~MATHi_CRC32GetHash(context));
686 }
687 
688 
689 /*****************************************************************************/
690 /* Utility Functions                                                        */
691 /*****************************************************************************/
692 
693 /*---------------------------------------------------------------------------*
694   Name:         MATH_CalcCRC8
695 
696   Description:  Calculates the CRC-8 value.
697 
698   Arguments:    table:   Pointer to the table for calculation, MATHCRC8Table.
699                 data:    Pointer to input data.
700                 dataLength:   Length of input data.
701 
702   Returns:      Calculation result
703  *---------------------------------------------------------------------------*/
704 u8      MATH_CalcCRC8(const MATHCRC8Table * table, const void *data, u32 dataLength);
705 
706 /*---------------------------------------------------------------------------*
707   Name:         MATH_CalcCRC16
708 
709   Description:  Calculates the CRC-16 value.
710 
711   Arguments:    table:   Pointer to the table for calculation, MATHCRC16Table.
712                 data:    Pointer to input data.
713                 dataLength:   Length of input data.
714 
715   Returns:      Calculation result
716  *---------------------------------------------------------------------------*/
717 u16     MATH_CalcCRC16(const MATHCRC16Table * table, const void *data, u32 dataLength);
718 
719 /*---------------------------------------------------------------------------*
720   Name:         MATH_CalcCRC16CCITT
721 
722   Description:  Calculates the CRC-16/CCITT values.
723 
724   Arguments:    table:   Pointer to the table for calculation, MATHCRC16Table.
725                 data:    Pointer to input data.
726   Arguments:    data:    Pointer to input data.
727                 dataLength:   Length of input data.
728 
729   Returns:      Calculation result
730  *---------------------------------------------------------------------------*/
731 u16     MATH_CalcCRC16CCITT(const MATHCRC16Table * table, const void *data, u32 dataLength);
732 
733 /*---------------------------------------------------------------------------*
734   Name:         MATH_CalcCRC32
735 
736   Description:  Calculates the CRC-32 value.
737 
738   Arguments:    table:   Pointer to the table for calculation, MATHCRC32Table.
739                 data:    Pointer to input data.
740                 dataLength:   Length of input data.
741 
742   Returns:      Calculation result
743  *---------------------------------------------------------------------------*/
744 u32     MATH_CalcCRC32(const MATHCRC32Table * table, const void *data, u32 dataLength);
745 
746 /*---------------------------------------------------------------------------*
747   Name:         MATH_CalcCRC32POSIX
748 
749   Description:  Calculates the CRC-32/POSIX values.
750 
751   Arguments:    table:   Pointer to the table for calculation, MATHCRC32Table.
752                 data:    Pointer to input data.
753                 dataLength:   Length of input data.
754 
755   Returns:      Calculation result
756  *---------------------------------------------------------------------------*/
757 u32     MATH_CalcCRC32POSIX(const MATHCRC32Table * table, const void *data, u32 dataLength);
758 
759 
760 
761 
762 
763 #ifdef __cplusplus
764 }/* extern "C" */
765 #endif
766 
767 /* NITRO_MATH_CRC_H_ */
768 #endif
769