It seems that there are some bug in sscanf() with Android NDK-r9.
When read a line from a text file, i use the strtok() to tokenize the string, and call sscanf() to convert the token into hex value. There are some chance to get 0 from sscanf() , although it is not always occurred.
To solve the problem in NDK, i write a simple function to convert the token into hex, the code is as follow listing:
// sscanf has bug in Android NDK
static unsigned char convertToHex( char c ) {
if ( c >= '0' && c <= '9' ) {
return c - '0';
}
if ( c >= 'A' && c <= 'F' ) {
return c - 'A' + 10;
}
if ( c >= 'a' && c <= 'f' ) {
return c - 'a' + 10;
}
return 0;
}
static unsigned char bytesToHex( char *token ) {
unsigned char tmp ;
unsigned char tmp1;
unsigned char tmp2;
tmp1 = convertToHex( token[0] );
tmp2 = convertToHex( token[1] );
tmp = tmp1 << 4 | tmp2;
return tmp ;
};
2013年11月14日 星期四
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
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
Chrome Global Dark Style
一個 Chrome 的 Plugin 可以讓網頁瀏覽變成黑底白字
http://userstyles.org/styles/23516/midnight-surfing-global-dark-style
http://userstyles.org/styles/23516/midnight-surfing-global-dark-style
訂閱:
文章 (Atom)