diff options
author | Jack Lloyd <[email protected]> | 2015-10-26 10:45:47 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-10-26 10:45:47 -0400 |
commit | a3d1249709fa983829774bf5536aa114a43077bb (patch) | |
tree | 876db0b25ac9deec37c40b790870a3b58860f934 /src/lib/utils/ct_utils.h | |
parent | b2da74ca508745f00bb3d6b35cbe34d5031e27e7 (diff) |
Asan fix - referencing &vec[vec.size()] instead of vec.end()
Convert to a const time algo
Diffstat (limited to 'src/lib/utils/ct_utils.h')
-rw-r--r-- | src/lib/utils/ct_utils.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/utils/ct_utils.h b/src/lib/utils/ct_utils.h index 2ea07b382..7a13eb246 100644 --- a/src/lib/utils/ct_utils.h +++ b/src/lib/utils/ct_utils.h @@ -138,6 +138,22 @@ inline T min(T a, T b) return select(expand_top_bit(b), b, a); } +template<typename T, typename Alloc> +std::vector<T, Alloc> strip_leading_zeros(const std::vector<T, Alloc>& input) + { + size_t leading_zeros = 0; + + uint8_t only_zeros = 0xFF; + + for(size_t i = 0; i != input.size(); ++i) + { + only_zeros &= CT::is_zero(input[i]); + leading_zeros += CT::select<uint8_t>(only_zeros, 1, 0); + } + + return secure_vector<byte>(input.begin() + leading_zeros, input.end()); + } + } } |