Something More for Research

Explorer of Research #HEMBAD


Posted by Hemprasad Y. Badgujar on April 2, 2013

libgpucrypto is subset of SSLShader software that implements few cryptographic algorithms: AES, SHA1, RSA using CUDA. It also includes several data structures to help utilize CUDA’s stream for better performance. See here for more details.

Install required libraries
you can download CUDA stuff at
libgpucrypto requires CUDA dev driver, CUDA toolkit, and CUDA SDK.

We have tested under software settings as below.

CUDA 4.0
CUDA driver : 270.41.19
CUDA toolkit : 4.0.17
CUDA SDK : 4.0.17

CUDA 3.2
CUDA driver : 260.19.26
CUDA toolkit : 3.2.16
CUDA SDK : 3.2.16

Ubuntu 10.04 LTS 64bit

Install OpenSSL libraries and headers
you can download OpenSSL at

Configure following variables in

if you’re using system default opeenssl development library, then you may leave OPENSSL_DIR as blank.

Build libgpucrypto

Try running test code
#./bin/aes_test -m ENC
AES-128-CBC ENC, Size: 16KB
#msg latency(usec) thruput(Mbps)
1 6012 21
2 6305 41
4 7020 74
8 8737 120
16 11834 177
32 16168 259
64 17244 486
128 19256 871
256 24579 1365
512 27067 2479
1024 31605 4246
2048 40924 6559
4096 61402 8743
Correctness check (batch, random): ………….OK
#./bin/rsa_test -m MP

you can see more detailed usage by running program w/o arguments or w/ incorrect one :).
How to use?
Here, I’ll explain how to use libgpucrypto with an example of AES. Below is part of the code from

device_context dev_ctx;
pinned_mem_pool *pool;
aes_enc_param_t param;
operation_batch_t ops;

//1. initialize device context
dev_ctx.init(num_flows * flow_len * 3, 0);

//2. create aes_context.
aes_context aes_ctx(&dev_ctx);

//generate test random test case

//3. prepare data to be encrypted
pool = new pinned_mem_pool();
pool->init(num_flows * flow_len * 3);

aes_cbc_encrypt_prepare(&ops, &param, pool);

//4. Launch GPU code

//5. Wait for completion

Initialize device_context: libgpucrypto has several wrapper for CUDA initialization and stream manipulation. To utilize libgpucrypto, you need to create device_context .

Create aes_context: class aes_context provides APIs to launch GPU code using CUDA library. You need an initialized device_context for this.

Prepare data to be encrypted: To use aes_context, you need to organize data and prepare some metadata. GPU requires large batch size to get maximum throughput and you need to copy data into GPU’s memory before processing. Data copy cost between GPU’s memory and host memory is relatively huge when you copy small amount of data. For this reason, we gather all data into one big buffer before passing to aes_context. Please read sample code in test directory for details.

In the above example we used pinned_page to avoid another copy in CPU’s memory. Before CUDA4.0, unless you allocate pinned page using CUDA, it will copy data into pinned page internally before copying into GPU. To avoid this we use pinned page explicitly.

We know it’s not very friendly. We’re working on improving the interface.

Launch GPU code: aes_context will copy data into GPU’s memory and launch GPU kernel.

Wait for completion: sync function poll to check whether the GPU execution has finished, and it will copy data back to host memory once kernel execution is done. You can use this function in async manner to just check status. See here for more details.

Please see files in test directory for more examples.

Doxygen API documentation

Source Code
click here to download

Code license
This source code is distributed under BSD-style license. Read LICENSE for more details.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Extracts from a Personal Diary

dedicated to the life of a silent girl who eventually learnt to open up

Num3ri v 2.0

I miei numeri - seconda versione


Just another site

Algunos Intereses de Abraham Zamudio Chauca

Matematica, Linux , Programacion Serial , Programacion Paralela (CPU - GPU) , Cluster de Computadores , Software Cientifico




A great site

Travel tips

Travel tips

Experience the real life.....!!!

Shurwaat achi honi chahiye ...

Ronzii's Blog

Just your average geek's blog

Karan Jitendra Thakkar

Everything I think. Everything I do. Right here.


News About Tech, Money and Innovation

Chetan Solanki

Helpful to u, if u need it.....


Explorer of Research #HEMBAD


Explorer of Research #HEMBAD


A great site


This is My Space so Dont Mess With IT !!

%d bloggers like this: