fixed hard coded pad size (for encrypted connections) to be properly randomized

This commit is contained in:
Arvid Norberg 2008-01-31 06:34:43 +00:00
parent 6caca17883
commit 684bade8ea
1 changed files with 9 additions and 10 deletions

View File

@ -411,7 +411,7 @@ namespace libtorrent
sha1_hash const& info_hash = t->torrent_file().info_hash(); sha1_hash const& info_hash = t->torrent_file().info_hash();
char const* const secret = m_DH_key_exchange->get_secret(); char const* const secret = m_DH_key_exchange->get_secret();
int pad_size = 0; // rand() % 512; // Keep 0 for now int pad_size = rand() % 512;
// synchash,skeyhash,vc,crypto_provide,len(pad),pad,len(ia) // synchash,skeyhash,vc,crypto_provide,len(pad),pad,len(ia)
buffer::interval send_buf = buffer::interval send_buf =
@ -486,7 +486,7 @@ namespace libtorrent
TORRENT_ASSERT(crypto_select == 0x02 || crypto_select == 0x01); TORRENT_ASSERT(crypto_select == 0x02 || crypto_select == 0x01);
TORRENT_ASSERT(!m_sent_handshake); TORRENT_ASSERT(!m_sent_handshake);
int pad_size = 0; // rand() % 512; // Keep 0 for now int pad_size =rand() % 512;
const int buf_size = 8 + 4 + 2 + pad_size; const int buf_size = 8 + 4 + 2 + pad_size;
buffer::interval send_buf = allocate_send_buffer(buf_size); buffer::interval send_buf = allocate_send_buffer(buf_size);
@ -516,7 +516,6 @@ namespace libtorrent
INVARIANT_CHECK; INVARIANT_CHECK;
TORRENT_ASSERT(crypto_field <= 0x03 && crypto_field > 0); TORRENT_ASSERT(crypto_field <= 0x03 && crypto_field > 0);
TORRENT_ASSERT(pad_size == 0); // pad not used yet
// vc,crypto_field,len(pad),pad, (len(ia)) // vc,crypto_field,len(pad),pad, (len(ia))
TORRENT_ASSERT( (write_buf.left() == 8+4+2+pad_size+2 && is_local()) || TORRENT_ASSERT( (write_buf.left() == 8+4+2+pad_size+2 && is_local()) ||
(write_buf.left() == 8+4+2+pad_size && !is_local()) ); (write_buf.left() == 8+4+2+pad_size && !is_local()) );
@ -533,14 +532,14 @@ namespace libtorrent
detail::write_uint16(pad_size, write_buf.begin); // len (pad) detail::write_uint16(pad_size, write_buf.begin); // len (pad)
// fill pad with zeroes // fill pad with zeroes
// std::fill(write_buf.begin, write_buf.begin+pad_size, 0); std::generate(write_buf.begin, write_buf.begin + pad_size, &std::rand);
// write_buf.begin += pad_size; write_buf.begin += pad_size;
// append len(ia) if we are initiating // append len(ia) if we are initiating
if (is_local()) if (is_local())
detail::write_uint16(handshake_len, write_buf.begin); // len(IA) detail::write_uint16(handshake_len, write_buf.begin); // len(IA)
assert (write_buf.begin == write_buf.end); TORRENT_ASSERT(write_buf.begin == write_buf.end);
} }
void bt_peer_connection::init_pe_RC4_handler(char const* secret, sha1_hash const& stream_key) void bt_peer_connection::init_pe_RC4_handler(char const* secret, sha1_hash const& stream_key)