Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AES in GCM mode in Python [closed]

Does anyone know of a python library or wrapper around a c library that will easily provide Authenticated AES via GCM mode?

PyCrypto does not support it and it does not appear that PyOpenSSL supports direct access to the symmetric cipher portions of OpenSSL

like image 498
imichaelmiers Avatar asked Oct 31 '11 18:10

imichaelmiers


People also ask

What is GCM mode in AES?

AES-GCM is a block cipher mode of operation that provides high speed of authenticated encryption and data integrity. Todays, the level of privacy protection is insufficient and make the data is been hacked easily.

Is GCM a block cipher mode?

The Galois/Counter Mode (GCM) is a typical block cipher modes of operation using block cipher algorithm. In this version, we provide Advanced Encryption Standard (AES) processing ability, the cipherkey length for AES should be 128/192/256 bits.

What is AES-GCM nonce?

GCM. Nonce. A value used once during a cryptographic operation and then discarded.

Is AES-GCM secure?

AES-GCM is a more secure cipher than AES-CBC, because AES-CBC, operates by XOR'ing (eXclusive OR) each block with the previous block and cannot be written in parallel. This affects performance due to the complex mathematics involved requiring serial encryption.


3 Answers

The PyCA cryptography library provides AES-GCM: https://cryptography.io/en/latest/hazmat/primitives/symmetric-encryption/#cryptography.hazmat.primitives.ciphers.modes.GCM

like image 62
Alex Gaynor Avatar answered Oct 07 '22 01:10

Alex Gaynor


I have just finished looking for an EAX or GCM mode AES encryption algorithm in python. This was a particularly difficult search because I was unable to download the PyCrypto alpha version, which includes both of these, due to a dependency issue.

Eventually I turned to an offshoot of pycrypto that can be pip installed without issue, and has a stable release of GCM.

http://pycryptodome.readthedocs.org/en/latest/src/introduction.html

like image 38
trevorKirkby Avatar answered Oct 07 '22 01:10

trevorKirkby


I am looking for exactly the same thing, and strangely enough I cannot find any "official" solutions, just those:

  • this small wrapper (used for iphone tools?)
  • this github code drop which does AES GCM in Python, and nothing else

So it looks like the answer above (which I have upvoted) is right, you have to do the maths yourself.. It's a shame there isn't a python wrapper for a C/assembly library because the latest CPUs provide hardware acceleration for those calculations, and we won't benefit from those with a pure python solution.

like image 20
totaam Avatar answered Oct 06 '22 23:10

totaam