Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
7.0 KiB

  1. /****************************************************************************/
  2. /* Start of crcmodel.h */
  3. /****************************************************************************/
  4. /* */
  5. /* Author : Ross Williams ([email protected].). */
  6. /* Date : 3 June 1993. */
  7. /* Status : Public domain. */
  8. /* */
  9. /* Description : This is the header (.h) file for the reference */
  10. /* implementation of the Rocksoft^tm Model CRC Algorithm. For more */
  11. /* information on the Rocksoft^tm Model CRC Algorithm, see the document */
  12. /* titled "A Painless Guide to CRC Error Detection Algorithms" by Ross */
  13. /* Williams ([email protected].). This document is likely to be in */
  14. /* "ftp.adelaide.edu.au/pub/rocksoft". */
  15. /* */
  16. /* Note: Rocksoft is a trademark of Rocksoft Pty Ltd, Adelaide, Australia. */
  17. /* */
  18. /****************************************************************************/
  19. /* */
  20. /* How to Use This Package */
  21. /* ----------------------- */
  22. /* Step 1: Declare a variable of type cm_t. Declare another variable */
  23. /* (p_cm say) of type p_cm_t and initialize it to point to the first*/
  24. /* variable (e.g. p_cm_t p_cm = &cm_t). */
  25. /* */
  26. /* Step 2: Assign values to the parameter fields of the structure. */
  27. /* If you don't know what to assign, see the document cited earlier.*/
  28. /* For example: */
  29. /* p_cm->cm_width = 16; */
  30. /* p_cm->cm_poly = 0x8005L; */
  31. /* p_cm->cm_init = 0L; */
  32. /* p_cm->cm_refin = TRUE; */
  33. /* p_cm->cm_refot = TRUE; */
  34. /* p_cm->cm_xorot = 0L; */
  35. /* Note: Poly is specified without its top bit (18005 becomes 8005).*/
  36. /* Note: Width is one bit less than the raw poly width. */
  37. /* */
  38. /* Step 3: Initialize the instance with a call cm_ini(p_cm); */
  39. /* */
  40. /* Step 4: Process zero or more message bytes by placing zero or more */
  41. /* successive calls to cm_nxt. Example: cm_nxt(p_cm,ch); */
  42. /* */
  43. /* Step 5: Extract the CRC value at any time by calling crc = cm_crc(p_cm); */
  44. /* If the CRC is a 16-bit value, it will be in the bottom 16 bits. */
  45. /* */
  46. /****************************************************************************/
  47. /* */
  48. /* Design Notes */
  49. /* ------------ */
  50. /* PORTABILITY: This package has been coded very conservatively so that */
  51. /* it will run on as many machines as possible. For example, all external */
  52. /* identifiers have been restricted to 6 characters and all internal ones to*/
  53. /* 8 characters. The prefix cm (for Crc Model) is used as an attempt to */
  54. /* avoid namespace collisions. This package is endian independent. */
  55. /* */
  56. /* EFFICIENCY: This package (and its interface) is not designed for */
  57. /* speed. The purpose of this package is to act as a well-defined reference */
  58. /* model for the specification of CRC algorithms. If you want speed, cook up*/
  59. /* a specific table-driven implementation as described in the document cited*/
  60. /* above. This package is designed for validation only; if you have found or*/
  61. /* implemented a CRC algorithm and wish to describe it as a set of para- */
  62. /* meters to the Rocksoft^tm Model CRC Algorithm, your CRC algorithm imple- */
  63. /* mentation should behave identically to this package under those para- */
  64. /* meters. */
  65. /* */
  66. /****************************************************************************/
  67. /* The following #ifndef encloses this entire */
  68. /* header file, rendering it idempotent. */
  69. #ifndef CM_DONE
  70. #define CM_DONE
  71. #ifdef __cplusplus
  72. extern "C" {
  73. #endif
  74. /****************************************************************************/
  75. /* The following definitions are extracted from my style header file which */
  76. /* would be cumbersome to distribute with this package. The DONE_STYLE is */
  77. /* the idempotence symbol used in my style header file. */
  78. #ifndef DONE_STYLE
  79. typedef unsigned long ulong;
  80. typedef unsigned ubool;
  81. typedef unsigned char * p_ubyte_;
  82. #ifndef TRUE
  83. #define FALSE 0
  84. #define TRUE 1
  85. #endif
  86. /* Uncomment this definition if you don't have void. */
  87. /* typedef int void; */
  88. #endif
  89. /****************************************************************************/
  90. /* CRC Model Abstract Type */
  91. /* ----------------------- */
  92. /* The following type stores the context of an executing instance of the */
  93. /* model algorithm. Most of the fields are model parameters which must be */
  94. /* set before the first initializing call to cm_ini. */
  95. typedef struct
  96. {
  97. int cm_width; /* Parameter: Width in bits [8,32]. */
  98. ulong cm_poly; /* Parameter: The algorithm's polynomial. */
  99. ulong cm_init; /* Parameter: Initial register value. */
  100. ubool cm_refin; /* Parameter: Reflect input bytes? */
  101. ubool cm_refot; /* Parameter: Reflect output CRC? */
  102. ulong cm_xorot; /* Parameter: XOR this to output CRC. */
  103. ulong cm_reg; /* Context: Context during execution. */
  104. } cm_t;
  105. typedef cm_t *p_cm_t;
  106. /****************************************************************************/
  107. /* Functions That Implement The Model */
  108. /* ---------------------------------- */
  109. /* The following functions animate the cm_t abstraction. */
  110. void cm_ini(p_cm_t p_cm);
  111. /* Initializes the argument CRC model instance. */
  112. /* All parameter fields must be set before calling this. */
  113. void cm_nxt(p_cm_t p_cm, int ch);
  114. /* Processes a single message byte [0,255]. */
  115. void cm_blk(p_cm_t p_cm, p_ubyte_ blk_adr, ulong blk_len);
  116. /* Processes a block of message bytes. */
  117. ulong cm_crc(p_cm_t p_cm);
  118. /* Returns the CRC value for the message bytes processed so far. */
  119. /****************************************************************************/
  120. /* Functions For Table Calculation */
  121. /* ------------------------------- */
  122. /* The following function can be used to calculate a CRC lookup table. */
  123. /* It can also be used at run-time to create or check static tables. */
  124. ulong cm_tab(p_cm_t p_cm, int index);
  125. /* Returns the i'th entry for the lookup table for the specified algorithm. */
  126. /* The function examines the fields cm_width, cm_poly, cm_refin, and the */
  127. /* argument table index in the range [0,255] and returns the table entry in */
  128. /* the bottom cm_width bytes of the return value. */
  129. /****************************************************************************/
  130. /* End of the header file idempotence #ifndef */
  131. #ifdef __cplusplus
  132. }
  133. #endif
  134. #endif
  135. /****************************************************************************/
  136. /* End of crcmodel.h */
  137. /****************************************************************************/