aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-06-29 11:11:00 -0400
committerJack Lloyd <[email protected]>2017-06-29 11:11:00 -0400
commit166f6656b5fd62fd88090ca40993673c7e0ea34a (patch)
treef1f14a05ad21df040f8f3c8a76c9b57b92057dcd /src
parent1678ab06b69e8ec58a90b6c1f505b6080800f52a (diff)
parent2b37c13dcf9f8460bf86c4b9096dcc49aed72a44 (diff)
Merge GH #1096 Avoid undefined behavior in rotation operations
Diffstat (limited to 'src')
-rw-r--r--src/lib/utils/rotate.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/lib/utils/rotate.h b/src/lib/utils/rotate.h
index b936521e6..8361e4705 100644
--- a/src/lib/utils/rotate.h
+++ b/src/lib/utils/rotate.h
@@ -20,6 +20,7 @@ namespace Botan {
*/
template<typename T> inline T rotate_left(T input, size_t rot)
{
+ rot %= 8 * sizeof(T);
return (rot == 0) ? input : static_cast<T>((input << rot) | (input >> (8*sizeof(T)-rot)));;
}
@@ -31,6 +32,7 @@ template<typename T> inline T rotate_left(T input, size_t rot)
*/
template<typename T> inline T rotate_right(T input, size_t rot)
{
+ rot %= 8 * sizeof(T);
return (rot == 0) ? input : static_cast<T>((input >> rot) | (input << (8*sizeof(T)-rot)));
}