# # patch "ChangeLog" # from [81eece5640970d2c6a838995ff56ed60e0868cd9] # to [ce8e52ee011a7e9a7905d6ea8b6260a6c049df56] # # patch "constants.hh" # from [a4741c95ae4faeb5db1f36f6ccf406f732250241] # to [94b12534ecf00b0d10056ab3edf9fad2e38eb300] # # patch "hmac.cc" # from [39bc2c1c84cb059b9d4095dd23daa369c33c4cbf] # to [b3ff5a538eb8986fddf018c89f2352abc45e73dd] # # patch "hmac.hh" # from [1aca898a8a90b9054cd1b4c0e966b298854cc924] # to [1f62c61985e4369d1ee5a29c5b8e3525bc03ebfe] # # patch "netcmd.cc" # from [b8f2bfffbb6ebefdf274ea1d5ac59b58cd837671] # to [672a3694248e09ec47f64929e99411c1a35ae745] # # patch "vocab.cc" # from [0a568b1d7a988e146671055888136fdff7818916] # to [d76e379b5a6bc88ed11268a9a63cd4f4ecc798c0] # --- ChangeLog +++ ChangeLog @@ -1,5 +1,16 @@ 2005-07-04 Nathaniel Smith
+ * netcmd.cc (do_netcmd_roundtrip, test_netcmd_mac): Update for new + chained_hmac object. + * constants.hh (netsync_key_initializer): Update comment. + * hmac.hh (hmac_length): Expose length of MACs. + * hmac.cc: I() that it matches what CryptoPP wants to give. + * netcmd.cc: I() that it matches the length hard-coded into the + netsync protocol. + * vocab.cc (verify(netsync_hmac_value)): Fix error message. + +2005-07-04 Nathaniel Smith + * tests/t_netsync_defaults.at: Update for new var names. All tests now pass. --- constants.hh +++ constants.hh @@ -127,7 +127,7 @@ // netsync HMAC value length extern size_t const netsync_hmac_value_length_in_bytes; - // netsync session key and HMAC key default initializer + // netsync session key default initializer extern std::string const & netsync_key_initializer; } --- hmac.cc +++ hmac.cc @@ -11,6 +11,7 @@ chained_hmac::chained_hmac(netsync_session_key const & session_key) : key(session_key) { + I(hmac_length == CryptoPP::SHA::DIGESTSIZE); memset(chain_val, 0, sizeof(chain_val)); } --- hmac.hh +++ hmac.hh @@ -16,9 +16,11 @@ std::string process(std::string const & str, size_t pos = 0, size_t n = std::string::npos); + static size_t const hmac_length = CryptoPP::SHA::DIGESTSIZE; + private: netsync_session_key key; - char chain_val[CryptoPP::SHA::DIGESTSIZE]; + char chain_val[hmac_length]; }; --- netcmd.cc +++ netcmd.cc @@ -73,6 +73,7 @@ insert_variable_length_string(payload, out); string digest = hmac.process(out, oldlen); + I(hmac.hmac_length == constants::netsync_hmac_value_length_in_bytes); out.append(digest); } @@ -135,6 +136,7 @@ require_bytes(inbuf, pos, payload_len, "netcmd payload"); // grab it before the data gets munged + I(hmac.hmac_length == constants::netsync_hmac_value_length_in_bytes); string digest = hmac.process(inbuf, 0, pos + payload_len); payload = inbuf.substr(pos + payload_len); @@ -568,40 +570,40 @@ string buf; netsync_session_key key(constants::netsync_key_initializer); { - netsync_hmac_value mac(constants::netsync_key_initializer); + chained_hmac mac(key); // mutates mac - out_cmd.write(buf, key, mac); - BOOST_CHECK_THROW(in_cmd.read(buf, key, mac), bad_decode); + out_cmd.write(buf, mac); + BOOST_CHECK_THROW(in_cmd.read(buf, mac), bad_decode); } { - netsync_hmac_value mac(constants::netsync_key_initializer); - out_cmd.write(buf, key, mac); + chained_hmac mac(key); + out_cmd.write(buf, mac); } buf[0] ^= 0xff; { - netsync_hmac_value mac(constants::netsync_key_initializer); - BOOST_CHECK_THROW(in_cmd.read(buf, key, mac), bad_decode); + chained_hmac mac(key); + BOOST_CHECK_THROW(in_cmd.read(buf, mac), bad_decode); } { - netsync_hmac_value mac(constants::netsync_key_initializer); - out_cmd.write(buf, key, mac); + chained_hmac mac(key); + out_cmd.write(buf, mac); } buf[buf.size() - 1] ^= 0xff; { - netsync_hmac_value mac(constants::netsync_key_initializer); - BOOST_CHECK_THROW(in_cmd.read(buf, key, mac), bad_decode); + chained_hmac mac(key); + BOOST_CHECK_THROW(in_cmd.read(buf, mac), bad_decode); } { - netsync_hmac_value mac(constants::netsync_key_initializer); - out_cmd.write(buf, key, mac); + chained_hmac mac(key); + out_cmd.write(buf, mac); } buf += '\0'; { - netsync_hmac_value mac(constants::netsync_key_initializer); - BOOST_CHECK_THROW(in_cmd.read(buf, key, mac), bad_decode); + chained_hmac mac(key); + BOOST_CHECK_THROW(in_cmd.read(buf, mac), bad_decode); } } @@ -610,12 +612,12 @@ { netsync_session_key key(constants::netsync_key_initializer); { - netsync_hmac_value mac(constants::netsync_key_initializer); - out_cmd.write(buf, key, mac); + chained_hmac mac(key); + out_cmd.write(buf, mac); } { - netsync_hmac_value mac(constants::netsync_key_initializer); - BOOST_CHECK(in_cmd.read(buf, key, mac)); + chained_hmac mac(key); + BOOST_CHECK(in_cmd.read(buf, mac)); } BOOST_CHECK(in_cmd == out_cmd); } --- vocab.cc +++ vocab.cc @@ -133,7 +133,7 @@ } N(val().size() == constants::netsync_hmac_value_length_in_bytes, - F("Invalid key length of %d bytes") % val().length()); + F("Invalid hmac length of %d bytes") % val().length()); val.ok = true; }