File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -108,9 +108,9 @@ template <compat::size_t Extent>
108
108
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto ecb_impl<Nr>::encrypt_no_padding(
109
109
compat::span<compat::byte, Extent> message) noexcept -> state
110
110
{
111
- static_assert (Extent >= block_length_bytes, " Invalid block length" );
111
+ static_assert (Extent == compat::dynamic_extent || Extent % block_length_bytes == 0 , " Invalid ciphertext length" );
112
112
113
- if (message.size () % block_length_bytes != 0 )
113
+ if (message.size () % block_length_bytes != 0 && !message. empty () )
114
114
{
115
115
return state::incorrect_message_length;
116
116
}
@@ -145,7 +145,9 @@ template <compat::size_t Extent>
145
145
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto ecb_impl<Nr>::decrypt_no_padding(
146
146
compat::span<compat::byte, Extent> ciphertext) noexcept -> state
147
147
{
148
- if (ciphertext.size () % block_length_bytes != 0 )
148
+ static_assert (Extent == compat::dynamic_extent || Extent % block_length_bytes == 0 , " Invalid ciphertext length" );
149
+
150
+ if (ciphertext.size () % block_length_bytes != 0 && !ciphertext.empty ())
149
151
{
150
152
return state::incorrect_message_length;
151
153
}
Original file line number Diff line number Diff line change @@ -116,6 +116,10 @@ void ecb_test()
116
116
BOOST_TEST (gen2.init (key_span) == boost::crypt::state::success);
117
117
BOOST_TEST (gen2.encrypt_no_padding (bad_message) == boost::crypt::state::incorrect_message_length);
118
118
BOOST_TEST (gen2.encrypt_no_padding (bad_message_span) == boost::crypt::state::incorrect_message_length);
119
+
120
+ std::array<std::byte, 1000 > incorrect_size {};
121
+ std::span<std::byte, std::dynamic_extent> incorrect_size_span {incorrect_size};
122
+ BOOST_TEST (gen2.decrypt_no_padding (incorrect_size_span) == boost::crypt::state::incorrect_message_length);
119
123
}
120
124
121
125
/*
You can’t perform that action at this time.
0 commit comments