std::string --> char array where meaningful #8

Open
opened 2022-01-07 05:44:48 +01:00 by wanderer · 0 comments
Owner

since strings are \0-terminated, this makes for an ugly issue down the road unless it's fixed very soon (std::string has been overused).

examples/candidates:

generator.cpp Lines 49 to 50 in d4c7c61ac4
std::string da_key(reinterpret_cast<const char*>(&G.k[0]),
G.k.SizeInBytes() * 8); // we need the size in bits

generator.cpp Lines 57 to 58 in d4c7c61ac4
std::string a{fortuna::Util::do_sha(da_key + s)};
std::memmove(&G.k[0], &a[0], G.k.SizeInBytes());

r += do_crypto();

util.h Lines 16 to 30 in d4c7c61ac4
static auto do_sha(const std::string& str_to_hash) -> const std::string {
// do sha256
std::string digest;
// no reason not to go for Keccak
CryptoPP::SHA3_256 sha3_256;
CryptoPP::StringSource str_src(str_to_hash, true,
new CryptoPP::HashFilter (
sha3_256, new CryptoPP::HexEncoder(
new CryptoPP::StringSink(digest), false))
);
return digest;
}

return encoded_c;

since strings are `\0`-terminated, this makes for an ugly issue down the road unless it's fixed very soon (`std::string` has been overused). examples/candidates: https://git.dotya.ml/ak-fortuna/fortuna/src/commit/d4c7c61ac47baa7c5dd73029f4692c5c4e7afc50/generator.cpp#L49-L50 https://git.dotya.ml/ak-fortuna/fortuna/src/commit/d4c7c61ac47baa7c5dd73029f4692c5c4e7afc50/generator.cpp#L57-L58 https://git.dotya.ml/ak-fortuna/fortuna/src/commit/d4c7c61ac47baa7c5dd73029f4692c5c4e7afc50/generator.cpp#L135 https://git.dotya.ml/ak-fortuna/fortuna/src/commit/d4c7c61ac47baa7c5dd73029f4692c5c4e7afc50/util.h#L16-L30 https://git.dotya.ml/ak-fortuna/fortuna/src/commit/d4c7c61ac47baa7c5dd73029f4692c5c4e7afc50/generator.cpp#L127
wanderer added the
bug
label 2022-01-07 05:44:48 +01:00
wanderer self-assigned this 2022-01-07 05:44:48 +01:00
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: ak-fortuna/fortuna#8
No description provided.