39 else if (!openBroadcastEnvelope(_e, _t, b))
54 unsigned topicIndex = 0;
59 for (
unsigned ti = 0; ti < _fk.size() && !topicSecret; ++ti)
60 for (
unsigned i = 0; i < _e.
topic().size(); ++i)
61 if (_e.
topic()[i] == knownTopic[ti])
63 topicSecret =
Secret(_fk[ti]);
71 unsigned index = topicIndex * 2;
74 Secret key =
Secret(generateGamma(topicSecret, salt).makeInsecure() ^ encryptedKey.makeInsecure());
79 bool Message::populate(
bytes const& _data)
84 byte flags = _data[0];
100 Envelope Message::seal(
Secret const& _from,
Topics const& _fullTopics,
unsigned _ttl,
unsigned _workToProve)
const 105 bytes input(1 + m_payload.size());
107 memcpy(input.data() + 1, m_payload.data(), m_payload.size());
111 input.resize(1 + m_payload.size() +
sizeof(
Signature));
124 Secret s = Secret::random();
125 for (
h256 const& t: _fullTopics)
127 h256 salt = h256::random();
141 Envelope::Envelope(
RLP const& _m)
143 m_expiry = _m[0].
toInt<
unsigned>();
144 m_ttl = _m[1].
toInt<
unsigned>();
155 unsigned Envelope::workProved()
const 163 void Envelope::proveWork(
unsigned _ms)
167 unsigned bestBitSet = 0;
171 while (chrono::high_resolution_clock::now() < then)
173 for (
unsigned i = 0; i < 1024; ++i, ++d[1])
175 auto fbs =
dev::sha3(chuck).firstBitSet();
176 if (fbs > bestBitSet)
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
void encryptSym(Secret const &_k, bytesConstRef _plain, bytes &o_cipher)
Symmetric encryption.
bytes const & data() const
vector_ref< _T const > ref(_T const &_t)
bool contains(FixedHash const &_c) const
uint64_t utcTime()
Get the current time in seconds since the epoch in UTC.
std::vector< T > toVector(int _flags=LaissezFaire) const
std::vector< AbridgedTopic > AbridgedTopics
Simple class that represents a "key pair".
SecureFixedHash< 32 > Secret
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
vector_ref< _T > cropped(size_t _begin, size_t _count) const
AbridgedTopics const & topic() const
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< N *8, N *8, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> Arith
The corresponding arithmetic type.
bool decryptSym(Secret const &_k, bytesConstRef _cipher, bytes &o_plaintext)
Symmetric decryption.
Public const & pub() const
Retrieve the public key.
FixedHash< T > const & makeInsecure() const
Public recover(Signature const &_sig, h256 const &_hash)
Recovers Public key from signed message hash.
std::vector< byte > bytes
std::vector< unsigned char > toBytes() const
vector_ref< byte const > bytesConstRef
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
h520 Signature
A signature: 65 bytes: r: [0, 32), s: [32, 64), v: 64.
AbridgedTopic abridge(Topic const &_topic)
Signature sign(Secret const &_k, h256 const &_hash)
Returns siganture of message hash.
void encrypt(Public const &_k, bytesConstRef _plain, bytes &o_cipher)
Encrypts plain text using Public key.
uint8_t const size_t const size
void * memcpy(void *a, const void *b, size_t c)
bool decrypt(Secret const &_k, bytesConstRef _cipher, bytes &o_plaintext)
Decrypts cipher using Secret key.
An (unencrypted) message, constructed from the combination of an Envelope, and, potentially, a Secret key to decrypt the Message.
clock::time_point time_point
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
void proveWork(unsigned _ms)
_T toInt(int _flags=Strict) const
Converts to int of type given; if isString(), decodes as big-endian bytestream.
Class for interpreting Recursive Linear-Prefix Data.
bytes toBytes(int _flags=LaissezFaire) const
Converts to bytearray.
LogBloom bloom(LogEntries const &_logs)