aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/hash/shake
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-01-30 12:16:50 -0500
committerJack Lloyd <[email protected]>2018-01-30 12:41:35 -0500
commitc3a2c598f7f9ac714681e7f7c7568dd022451382 (patch)
treef2d7bc6939cbdc81653115eb64bde1f6634df93f /src/lib/hash/shake
parentd8e6c5bd2912e19654ad46389fb27dcb00610b66 (diff)
Avoid allocating zero bytes for SHA-3 padding
Inspired by #1433
Diffstat (limited to 'src/lib/hash/shake')
-rw-r--r--src/lib/hash/shake/shake.cpp17
1 files changed, 2 insertions, 15 deletions
diff --git a/src/lib/hash/shake/shake.cpp b/src/lib/hash/shake/shake.cpp
index ab7c9debe..76ed79a27 100644
--- a/src/lib/hash/shake/shake.cpp
+++ b/src/lib/hash/shake/shake.cpp
@@ -47,15 +47,8 @@ void SHAKE_128::add_data(const uint8_t input[], size_t length)
void SHAKE_128::final_result(uint8_t output[])
{
- std::vector<uint8_t> padding(SHAKE_128_BITRATE / 8 - m_S_pos);
-
- padding[0] = 0x1F;
- padding[padding.size()-1] |= 0x80;
-
- add_data(padding.data(), padding.size());
-
+ SHA_3::finish(SHAKE_128_BITRATE, m_S, m_S_pos, 0x1F, 0x80);
SHA_3::expand(SHAKE_128_BITRATE, m_S, output, output_length());
-
clear();
}
@@ -95,13 +88,7 @@ void SHAKE_256::add_data(const uint8_t input[], size_t length)
void SHAKE_256::final_result(uint8_t output[])
{
- std::vector<uint8_t> padding(SHAKE_256_BITRATE / 8 - m_S_pos);
-
- padding[0] = 0x1F;
- padding[padding.size()-1] |= 0x80;
-
- add_data(padding.data(), padding.size());
-
+ SHA_3::finish(SHAKE_256_BITRATE, m_S, m_S_pos, 0x1F, 0x80);
SHA_3::expand(SHAKE_256_BITRATE, m_S, output, output_length());
clear();