go 1.4, using hash/crc32 with crypto/hmac gives incorrect sum

184 views
Skip to first unread message

agj32mr...@gmail.com

unread,
Jun 27, 2015, 12:38:26 PM6/27/15
to golan...@googlegroups.com
The sum for string "test" with key "test" and polynomial IEEE should give a sum of "3b5bb714", but instead it gives "f7f3ea7d".

See here: http://play.golang.org/p/6AEtZh7lwt

Am I doing something wrong? Is there an easy way to remedy this?

Highly appreciate anyone taking the time to look at this.

Matt Harden

unread,
Jun 27, 2015, 3:04:36 PM6/27/15
to agj32mr...@gmail.com, golan...@googlegroups.com
crc32 reports its block size as 1 byte. In hmac the blocksize is actually relevant to the algorithm to calculate the MAC, not just a performance thing. This code gives the answer you were looking for, by arranging for a block size of 4 bytes - http://play.golang.org/p/KEIs_zBwIw.

crc32 is not a cryptographic hash. Are you sure you want to use it with an hmac?

--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Agj32mrgibbits

unread,
Jun 27, 2015, 4:22:22 PM6/27/15
to Matt Harden, golan...@googlegroups.com
(Sorry for the double-send, forgot to cc golang-nuts.)

Thank you very much for the explanation and example, Matt. I understand it fully now.

I am using the crc32 for basic error checking, and hmac to add a very slight obstacle to purposeful alteration of the data. It needs to be fast, and the data isn't very sensitive, so it's a good fit.

Damian Gryski

unread,
Jun 28, 2015, 12:28:14 AM6/28/15
to golan...@googlegroups.com
Siphash (https://131002.net/siphash/ , https://github.com/dchest/siphash ) would also be appropriate here.

Damian
Reply all
Reply to author
Forward
0 new messages