aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-03-19 22:52:48 -0400
committerJack Lloyd <[email protected]>2016-03-20 09:38:22 -0400
commitb8966d0f89e520cecf3e822241aef38ed9a6d876 (patch)
tree9b5c0f6afa89e8e91ef230e3d7824b10e037802c /src/lib/utils
parentada363473a9491a3b07e3bb6fa2b5fd9f12aec98 (diff)
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.
Diffstat (limited to 'src/lib/utils')
-rw-r--r--src/lib/utils/ct_utils.h14
1 files changed, 9 insertions, 5 deletions
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<typename T, typename Alloc>
-std::vector<T, Alloc> strip_leading_zeros(const std::vector<T, Alloc>& input)
+inline secure_vector<uint8_t> 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<uint8_t>(only_zeros, 1, 0);
}
- return secure_vector<byte>(input.begin() + leading_zeros, input.end());
+ return secure_vector<byte>(in + leading_zeros, in + length);
+ }
+
+inline secure_vector<byte> strip_leading_zeros(const secure_vector<uint8_t>& in)
+ {
+ return strip_leading_zeros(in.data(), in.size());
}
}