I am facing strange results fo go
SHA3-256 function: here is source code
import (
"golang.org/x/crypto/sha3"
"encoding/hex"
)
func main() {
pub, _ := hex.DecodeString("c342dbf7cdd3096c4c3910c511a57049e62847dd5030c7e644bc855acc1fd626")
h := sha3.Sum256(pub[:])
fmt.Printf("SHA3 %x
", h)
// expected: b32562e67d3ea44ba1367ce134caac49fd305b24cde6716ad3857ac682576379
// received: 8a3ccc097f854811f4c49346da9c3bd1745d087ed539fa7817960f3e0ed8a44f
}
I verified result on couple of online converters, they all give same result, different from mine.
You are assuming that the online converters that you've tested perform hexadecimal decoding. They don't; they just take the ASCII/UTF-8/whatever value of the string and use that, i.e. they hash the text.
This can be easily observed by inputting your c342...
string and then inputting hello
. Both will work, while hello
obviously doesn't contain hexadecimals. Another way is to start with an uppercase C
instead of c
, which will also return a different result, while the hexadecimal decoding should return an identical byte array and thus hash.
And a small Java application does indeed confirm your value of:
8a3ccc097f854811f4c49346da9c3bd1745d087ed539fa7817960f3e0ed8a44f
Note that most if not all online tools are basically hobby projects by amateur cryptographers. Expect all kind of encoding / decoding issues, errors and uncertainties in the implementation. If you want to test your implementation, use the official NIST test vectors.