Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cryptography instead of pycrypto #11

Closed
wants to merge 4 commits into from
Closed

Use cryptography instead of pycrypto #11

wants to merge 4 commits into from

Conversation

Taik
Copy link

@Taik Taik commented May 24, 2016

In order to support pypy, I converted this library over to using the cryptography package. Let me know if you need anything else.

@n8henrie
Copy link
Owner

Cool, thanks for the contribution!

I'm running into an issue installing cryptography with pypy-5.1.1 on OS X. Interestingly, it works fine installing with python3, just has an issue with pypy.

    cc -arch x86_64 -O2 -fPIC -Wimplicit -I/Users/n8henrie/git/pycookiecheat/venv/include -c build/temp.macosx-10.11-x86_64-2.7/_openssl.c -o build/temp.macosx-10.11-x86_64-2.7/build/temp.macosx-10.11-x86_64-2.7/_openssl.o
    build/temp.macosx-10.11-x86_64-2.7/_openssl.c:423:10: fatal error: 'openssl/opensslv.h' file not found
    #include <openssl/opensslv.h>
             ^
    1 error generated.
    error: command 'cc' failed with exit status 1

Also unfortunate that cryptography seems to be incompatible with pypy3, though I suppose not a critical issue.

$  python --version
Python 3.2.5 (b2091e973da6, Oct 19 2014, 18:30:58)
[PyPy 2.4.0 with GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)]
$ pip install -e .
RuntimeError: cryptography 1.0 is not compatible with PyPy < 2.6. Please upgrade PyPy to use this library.

@n8henrie
Copy link
Owner

n8henrie commented May 26, 2016

Got it -- env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography, taken from the Building cryptography on OS X section on Homebrew.

I'm surprised to see that pypy doesn't seem to improve performance vs python2, though cryptography seems to be faster than pycrypto which may make up for the sightly more complicated installation on OSX. Are you getting different results? Both of these are using the cryptography lib.

python 2.7.10, using cryptography

$ python --version
Python 2.7.10
$ python -m timeit -s 'from pycookiecheat import chrome_cookies' 'chrome_cookies("http://www.html-kit.com/tools/cookietester")'
10 loops, best of 3: 18.7 msec per loop

pypy 5.1.1 (python 2.7.10), using cryptography

$ python --version
Python 2.7.10 (b0a649e90b66, Apr 28 2016, 08:33:07)
[PyPy 5.1.1 with GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)]
$ python -m timeit -s 'from pycookiecheat import chrome_cookies' 'chrome_cookies("http://www.html-kit.com/tools/cookietester")'
10 loops, best of 3: 21 msec per loop

Old version with pycrypto

$ python --version
Python 2.7.10
$ python -m timeit -s 'from pycookiecheat import chrome_cookies' 'chrome_cookies("http://www.html-kit.com/tools/cookietester")'
10 loops, best of 3: 33.2 msec per loop

For comparison,

python3 with pycrypto

$ python --version
Python 3.5.1
$ python -m timeit -s 'from pycookiecheat import chrome_cookies' 'chrome_cookies("http://www.html-kit.com/tools/cookietester")'
10 loops, best of 3: 31.5 msec per loop

python3 with cryptography

$ python --version
Python 3.5.1
$ python -m timeit -s 'from pycookiecheat import chrome_cookies' 'chrome_cookies("http://www.html-kit.com/tools/cookietester")'
10 loops, best of 3: 16.2 msec per loop

So my results sorted:

  • Python 3.5.1 with cryptography: 16.2 msec per loop
  • Python 2.7.10 with cryptography: 18.7 msec per loop
  • Pypy 5.1.1 (python 2.7.10) with cryptography: 21 msec per loop
  • Python 3.5.1 with pycrypto: 31.5 msec per loop
  • Python 2.7.10 with pycrypto: 33.2 msec per loop

Are you getting something substantially different?

I figure I can accept the pull request since using the cryptography module is compatible with everything else, though I don't imagine that I'll put much effort into keeping it pypy compatible going forward if it's not any faster, especially since I prefer python3. That said, I don't really use pypy, so if I'm doing something wrong here that's skewing the results, let me know.

@Taik
Copy link
Author

Taik commented May 26, 2016

Hey, glad to see you got cryptography sorted out :)

As for pypy performance gains, what you see is pretty much expected. Pypy provides a JIT which isn't going to get much warm-up time if we are running synthetic benchmarks like timeit. Also, the python code in the cryptography library won't get much JIT'ting either, since OpenSSL is actually doing the heavy computation.

Cryptography is fully working with CPython 2-3, and Pypy2. Pypy3 is unfortunately not maintained (as most of their donations go towards maintaining CPython2 compatibility).

@n8henrie
Copy link
Owner

n8henrie commented Jun 1, 2016

Merged in 7720195. Thank you!

@n8henrie n8henrie closed this Jun 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants