Cody Blog

Software development

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


%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 ...

Upgrade openssl from source code on Ubuntu

Remove previous openssl installation

$ sudo apt-get remove openssl libssl-dev

Install openssl 1.0.1c from source

$ tar -xvf openssl-w.x.yz.tar.gz
$ cd openssl-w.x.yz
$ ./config --prefix=/usr
$ sudo make install