Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a python crypto library that does not rely on anything besides python? Or pre-complied bundles of PyCrypto for Linux?

share|improve this question

migrated from crypto.stackexchange.com Apr 25 at 11:51

This question came from our site for software developers, mathematicians and others interested in cryptography.

Most package managers have pycrypto. Or you could use pip to install it. –  mikeazo Apr 25 at 0:19
using pip returned errors because a C-compiler couldn't be found in my Linux distro -- which I should mention is the adorably portable Levinux –  pinhead Apr 25 at 0:36
This question is off-topic because it is about non-cryptographic aspects of deploying a piece of software. –  fgrieu Apr 25 at 6:48
Speed - Crypto.Cipher.ARC4 is at least 2x faster than my rewrite of it in pure python, and we're talking about a ridiculously simple cipher! Security - linking to known good implementations means you can't make typos translating them, and also you're much more likely to avoid side channel attacks in C compared to python :) –  loreb Apr 25 at 12:52
good answer. Thanks. That makes sense –  pinhead Apr 25 at 14:22

1 Answer 1

up vote 2 down vote accepted

Cryptography involves intensive numerical computations that are significantly faster when implemented in a low-level language such as C and compiled to machine code, than when implemented in a high-level language such as Python and executed as interpreted bytecode. This is why you should expect any library that provides basic cryptographic primitives to be at least partly written in C (or even assembler).

However, Python does include some cryptographic primitives: the hashlib and hmac modules provide the most common digest algorithms (MD5, SHA-1, SHA-2) and the corresponding HMAC algorithms.

Furthermore, Python has built-in arbitrary-precision integer arithmetic, which allows efficiently implementing some asymmetric algorithms in pure Python (at least signing and verification, not necessarily key generation). Python-RSA (rsa) is a pure Python implementation of RSA PKCS#1 1.5.

Python does not ship with any encryption algorithms (in particular AES), because the distribution of encryption code is legally restricted in many parts of the world. The officially recommended external library is PyCrypto.

You should install PyCrypto. It would be in the standard library if it wasn't for legal restrictions. Most distributions include a Pycrypto package. If yours doesn't (I'm unfamiliar with Levinux), you will need to install gcc. If your distribution lacks gcc (or a cross-compilation system to easily compile packages on a more complete system), it isn't suitable for serious work.

share|improve this answer
Thanks, I gave up on Livenux and installed Anaconda on my Mac, which includes a compiled version of PyCrypto! So I'm allllll set now –  pinhead Apr 25 at 22:37
"It would be in the standard library if it wasn't for legal restrictions." Just curious, what legal restrictions? –  twasbrillig Dec 8 at 22:59
@twasbrillig Many countries (even democracies) have restrictions on the exportation, importation or distribution of encryption software. –  Gilles Dec 8 at 23:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.