DES_set_key issue in 64-bit environment, openssl 1.0.2

17 views
Skip to first unread message

方涛

unread,
Jan 28, 2015, 9:36:10 PM1/28/15
to openssl...@googlegroups.com

As Apple required 64-bit support, so i compiled the latest 1.0.2 openssl and used it in my old project.

Build and compile are both ok, but i figured out an issue with DES_set_key function:

In 32-bit environment, DES_key_schedule and DES_set_key works fine.

While, in 64-bit environment, the key schedule variable will overflow and the exceeded value will overwrite the value into contiguous memory space of another variable.

Like the following code:

int64_t in_len = [inputData length]; // the length of input data

DES_key_schedule ks1, ks2, ks3;
unsigned char * keybytes = (unsigned cahr *)[key bytes];
DES_set_key((C_Block*)keybytes, &ks1);
DES_set_key((C_Block*)keybytes+8, &ks2);
DES_set_key((C_Block*)keybytes, &ks3);

the in_len has the right value as 1567, but after

 DES_set_key((C_Block*)keybytes, &ks1);

in_len has been changed to another strange and very big value, 1222431968.

Through view the memory, the memory location of in_len is next to ks1, the gap is 128 bytes, after ks1 set key, the value of in_len was overwritten.

Anyone has any idea to fix this?

Reply all
Reply to author
Forward
0 new messages