Cody Blog

How to build M2Crypto to support AES 256 in CTR mode

M2Cryto library is out of date. The latest version was released on 2011, so there are some new features provided by OpenSSL are missing. For example, If you want to support AES 256 CTR, you need to build M2Crypto by yourself.

Download M2Crypto source code

Download the M2Crypto 0.21.1 from here

Install necessary packages

$ sudo apt-get install build-essential python-dev swig libssl-dev

Modify M2Crypto-0.21.1/SWIG/_evp.i

Near:

%rename(aes_256_ofb) EVP_aes_256_ofb;
extern const EVP_CIPHER *EVP_aes_256_ofb(void);

Add these two lines:

%rename(aes_256_ctr) EVP_aes_256_ctr;
extern const EVP_CIPHER *EVP_aes_256_ctr(void);

Modify M2Crypto-0.21.1/SWIG/_ssl.i

Remove these two lines, SSLv2 is removed from newer OpenSSL versions.

%rename(sslv2_method) SSLv2_method;
extern SSL_METHOD *SSLv2_method(void);

Modify M2Crypto-0.21.1/setup.py

Modify

m2crypto = Extension(name = 'M2Crypto.__m2crypto',

to

m2crypto = Extension(name = '__m2crypto',

Build and Install

$python setup.py build 
$sudo python setup.py install

OpenSSL

Related Posts

Comments