Browse Source

pair-coding update

cl-refactor
subtly 10 years ago
parent
commit
924ac4ec92
  1. 10
      libp2p/RLPxHandshake.cpp
  2. 2
      libp2p/RLPxHandshake.h

10
libp2p/RLPxHandshake.cpp

@ -22,7 +22,7 @@
#include "Host.h"
#include "Session.h"
#include "Peer.h"
#include "PeerHandshake.h"
#include "RLPxHandshake.h"
using namespace std;
using namespace dev;
using namespace dev::p2p;
@ -107,7 +107,7 @@ h128 RLPXFrameIO::ingressDigest()
void RLPXFrameIO::updateEgressMACWithHeader(h128 const& _headerCipher)
{
m_egressMac.Update(_headerCipher.data(), h128::size);
updateMAC(m_egressMac);
updateMAC(m_egressMac, *(h128*)_headerCipher.data());
}
void RLPXFrameIO::updateEgressMACWithEndOfFrame(bytesConstRef _cipher)
@ -119,7 +119,7 @@ void RLPXFrameIO::updateEgressMACWithEndOfFrame(bytesConstRef _cipher)
void RLPXFrameIO::updateIngressMACWithHeader(bytesConstRef _headerCipher)
{
m_ingressMac.Update(_headerCipher.data(), h128::size);
updateMAC(m_ingressMac);
updateMAC(m_ingressMac, *(h128*)_headerCipher.data());
}
void RLPXFrameIO::updateIngressMACWithEndOfFrame(bytesConstRef _cipher)
@ -128,7 +128,7 @@ void RLPXFrameIO::updateIngressMACWithEndOfFrame(bytesConstRef _cipher)
updateMAC(m_ingressMac);
}
void RLPXFrameIO::updateMAC(SHA3_256& _mac)
void RLPXFrameIO::updateMAC(SHA3_256& _mac, h128 const& _seed)
{
SHA3_256 prevDigest(_mac);
h128 prevDigestOut;
@ -136,7 +136,7 @@ void RLPXFrameIO::updateMAC(SHA3_256& _mac)
h128 encDigest;
m_macUpdateEncryptor.ProcessData(encDigest.data(), prevDigestOut.data(), h128::size);
encDigest ^= prevDigestOut;
encDigest ^= (!!_seed ? _seed : prevDigestOut);
// update mac for final digest
_mac.Update(encDigest.data(), h256::size);

2
libp2p/RLPxHandshake.h

@ -73,7 +73,7 @@ private:
CryptoPP::SHA3_256 ingressMac;
};
void updateMAC(CryptoPP::SHA3_256& _mac);
void updateMAC(CryptoPP::SHA3_256& _mac, h128 const& _seed = h128());
CryptoPP::ECB_Mode<CryptoPP::Rijndael>::Encryption m_macUpdateEncryptor;
CryptoPP::SHA3_256 m_egressMac;

Loading…
Cancel
Save