1

I have Py3.6 on my PC, and one of the stock modules is hashlib, and from 3.6+ it includes SHA3 hashing. However, I need to be able to run hashlib with SHA3 on Python 3.4, where hashlib doesn't include SHA3.

How can I rip hashlib from Py3.6 and use it as an external module, eg having it sit in the same directory as the rest of my .py files?

  • 4
    Apparently [someone has already done that](https://pypi.python.org/pypi/pysha3) for you, as long as you don't necessarily _need_ it to sit in the same directory as your `.py` files. As per _how_ to do it on your own, you'll just have to read the 3.6 code, read the 3.4 code, and figure out what you need to do. My guess is it won't be easy, since it's implemented in C, but on the other hand it's Python, so nothing is impossible. – kyrill Apr 09 '17 at 10:25
  • You'll have to download the sourcecode of _Py34_, and (_36_), port the functionality of _3.6_ in _3.4_, and recompile. Apparently, the suite (_blake2*_, _sha3*_, _shake*_) is implemented in _python36.dll_, as the _OpenSSL_ version linked against is (v1.0.2j) that does not define them. – CristiFati Apr 09 '17 at 15:08
  • christ, that sounds complex. What if I used the Pip module pysha3? How can I make it portable? –  Apr 09 '17 at 15:48
  • 1
    Not sure whether you still need this, but anyways: to make it portable, you have to ensure that `pysha3` is installed if you're not running Python 3.6 or newer. If you read the page I linked in my first comment, you can see it says: _"The `sha3` module monkey patches the `hashlib` module . The monkey patch is automatically activated with the first import of the `sha3` module."_ There is also an example code showing exactly what you need to do to support both older and newer versions, eg. versions with / without `sha3`. Relevant part is the conditional import `if sys.version_info < (3, 6): …`. – kyrill Apr 30 '17 at 16:47
  • THANKS! It works now, after much messing with wheels and the source. –  May 02 '17 at 13:36

0 Answers0