From b8966d0f89e520cecf3e822241aef38ed9a6d876 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sat, 19 Mar 2016 22:52:48 -0400 Subject: Clean up PK decryption encoding. Previously RSA and ElGamal stripped off leading zeros which were then assumed by the padding decoders. Instead have them produce ciphertexts with leading zeros. Changes EME_Raw to strip leading zeros to match existing behavior. --- src/lib/utils/ct_utils.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/lib/utils') diff --git a/src/lib/utils/ct_utils.h b/src/lib/utils/ct_utils.h index ec055374a..5a1d03d4f 100644 --- a/src/lib/utils/ct_utils.h +++ b/src/lib/utils/ct_utils.h @@ -177,20 +177,24 @@ inline T min(T a, T b) return select(expand_top_bit(b), b, a); } -template -std::vector strip_leading_zeros(const std::vector& input) +inline secure_vector strip_leading_zeros(const uint8_t in[], size_t length) { size_t leading_zeros = 0; uint8_t only_zeros = 0xFF; - for(size_t i = 0; i != input.size(); ++i) + for(size_t i = 0; i != length; ++i) { - only_zeros &= CT::is_zero(input[i]); + only_zeros &= CT::is_zero(in[i]); leading_zeros += CT::select(only_zeros, 1, 0); } - return secure_vector(input.begin() + leading_zeros, input.end()); + return secure_vector(in + leading_zeros, in + length); + } + +inline secure_vector strip_leading_zeros(const secure_vector& in) + { + return strip_leading_zeros(in.data(), in.size()); } } -- cgit v1.2.3