Selaa lähdekoodia

fix:新版crc32没有正确生成table,导致计算错误

alienwalker 9 kuukautta sitten
vanhempi
sitoutus
973db1565f
2 muutettua tiedostoa jossa 9 lisäystä ja 3 poistoa
  1. 2 2
      components/crypto/luat_crc.c
  2. 7 1
      luat/modules/luat_lib_crypto.c

+ 2 - 2
components/crypto/luat_crc.c

@@ -158,8 +158,8 @@ static void prvCRC32_CreateTable(uint32_t *Tab, uint32_t Gen)
 {
 	uint32_t crc;
 	uint32_t i, j, temp, t1, t2, flag;
-	if (Tab[1] != 0)
-		return;
+//	if (Tab[1] != 0)
+//		return;
 	for (i = 0; i < 256; i++)
 	{
 		temp = prvReflect(i, 8);

+ 7 - 1
luat/modules/luat_lib_crypto.c

@@ -366,7 +366,13 @@ static int l_crypto_crc32(lua_State *L)
 {
     size_t len = 0;
     const unsigned char *inputData = (const unsigned char*)luaL_checklstring(L, 1, &len);
-
+    if (lua_isinteger(L, 2) || lua_isinteger(L, 3) || lua_isinteger(L, 4)) {
+    	uint32_t start = luaL_optinteger(L, 2, 0xffffffff);
+    	uint32_t poly = luaL_optinteger(L, 3, 0x04C11DB7);
+    	uint32_t end = luaL_optinteger(L, 4, 0xffffffff);
+        lua_pushinteger(L, luat_crc32(inputData, len, start, poly) ^ end);
+        return 1;
+    }
     lua_pushinteger(L, calcCRC32(inputData, len));
     return 1;
 }