Python Forum
Using SHA3 (keccak) from Hashlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using SHA3 (keccak) from Hashlib
#1
Hello community,

I am relatively new to Python and got in to it because of an tutorial related to cryptocurrencies.
I am using Python 3.6 on a Windows10 machine.

My target is to create a sha3_256() hash of an Input based on keccak Definition.

In the Readme of hashlib library , I can find that from Python Version 3.6 the call sha3_256() is according to keccak Definition.

So I try the following:

import hashlib

s = hashlib.sha3_256()
s.update(b'a')
print(s.hexdigest())
When I compare the Output in my console
80084bf2fba02475726feb2cab2d8215eab14bc6bdd8bfb2c8151257032ecd8b
with the Output from this Website

I can see that they are not the same.

However, when I change from keccak_256 to SHA3_256 on the same Website
I can find that the Output Matches my Output.

My conclusion: Hashlib providing the function sha3_256() is not according to keccak which is stated by the documentation.

Question is: can I obtain a keccak_256 conform hash using hashlib?

I appreciate your help!

Many thanks in advance.

Short update:

I found an Explanation on this website which explains that keccak is an older Definition of sha3 back in 2012. Since 2015 sha3 was updated.

Hence my implementation of hashlib uses the 2015 Version of sha3 which differs from the keccak Version.

Is there a Chance to use the old Version of hashlib or a keccak call in the new Version?

Edit2:

I gave up using library hashlib and installed pysha3 library instead.

It offers keccak_256() call which is based on sha3 2012 Definition.

I can now create Ethereum private and public key pairs on my own :-)

This thread can be closed.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] How to crack hash with hashlib Milan 0 1,403 Mar-09-2023, 08:25 PM
Last Post: Milan
  Python3 hashlib ogautier 1 1,532 Mar-28-2022, 04:42 AM
Last Post: snippsat
  how can I generate a password in hashlib go127a 20 8,596 May-19-2019, 09:26 AM
Last Post: buran
  Confusion about Hashlib Vysero 2 2,983 Jun-25-2018, 04:05 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020