-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement bitwise operations for negative numbers
To make this work, we need to transform the byte array that OpenSSL gives us to two's complement. The byte array is a 4-byte size in big-endian format, followed by an array of bytes, also in big endian format, which contains the number itself. The number is laid out exactly like an equivalent positive integer in memory; however, if the number is negative, only the most significant bit (which is testable via bytes[4] & 0x80) is set, rather than being in two's complement. Since we expect negative bitwise operations to return results consistent with bitwise operations on the two's complement form, we need to perform the conversion. In addition, after the operation has been performed, if the result is the highest negative number representable by the current bit width, we need to add an extra byte and move some bits around, since leaving it alone would cause OpenSSL to interpret it as negative zero.
- Loading branch information
Showing
2 changed files
with
168 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters