diff options
| author | tobtoht <tob@featherwallet.org> | 2025-07-13 16:50:31 +0000 |
|---|---|---|
| committer | tobtoht <tob@featherwallet.org> | 2025-07-13 16:50:31 +0000 |
| commit | f8c575e0b16825d79dd3f28992bc4e1e29c006a1 (patch) | |
| tree | 8e3e028d0cdbbbc4318008d992bf0af1d5492556 | |
| parent | 3e218c2021a8346e8adb87baaadfb7261ae1477a (diff) | |
| parent | 1d3d30c5076200a308de4764491ace1d8a4d52af (diff) | |
| download | monzero-core-f8c575e0b16825d79dd3f28992bc4e1e29c006a1.tar.gz monzero-core-f8c575e0b16825d79dd3f28992bc4e1e29c006a1.tar.xz monzero-core-f8c575e0b16825d79dd3f28992bc4e1e29c006a1.zip | |
Merge pull request #9986
1d3d30c crypto: check+throw for Cryptonight v1 invalid input (jeffro256)
| -rw-r--r-- | src/crypto/hash.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/crypto/hash.h b/src/crypto/hash.h index 2812422e0..8ea626314 100644 --- a/src/crypto/hash.h +++ b/src/crypto/hash.h @@ -30,8 +30,9 @@ #pragma once -#include <stddef.h> #include <iostream> +#include <stddef.h> +#include <stdexcept> #include "common/pod-class.h" #include "generic-ops.h" @@ -70,11 +71,20 @@ namespace crypto { return h; } + static constexpr void cn_variant1_check(const std::size_t length, const int variant) + { + // see VARIANT1_CHECK in slow-hash.c + if (variant == 1 && length < 43) + throw std::logic_error("Cryptonight variant 1 is undefined for inputs of less than 43 bytes"); + } + inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) { + cn_variant1_check(length, variant); cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height); } inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) { + cn_variant1_check(length, variant); cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height); } |
