fixed bug in aes

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-GenericTunneling@6297 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-04-07 15:07:13 +00:00
parent 66de50508b
commit cd2d702e44
2 changed files with 11 additions and 13 deletions

View File

@ -81,10 +81,10 @@ int main(int argc,char *argv[])
for(int j=0;j<8;++j)
salt[j] = lrand48() & 0xff ;
unsigned char output_data[source_string.size() + 1 + 16] ;
uint32_t output_data_length = source_string.size() + 1 + 16 ;
unsigned char output_data[source_string.size() + 16] ;
uint32_t output_data_length = source_string.size() + 16 ;
CHECK(RsAes::aes_crypt_8_16( (const uint8_t*)source_string.c_str(),source_string.length()+1,key_data,salt,output_data,output_data_length)) ;
CHECK(RsAes::aes_crypt_8_16( (const uint8_t*)source_string.c_str(),source_string.length(),key_data,salt,output_data,output_data_length)) ;
std::cerr << "Round " << i << " salt=" ;
printHex(salt,8) ;
@ -92,19 +92,19 @@ int main(int argc,char *argv[])
printHex(output_data,output_data_length) ;
std::cerr << std::endl;
unsigned char output_data2[output_data_length + 1 + 16] ;
uint32_t output_data_length2 = output_data_length + 1 + 16 ;
unsigned char output_data2[output_data_length + 16] ;
uint32_t output_data_length2 = output_data_length + 16 ;
CHECK(RsAes::aes_decrypt_8_16(output_data,output_data_length,key_data,salt,output_data2,output_data_length2)) ;
// std::cerr << " output_length = " << output_data_length2 << ", decrypted string = " ;
// printHex(output_data2,output_data_length2) ;
// std::cerr << std::endl;
std::cerr << " output_length = " << output_data_length2 << ", decrypted string = " ;
printHex(output_data2,output_data_length2) ;
std::cerr << std::endl;
CHECK(std::string( (const char *)output_data2,output_data_length2) == source_string) ;
}
FINALREPORT("Sha1Test") ;
FINALREPORT("AESTest") ;
return TESTRESULT() ;
}

View File

@ -57,15 +57,13 @@ bool RsAes::aes_crypt_8_16(const uint8_t *input_data,uint32_t input_data_length,
if(output_data_length < (uint32_t)c_len)
return false ;
output_data_length = c_len ;
/* update ciphertext, c_len is filled with the length of ciphertext generated,
*len is the size of plaintext in bytes */
EVP_EncryptUpdate(&e_ctx, output_data, &c_len, input_data, input_data_length);
/* update ciphertext with the final remaining bytes */
EVP_EncryptFinal_ex(&e_ctx, const_cast<uint8_t*>(input_data)+c_len, &f_len);
EVP_EncryptFinal_ex(&e_ctx, output_data+c_len, &f_len);
output_data_length = c_len + f_len;
@ -109,7 +107,7 @@ bool RsAes::aes_decrypt_8_16(const uint8_t *input_data,uint32_t input_data_lengt
EVP_DecryptUpdate(&e_ctx, output_data, &c_len, input_data, input_data_length);
/* update ciphertext with the final remaining bytes */
EVP_DecryptFinal_ex(&e_ctx, const_cast<uint8_t*>(input_data)+c_len, &f_len);
EVP_DecryptFinal_ex(&e_ctx, output_data+c_len, &f_len);
output_data_length = c_len + f_len;