pycryptodome
pycryptodome copied to clipboard
SHA1_init missing when using PyInstaller on OSX
When running the executable generated by PyInstaller, I get the following error message. This only happens on OSX, is it possible that a certain dynamically linked library is not picked up?
(..)
File "Cryptodome/Cipher/PKCS1_OAEP.py", line 175, in decrypt
File "Cryptodome/Hash/SHA1.py", line 158, in new
File "Cryptodome/Hash/SHA1.py", line 74, in __init__
File "ctypes/__init__.py", line 361, in __getattr__
File "ctypes/__init__.py", line 366, in __getitem__
AttributeError: dlsym(0x7fb38d73d410, SHA1_init): symbol not found
I'm getting the same error on OS X Catalina with pycryptodomeex (3.9.0), is any progress made (I cannot find the pyinstaller-bump branch?)
The same here with SHA256_init
Have the same issue. I can find the symbol _SHA256_init (with underscore) in Crypto/Hash/_SHA256.cpython-37m-darwin.so
nm -C _SHA256.cpython-37m-darwin.so
0000000000002dc0 s _H
0000000000002810 T _SHA256_copy
0000000000000750 T _SHA256_destroy
00000000000025e0 T _SHA256_digest
00000000000006e0 T _SHA256_init
0000000000002840 T _SHA256_pbkdf2_hmac_assist
0000000000000760 T _SHA256_update
...
On my linux box I have there names without underscore:
nm -C _SHA256.cpython-38-x86_64-linux-gnu.so
0000000000002bb0 T SHA256_copy
00000000000029a0 T SHA256_destroy
0000000000002ae0 T SHA256_digest
0000000000002910 T SHA256_init
0000000000002c50 T SHA256_pbkdf2_hmac_assist
00000000000029b0 T SHA256_update
...
I don't have a mac to investigate the issue in detail right now.
I understand that - unlike in Linux - the compiler on OSX will prepend an underscore to all C symbols: the _SHA256_init
symbol appearing in the .so
file should not be the real issue.
On the other hand, ctypes
is supposed to do the right thing and prepend an underscore to all C symbols it is asked to load, if the underlying platform requires so. It seems that ctypes
shipped with pyinstaller is not doing that on OSX.
is there a workaround to this issue?
File "Crypto/Protocol/KDF.py", line 160, in PBKDF2
File "Crypto/Hash/HMAC.py", line 213, in new
File "Crypto/Hash/HMAC.py", line 86, in __init__
File "Crypto/Hash/SHA1.py", line 158, in new
File "Crypto/Hash/SHA1.py", line 74, in __init__
File "ctypes/__init__.py", line 377, in __getattr__
File "ctypes/__init__.py", line 382, in __getitem__
AttributeError: dlsym(0x7fbcd0ef1160, SHA1_init): symbol not found
Have you tried hook-Crypto.py? https://raw.githubusercontent.com/pyinstaller/pyinstaller/develop/PyInstaller/hooks/hook-Crypto.py
https://pyinstaller.readthedocs.io/en/stable/hooks.html
Re-igniting an old issue. The above hook did not work in my situation, switching to pycryptodomex rather than pycryptodome does seem to resolve the issue for me. I'm unsure why and I find myself caring less than I probably should..
Then changing imports from:
from Crypto.x to from Pycrypto.x
May be a fluke but works in my situation.
I am having no issues using pycryptodome or pycryptodomex 3.9.7 on my spouse's Mac which is running High Sierra. Cannot test on Catalina because Apple won't allow her 10-year-old Mac to upgrade. Thank you, Apple!
This issue sounds like something to be taken up with pyinstaller.
In my case, I used python 3.8 and got below error after running pyinstaller created MACOS application.
AttributeError: dlsym(0x7fb38d73d410, SHA1_init): symbol not found
Created new conda env with python 3.7. This issue did not occur.
The issue here is that .so loading code (both ctypes/cffi) is finding hashlib's .so first which obviously does not have _SHA1_Init & co exports. The _sha1.cpython-38-darwin.so file is in the Pyinstaller's root directory and the /Cryptodome/Hash/_sha1.cpython-38-darwin.so is not loaded at all. Same stands for other hashing algorithms
same issue after running Pyinstaller with pycryptodome-3.10.1
.
I'm in darwin.aarch64.0 (Apple M1), with python 3.8.2 and I can't downgrade because python is not at all compatible with M1.
Hello everyone, I have the same issue with the SHA1_init
symbol on this project built using pyinstaller. I am using python 3.6.10 on a macOS Catalina.
Here is the full trace bubbling from browser-cookie3
to pbkdf2
to finally pycryptodome
:
Traceback (most recent call last):
File "minet/cli/__main__.py", line 236, in <module>
main()
File "minet/cli/__main__.py", line 215, in main
fn(args)
File "minet/cli/facebook/__init__.py", line 14, in facebook_action
facebook_comments_action(namespace)
File "minet/cli/facebook/comments.py", line 32, in facebook_comments_action
scraper = FacebookCommentScraper(namespace.cookie)
File "minet/facebook/comments.py", line 195, in __init__
cookie = grab_facebook_cookie(cookie)
File "minet/facebook/utils.py", line 32, in grab_facebook_cookie
get_cookie_for_url = grab_cookies(source)
File "minet/utils.py", line 200, in grab_cookies
return CookieResolver(getattr(browser_cookie3, browser)())
File "browser_cookie3/__init__.py", line 592, in chrome
File "browser_cookie3/__init__.py", line 382, in __init__
File "browser_cookie3/__init__.py", line 190, in __init__
File "browser_cookie3/__init__.py", line 207, in __add_key_and_cookie_file
File "pbkdf2.py", line 161, in read
File "pbkdf2.py", line 173, in __f
File "pbkdf2.py", line 146, in _pseudorandom
File "Crypto/Hash/HMAC.py", line 213, in new
File "Crypto/Hash/HMAC.py", line 86, in __init__
File "Crypto/Hash/SHA1.py", line 158, in new
File "Crypto/Hash/SHA1.py", line 74, in __init__
File "cffi/api.py", line 912, in __getattr__
File "cffi/api.py", line 908, in make_accessor
File "cffi/api.py", line 838, in accessor_function
AttributeError: function/symbol 'SHA1_init' not found in library '/Users/Yomgui/code/minet/dist/minet/_SHA1.cpython-36m-darwin.so': dlsym(0x7fb62063b1b0, SHA1_init): symbol not found
[68061] Failed to execute script __main__
Tell me if I can help in any way and have a good evening (or night, or day, pick your favorite one :) ).
Hi guys, do you have any quickfix for this issue? It seems to be fixed in pyinstaller future version (https://github.com/pyinstaller/pyinstaller/issues/5583) but not yet available.
same problem(I'm using Mac M1 and python3.10)
>>> from Crypto.Hash import SHA256
>>> SHA256.new('key'.encode())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/homebrew/lib/python3.10/site-packages/Crypto/Hash/SHA256.py", line 158, in new
return SHA256Hash().new(data)
File "/opt/homebrew/lib/python3.10/site-packages/Crypto/Hash/SHA256.py", line 73, in __init__
result = _raw_sha256_lib.SHA256_init(state.address_of())
File "/opt/homebrew/Cellar/[email protected]/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ctypes/__init__.py", line 387, in __getattr__
func = self.__getitem__(name)
File "/opt/homebrew/Cellar/[email protected]/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ctypes/__init__.py", line 392, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x2002af2e0, SHA256_init): symbol not found