mem aligment blowfish_chain_test
This commit is contained in:
parent
0dbcb052b2
commit
d588d02b73
1 changed files with 11 additions and 8 deletions
|
|
@ -132,7 +132,6 @@ static unsigned int from_bytes( const unsigned char* p ) {
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(blowfish_chain_test)
|
BOOST_AUTO_TEST_CASE(blowfish_chain_test)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
unsigned char key[16], iv[8], cipher[32], out[32];
|
unsigned char key[16], iv[8], cipher[32], out[32];
|
||||||
BOOST_CHECK_EQUAL( 16, fc::from_hex( chain_test_key.c_str(), (char*) key, sizeof(key) ) );
|
BOOST_CHECK_EQUAL( 16, fc::from_hex( chain_test_key.c_str(), (char*) key, sizeof(key) ) );
|
||||||
BOOST_CHECK_EQUAL( 8, fc::from_hex( chain_test_iv.c_str(), (char*) iv, sizeof(iv) ) );
|
BOOST_CHECK_EQUAL( 8, fc::from_hex( chain_test_iv.c_str(), (char*) iv, sizeof(iv) ) );
|
||||||
|
|
@ -140,32 +139,36 @@ BOOST_AUTO_TEST_CASE(blowfish_chain_test)
|
||||||
BOOST_CHECK_EQUAL( 32, fc::from_hex( chain_test_cbc.c_str(), (char*) cipher, sizeof(cipher) ) );
|
BOOST_CHECK_EQUAL( 32, fc::from_hex( chain_test_cbc.c_str(), (char*) cipher, sizeof(cipher) ) );
|
||||||
fc::blowfish fish;
|
fc::blowfish fish;
|
||||||
fish.start( key, sizeof(key), fc::sblock( from_bytes( iv ), from_bytes( iv + 4 ) ) );
|
fish.start( key, sizeof(key), fc::sblock( from_bytes( iv ), from_bytes( iv + 4 ) ) );
|
||||||
fish.encrypt( (unsigned char*) chain_test_plain.c_str(), out, sizeof(out), fc::blowfish::CBC );
|
|
||||||
|
char buffer[32];
|
||||||
|
memset(buffer, 0, sizeof(buffer));
|
||||||
|
memcpy(buffer, chain_test_plain.c_str(), std::min(sizeof(buffer), chain_test_plain.size()));
|
||||||
|
|
||||||
|
fish.encrypt( (unsigned char*) buffer, out, sizeof(out), fc::blowfish::CBC );
|
||||||
BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
|
BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
|
||||||
fish.reset_chain();
|
fish.reset_chain();
|
||||||
fish.decrypt( out, sizeof(out), fc::blowfish::CBC );
|
fish.decrypt( out, sizeof(out), fc::blowfish::CBC );
|
||||||
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
|
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
|
||||||
fish.reset_chain();
|
fish.reset_chain();
|
||||||
fish.encrypt( out, sizeof(out), fc::blowfish::CBC );
|
fish.encrypt( out, sizeof(out), fc::blowfish::CBC );
|
||||||
BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
|
BOOST_CHECK( !memcmp( cipher, out, sizeof(cipher) ) );
|
||||||
fish.reset_chain();
|
fish.reset_chain();
|
||||||
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CBC );
|
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CBC );
|
||||||
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
|
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL( 29, fc::from_hex( chain_test_cfb.c_str(), (char*) cipher, sizeof(cipher) ) );
|
BOOST_CHECK_EQUAL( 29, fc::from_hex( chain_test_cfb.c_str(), (char*) cipher, sizeof(cipher) ) );
|
||||||
fish.reset_chain();
|
fish.reset_chain();
|
||||||
fish.encrypt( (unsigned char*) chain_test_plain.c_str(), out, sizeof(out), fc::blowfish::CFB );
|
fish.encrypt( (unsigned char*) buffer, out, sizeof(out), fc::blowfish::CFB );
|
||||||
BOOST_CHECK( !memcmp( cipher, out, 29 ) );
|
BOOST_CHECK( !memcmp( cipher, out, 29 ) );
|
||||||
fish.reset_chain(); memset( out + 29, 0, 3 );
|
fish.reset_chain(); memset( out + 29, 0, 3 );
|
||||||
fish.decrypt( out, sizeof(out), fc::blowfish::CFB );
|
fish.decrypt( out, sizeof(out), fc::blowfish::CFB );
|
||||||
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
|
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
|
||||||
fish.reset_chain(); memset( out + 29, 0, 3 );
|
fish.reset_chain(); memset( out + 29, 0, 3 );
|
||||||
fish.encrypt( out, sizeof(out), fc::blowfish::CFB );
|
fish.encrypt( out, sizeof(out), fc::blowfish::CFB );
|
||||||
BOOST_CHECK( !memcmp( cipher, out, 29 ) );
|
BOOST_CHECK( !memcmp( cipher, out, 29 ) );
|
||||||
fish.reset_chain(); memset( out + 29, 0, 3 );
|
fish.reset_chain(); memset( out + 29, 0, 3 );
|
||||||
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CFB );
|
fish.decrypt( cipher, out, sizeof(cipher), fc::blowfish::CFB );
|
||||||
BOOST_CHECK( !memcmp( chain_test_plain.c_str(), out, 29 ) );
|
BOOST_CHECK( !memcmp( buffer, out, 29 ) );
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue