mem aligment blowfish_chain_test
This commit is contained in:
parent
a2221e2054
commit
e46727cdbc
1 changed files with 11 additions and 6 deletions
|
|
@ -139,31 +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