diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-18 15:00:33 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-18 15:00:33 -0800 |
commit | cdea8aa87bd98ad6277262803f4a2b8cb48153a3 (patch) | |
tree | 9f7c63ff43ff99f54ddffcc24ab3c625b0dd2084 | |
parent | 4dd04c8f6eca8a85a57349a5be952f8c2f51ec6c (diff) | |
download | cryptography-cdea8aa87bd98ad6277262803f4a2b8cb48153a3.tar.gz cryptography-cdea8aa87bd98ad6277262803f4a2b8cb48153a3.tar.bz2 cryptography-cdea8aa87bd98ad6277262803f4a2b8cb48153a3.zip |
No more undefined behavior
-rw-r--r-- | cryptography/hazmat/primitives/padding.py | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/cryptography/hazmat/primitives/padding.py b/cryptography/hazmat/primitives/padding.py index 938afcec..8df4549e 100644 --- a/cryptography/hazmat/primitives/padding.py +++ b/cryptography/hazmat/primitives/padding.py @@ -26,11 +26,9 @@ _lib = _ffi.verify(""" #include <stdbool.h> /* Returns the value of the input with the most-significant-bit copied to all - of the bits. This relies on implementation details of computers with 2's - complement representations of integers, which is not required by the C - standard. */ + of the bits. */ static uint8_t Cryptography_DUPLICATE_MSB_TO_ALL(uint8_t a) { - return (uint8_t)((int8_t)(a) >> (sizeof(int8_t) * 8 - 1)); + return -(a >> (sizeof(uint8_t) * 8 - 1)); } /* This returns 0xFF if a < b else 0x00, but does so in a constant time |