Ask Your Question
1

Can using std::string as a wrapper for hashing raw buffer be problematic?

asked 2021-05-09 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-10-06 20:00:00 +0000

nofretete gravatar image

It is generally not recommended to use std::string as a wrapper for hashing raw buffer because std::string adds a null termination character at the end of the buffer. This null character can affect the hash value produced by the hashing function.

Additionally, std::string may allocate and deallocate memory dynamically, which can affect the performance of the hashing function. It is more efficient to use a fixed-size buffer for hashing and avoid any unnecessary memory allocations.

Instead, it is recommended to use a dedicated hashing function or library that is designed to handle raw buffers directly. Examples of such libraries include OpenSSL's SHA256, BLAKE2, or SHA3. These libraries can efficiently hash raw buffers without introducing any unnecessary overhead.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-05-09 11:00:00 +0000

Seen: 7 times

Last updated: Oct 06 '21