diff options
author | Jack Lloyd <[email protected]> | 2017-06-29 11:11:00 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-06-29 11:11:00 -0400 |
commit | 166f6656b5fd62fd88090ca40993673c7e0ea34a (patch) | |
tree | f1f14a05ad21df040f8f3c8a76c9b57b92057dcd /src | |
parent | 1678ab06b69e8ec58a90b6c1f505b6080800f52a (diff) | |
parent | 2b37c13dcf9f8460bf86c4b9096dcc49aed72a44 (diff) |
Merge GH #1096 Avoid undefined behavior in rotation operations
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/utils/rotate.h | 2 |
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))); } |