2006-10-19 03:00:21 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) Igor Sysoev
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _NGX_CRC32_H_INCLUDED_
|
|
|
|
#define _NGX_CRC32_H_INCLUDED_
|
|
|
|
|
|
|
|
|
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
|
|
|
|
|
|
|
|
2006-10-19 17:57:49 +08:00
|
|
|
extern uint32_t *ngx_crc32_table_short;
|
|
|
|
extern uint32_t ngx_crc32_table256[];
|
2006-10-19 03:00:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
static ngx_inline uint32_t
|
2006-10-19 17:57:49 +08:00
|
|
|
ngx_crc32_short(u_char *p, size_t len)
|
2006-10-19 03:00:21 +08:00
|
|
|
{
|
2006-10-19 17:57:49 +08:00
|
|
|
u_char c;
|
2006-10-19 03:00:21 +08:00
|
|
|
uint32_t crc;
|
|
|
|
|
|
|
|
crc = 0xffffffff;
|
|
|
|
|
|
|
|
while (len--) {
|
2006-10-19 17:57:49 +08:00
|
|
|
c = *p++;
|
|
|
|
crc = ngx_crc32_table_short[(crc ^ (c & 0xf)) & 0xf] ^ (crc >> 4);
|
|
|
|
crc = ngx_crc32_table_short[(crc ^ (c >> 4)) & 0xf] ^ (crc >> 4);
|
2006-10-19 03:00:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return crc ^ 0xffffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-19 17:57:49 +08:00
|
|
|
static ngx_inline uint32_t
|
|
|
|
ngx_crc32_long(u_char *p, size_t len)
|
|
|
|
{
|
|
|
|
uint32_t crc;
|
|
|
|
|
|
|
|
crc = 0xffffffff;
|
|
|
|
|
|
|
|
while (len--) {
|
|
|
|
crc = ngx_crc32_table256[(crc ^ *p++) & 0xff] ^ (crc >> 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
return crc ^ 0xffffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-16 05:31:03 +08:00
|
|
|
ngx_int_t ngx_crc32_init(void);
|
2006-10-19 17:57:49 +08:00
|
|
|
|
|
|
|
|
2006-10-19 03:00:21 +08:00
|
|
|
#endif /* _NGX_CRC32_H_INCLUDED_ */
|