Support message separation for multiple inputs from same user. (#142)

This commit is contained in:
Savinda Senevirathne
2020-11-06 10:55:40 +05:30
committed by GitHub
parent 202a6a2715
commit 51173e37f2
11 changed files with 241 additions and 114 deletions

View File

@@ -35,8 +35,8 @@ namespace crypto
seckey[0] = KEYPFX_ed25519;
crypto_sign_ed25519_keypair(
reinterpret_cast<unsigned char *>(pubkey.data() + 1), // +1 to skip the prefix byte.
reinterpret_cast<unsigned char *>(seckey.data() + 1)); // +1 to skip the prefix byte.
reinterpret_cast<unsigned char *>(pubkey.data() + 1), // +1 to skip the prefix byte.
reinterpret_cast<unsigned char *>(seckey.data() + 1)); // +1 to skip the prefix byte.
}
/**
@@ -196,4 +196,26 @@ namespace crypto
return hash;
}
/**
* Generates blake3 hash for the given string view vector using stream hashing.
*/
std::string get_hash(const std::vector<std::string_view> &sw_vect)
{
std::string hash;
hash.resize(BLAKE3_OUT_LEN);
// Init stream hashing.
blake3_hasher hasher;
blake3_hasher_init(&hasher);
// Hash is generated only using message in contract output struct.
for (std::string_view sw : sw_vect)
blake3_hasher_update(&hasher, reinterpret_cast<const unsigned char *>(sw.data()), sw.length());
// Get the final hash.
blake3_hasher_finalize(&hasher, reinterpret_cast<unsigned char *>(hash.data()), hash.length());
return hash;
}
} // namespace crypto