AES in GCM mode in Python

23,594

Solution 1

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

Solution 2

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

Solution 3

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

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.

Share:
23,594
imichaelmiers
Author by

imichaelmiers

Updated on July 12, 2022

Comments

  • imichaelmiers
    imichaelmiers almost 2 years

    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

  • kasperd
    kasperd about 8 years
    Answers are supposed to contain more than just a link.
  • Robert
    Robert over 6 years
    Unfortunately 3 years later PyCrypto v2.7 still seems to be an unreleased beta version. At least the repository used by pip has only v2.6.1.
  • LarsH
    LarsH over 6 years
    This answer does contain more than just a link, and it looks complete to me. It gives the name of the library, and states that it provides AES-GCM. What more should the answer say?
  • LarsH
    LarsH over 6 years
    Remember that "the answer above" is a reference that often can't be traced successfully. The order of answers on the page is dynamic. On my screen, the answer you're talking about appears below yours (and is deleted anyway). Referring to an answer by the name of the person who wrote it is usually pretty durable. You can use the URL from the "share" link if you want to be really precise.
  • John La Rooy
    John La Rooy about 6 years
    @kasperd. Questions aren't supposed to ask for recommendations of tools/libraries either.
  • Exectron
    Exectron almost 6 years
    According to Issue #238 · dlitz/pycrypto, PyCrypto is dead (not officially, but in practical terms it is unmaintained); use PyCryptodome instead.