2013年11月7日 星期四

AES-CTR-128 with OpenSSL on Android and Windows

I have some OpenSSL experience during Content Protection Project development. In this post, there some non-confidential technical skill could be shared to you.

For Developing the Content Encryption, the AES-CTR-128 was used.

To use the AES-CTR-128 easily with OpenSSL 0.9.8e
Copy aes_core.c and aes_ctr.c and related header files from OpenSSL source.

And the code sinppet should look like this:

#include

AES_key aes_key
input         : in_blk
output      : out_blk

unsigned char *key = "1234567812345678"
unsigned char nonce_counter[16];
unsigned char stream_block[16];
size_t tmp = 0;
int size = 0;

set up the AES key with AES-128
AES_set_encrypt_key(key, 128, &aes_key);

use AES-CTR-128 algorithm to encrypt content
AES_ctr128_encrypt(
   in_blk,
   out_blk,
   size,
  &aes_key,
  nonce_counter,
  stream_block,
  &tmp);


the decryption code snippet:
AES_ctr128_encrypt(
out_blk,
dec_out_blk,
size,
&aes_key,
nonce_counter,
stream_block, &tmp);


android_ndk demo 

visual_studio_2010_demo





沒有留言: