src/core/ngx_crc32.h - nginx-1.31.4 nginx/ @ 8d9666701

Functions defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_CRC32_H_INCLUDED_
  6. #define _NGX_CRC32_H_INCLUDED_


  7. #include <ngx_config.h>
  8. #include <ngx_core.h>


  9. extern uint32_t  *ngx_crc32_table_short;
  10. extern uint32_t   ngx_crc32_table256[];
  11. extern uint32_t   ngx_crc32c_table256[];


  12. static ngx_inline uint32_t
  13. ngx_crc32_short(u_char *p, size_t len)
  14. {
  15.     u_char    c;
  16.     uint32_t  crc;

  17.     crc = 0xffffffff;

  18.     while (len--) {
  19.         c = *p++;
  20.         crc = ngx_crc32_table_short[(crc ^ (c & 0xf)) & 0xf] ^ (crc >> 4);
  21.         crc = ngx_crc32_table_short[(crc ^ (c >> 4)) & 0xf] ^ (crc >> 4);
  22.     }

  23.     return crc ^ 0xffffffff;
  24. }


  25. static ngx_inline uint32_t
  26. ngx_crc32_long(u_char *p, size_t len)
  27. {
  28.     uint32_t  crc;

  29.     crc = 0xffffffff;

  30.     while (len--) {
  31.         crc = ngx_crc32_table256[(crc ^ *p++) & 0xff] ^ (crc >> 8);
  32.     }

  33.     return crc ^ 0xffffffff;
  34. }


  35. #define ngx_crc32_init(crc)                                                   \
  36.     crc = 0xffffffff


  37. static ngx_inline void
  38. ngx_crc32_update(uint32_t *crc, u_char *p, size_t len)
  39. {
  40.     uint32_t  c;

  41.     c = *crc;

  42.     while (len--) {
  43.         c = ngx_crc32_table256[(c ^ *p++) & 0xff] ^ (c >> 8);
  44.     }

  45.     *crc = c;
  46. }


  47. #define ngx_crc32_final(crc)                                                  \
  48.     crc ^= 0xffffffff


  49. static ngx_inline uint32_t
  50. ngx_crc32c_long(u_char *p, size_t len)
  51. {
  52.     uint32_t  crc;

  53.     crc = 0xffffffff;

  54.     while (len--) {
  55.         crc = ngx_crc32c_table256[(crc ^ *p++) & 0xff] ^ (crc >> 8);
  56.     }

  57.     return crc ^ 0xffffffff;
  58. }


  59. #define ngx_crc32c_init(crc)                                                  \
  60.     crc = 0xffffffff


  61. static ngx_inline void
  62. ngx_crc32c_update(uint32_t *crc, u_char *p, size_t len)
  63. {
  64.     uint32_t  c;

  65.     c = *crc;

  66.     while (len--) {
  67.         c = ngx_crc32c_table256[(c ^ *p++) & 0xff] ^ (c >> 8);
  68.     }

  69.     *crc = c;
  70. }


  71. #define ngx_crc32c_final(crc)                                                 \
  72.     crc ^= 0xffffffff


  73. ngx_int_t ngx_crc32_table_init(void);


  74. #endif /* _NGX_CRC32_H_INCLUDED_ */