Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.12 ]​[ nginx-1.16.0 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_CRC32_H_INCLUDED_
0009 #define _NGX_CRC32_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 
0015 
0016 extern uint32_t  *ngx_crc32_table_short;
0017 extern uint32_t   ngx_crc32_table256[];
0018 
0019 
0020 static ngx_inline uint32_t
0021 ngx_crc32_short(u_char *p, size_t len)
0022 {
0023     u_char    c;
0024     uint32_t  crc;
0025 
0026     crc = 0xffffffff;
0027 
0028     while (len--) {
0029         c = *p++;
0030         crc = ngx_crc32_table_short[(crc ^ (c & 0xf)) & 0xf] ^ (crc >> 4);
0031         crc = ngx_crc32_table_short[(crc ^ (c >> 4)) & 0xf] ^ (crc >> 4);
0032     }
0033 
0034     return crc ^ 0xffffffff;
0035 }
0036 
0037 
0038 static ngx_inline uint32_t
0039 ngx_crc32_long(u_char *p, size_t len)
0040 {
0041     uint32_t  crc;
0042 
0043     crc = 0xffffffff;
0044 
0045     while (len--) {
0046         crc = ngx_crc32_table256[(crc ^ *p++) & 0xff] ^ (crc >> 8);
0047     }
0048 
0049     return crc ^ 0xffffffff;
0050 }
0051 
0052 
0053 #define ngx_crc32_init(crc)                                                   \
0054     crc = 0xffffffff
0055 
0056 
0057 static ngx_inline void
0058 ngx_crc32_update(uint32_t *crc, u_char *p, size_t len)
0059 {
0060     uint32_t  c;
0061 
0062     c = *crc;
0063 
0064     while (len--) {
0065         c = ngx_crc32_table256[(c ^ *p++) & 0xff] ^ (c >> 8);
0066     }
0067 
0068     *crc = c;
0069 }
0070 
0071 
0072 #define ngx_crc32_final(crc)                                                  \
0073     crc ^= 0xffffffff
0074 
0075 
0076 ngx_int_t ngx_crc32_table_init(void);
0077 
0078 
0079 #endif /* _NGX_CRC32_H_INCLUDED_ */