|
|
|
@ -5,53 +5,15 @@ namespace llarp
|
|
|
|
|
{
|
|
|
|
|
namespace routing
|
|
|
|
|
{
|
|
|
|
|
bool
|
|
|
|
|
TransferTrafficMessage::Sign(llarp_crypto* c, const llarp::SecretKey& k)
|
|
|
|
|
{
|
|
|
|
|
byte_t tmp[MaxExitMTU + 512] = {0};
|
|
|
|
|
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
|
|
|
|
// zero out sig
|
|
|
|
|
Z.Zero();
|
|
|
|
|
// randomize nonce
|
|
|
|
|
Y.Randomize();
|
|
|
|
|
if(!BEncode(&buf))
|
|
|
|
|
return false;
|
|
|
|
|
// rewind buffer
|
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
|
return c->sign(Z, k, buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TransferTrafficMessage&
|
|
|
|
|
TransferTrafficMessage::operator=(const TransferTrafficMessage& other)
|
|
|
|
|
{
|
|
|
|
|
Z = other.Z;
|
|
|
|
|
Y = other.Y;
|
|
|
|
|
S = other.S;
|
|
|
|
|
version = other.version;
|
|
|
|
|
X = other.X;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
TransferTrafficMessage::Verify(llarp_crypto* c,
|
|
|
|
|
const llarp::PubKey& pk) const
|
|
|
|
|
{
|
|
|
|
|
byte_t tmp[MaxExitMTU + 512] = {0};
|
|
|
|
|
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
|
|
|
|
// make copy
|
|
|
|
|
TransferTrafficMessage copy;
|
|
|
|
|
copy = *this;
|
|
|
|
|
// zero copy's sig
|
|
|
|
|
copy.Z.Zero();
|
|
|
|
|
// encode
|
|
|
|
|
if(!copy.BEncode(&buf))
|
|
|
|
|
return false;
|
|
|
|
|
// rewind buffer
|
|
|
|
|
buf.sz = buf.cur - buf.base;
|
|
|
|
|
// verify signature
|
|
|
|
|
return c->verify(pk, buf, Z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
TransferTrafficMessage::PutBuffer(llarp_buffer_t buf)
|
|
|
|
|
{
|
|
|
|
@ -78,10 +40,6 @@ namespace llarp
|
|
|
|
|
return false;
|
|
|
|
|
if(!bencode_write_bytestring(buf, X.data(), X.size()))
|
|
|
|
|
return false;
|
|
|
|
|
if(!BEncodeWriteDictEntry("Y", Y, buf))
|
|
|
|
|
return false;
|
|
|
|
|
if(!BEncodeWriteDictEntry("Z", Z, buf))
|
|
|
|
|
return false;
|
|
|
|
|
return bencode_end(buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -89,10 +47,6 @@ namespace llarp
|
|
|
|
|
TransferTrafficMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
|
|
|
|
|
{
|
|
|
|
|
bool read = false;
|
|
|
|
|
if(!BEncodeMaybeReadDictEntry("Z", Z, read, key, buf))
|
|
|
|
|
return false;
|
|
|
|
|
if(!BEncodeMaybeReadDictEntry("Y", Y, read, key, buf))
|
|
|
|
|
return false;
|
|
|
|
|
if(!BEncodeMaybeReadDictInt("S", S, read, key, buf))
|
|
|
|
|
return false;
|
|
|
|
|
if(!BEncodeMaybeReadDictInt("V", version, read, key, buf))
|
|
|
|
|