generator: fix memmove UB warnings
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
408d783c37
commit
3d22b8de8b
|
@ -51,7 +51,7 @@ auto Generator::reseed(const std::string& s) -> void {
|
|||
try {
|
||||
std::lock_guard<std::mutex> lg(mtx);
|
||||
std::string a{fortuna::Util::do_sha(da_key + s)};
|
||||
std::memmove(&G.k[0], &a[0], G.k.SizeInBytes());
|
||||
std::memmove(G.k, a.c_str(), G.k_length);
|
||||
++G.ctr;
|
||||
fmt::print("[i] generator: reseeded\n");
|
||||
} catch(std::exception& e) {
|
||||
|
@ -77,13 +77,11 @@ auto Generator::do_crypto() -> std::string {
|
|||
std::string plain{"Oh, I am fortune's fool!"};
|
||||
std::string cipher, encoded_c;
|
||||
// in case we need to convert counter to string
|
||||
// std::string str_ctr{reinterpret_cast<const char*>(&G.k[0]), G.k.size()};
|
||||
// std::string str_ctr{(G.ctr)};
|
||||
std::string str_ctr{reinterpret_cast<const char*>(&G.ctr)};
|
||||
// 16 bytes --> 128bit
|
||||
static constexpr const std::size_t ctr_length{16};
|
||||
CryptoPP::FixedSizeSecBlock<CryptoPP::byte, ctr_length> ctr;
|
||||
// FIXME: potential (pretty-much) UB
|
||||
std::memmove(&ctr, &G.ctr, ctr_length);
|
||||
std::memmove(ctr, str_ctr.c_str(), ctr_length);
|
||||
|
||||
try {
|
||||
CTR_Mode<Serpent>::Encryption e;
|
||||
|
@ -173,7 +171,7 @@ auto Generator::generate_random_data(uint n) -> std::string {
|
|||
|
||||
/* clear out the old key and set a new one */
|
||||
std::memset(G.k, 0x00, G.k.size());
|
||||
std::memmove(&G.k[0], &dst[0], dst.size());
|
||||
std::memmove(G.k, dst.c_str(), G.k_length);
|
||||
} catch(std::exception& e) {
|
||||
fmt::print("{}", e.what());
|
||||
}
|
||||
|
|
Reference in New Issue