Shouldn't the polynomial be 0x1EDC6F41 instead of 0x1EDC6F1

On Saturday, July 11, 2015 at 10:18:15 AM UTC-7 Joe Poirier wrote:

> On Sat, Jul 11, 2015 at 10:25 AM, Akira Hayakawa <ruby...@gmail.com> 
> wrote:
>
>> Hi,
>>
>> I am at loss how I can compute crc32c hash value with given seed.
>>
>> Some C libraries including Linux kernel's libcrc32c has API that takes 
>> three arguments: seed(uint32), data(void *) and the length(int). So the 
>> same design in Go's crc32 library helps users import their C programs to 
>> Go. Actually, I need the API.
>>
>> I tried crc32.Update(seed, Castagnoli table, data) but the computed value 
>> differs from what I compute with Linux's libcrc32c.
>>
>> I am not expertise in crc32c algorithm but I am just a user. So I think I 
>> should ask you how to make the same thing as libcrc32c using Go's crc32 
>> library.
>>
>>
>>
>>
>> crc32c uses polynomial 0x1EDC6F1 (reversed 0x82F63B78). So from 
> src/hash/example_test.go (replace 0xD5828281 with 0x82F63B78):
>
> package crc32_test
>
> import (
>     "fmt"
>     "hash/crc32"
> )
>
> func ExampleMakeTable() {
>     // In this package, the CRC polynomial is represented in reversed 
> notation,
>     // or LSB-first representation.
>     //
>     // LSB-first representation is a hexadecimal number with n bits, in 
> which the
>     // most significant bit represents the coefficient of x⁰ and the least 
> significant
>     // bit represents the coefficient of xⁿ⁻¹ (the coefficient for xⁿ is 
> implicit).
>     //
>     // For example, CRC32-Q, as defined by the following polynomial,
>     //    x³²+ x³¹+ x²⁴+ x²²+ x¹⁶+ x¹⁴+ x⁸+ x⁷+ x⁵+ x³+ x¹+ x⁰
>     // has the reversed notation 0b11010101100000101000001010000001, so 
> the value
>     // that should be passed to MakeTable is 0xD5828281.
>     crc32q := crc32.MakeTable(0xD5828281)
>     fmt.Printf("%08x\n", crc32.Checksum([]byte("Hello world"), crc32q))
>     // Output:
>     // 2964d064
> }
>
> See more test examples in src/hash/crc32_test.go
>
> *Note, 0x82F63B78 is exported from src/hash/crc32.go as a constant via 
> crc32.Castagnoli
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/90f76496-51f9-4511-a96b-fb8bde8af9cen%40googlegroups.com.

Reply via email to