-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Windows compatibility #471
Merged
Merged
Conversation
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
MSVC produces an error for this line. It may be okay with gcc and clang, but actually negating an unsigned value does not make sense, though it's not clear what effect it should have according to the standard. gcc and clang on x86_64 compile this: unsigned int b; b = -b; into this: negl %eax So they treat unsigned negation as two's complement, as if the number was signed). Replace the current expression with its equivalent. The algorithm implies that "b" may only have 0 and 1 as values. Thus this line should be equivalent to b = b ? UINT_MAX : 0; but who knows what weird code paths lead here, so let's play it safe and use something completely equivalent. My little crypto: C is magic.
Fun fact: Windows does not have <sys/types.h> header and does not provide ssize_t in <WinSock2.h>. It is completely POSIX-specific. However, we use this type in Secure Session API. Provide our definition of ssize_t on Windows. We use actual size_t types from MSVC's <stddef.h>, but mark them as "signed". An alternative approach is to replace ssize_t with something else, like int32_t. However, this will require massive changes in all language wrappers which all expect ssize_t. This might actually become necessary when we will be supporting Windows in language wrappers, but some of them may provide ssize_t in their FFI libraries so let's not jump the gun.
Currently NIST test suite runner is POSIX-specific (due to popen(), pathconf(), etc.) It does not compile on Windows with MSVC. Furthermore, Windows does not have <unistd.h> header. Include <unistd.h> only when compiling NIST test runner. With this we can build Soter tests on Windows with NO_NIST_STS=1. We can add Windows support later.
MSVC does not support default initialization syntax. Initialize Secure Session callbacks explicitily to avoid compilation errors on Windows.
Lagovas
approved these changes
May 21, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
vixentael
approved these changes
May 21, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
shadinua
approved these changes
May 22, 2019
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are miscellaneous changes to ensure that Themis code can be compiled with Microsoft Visual Studio C Compiler.
MSVC produces an error for this line. It may be okay with gcc and clang, but actually negating an unsigned value does not make sense, though it's not clear what effect it should have according to the standard.
gcc and clang on x86_64 compile this:
into this:
So they treat unsigned negation as two's complement, as if the number was signed). Replace the current expression with its equivalent.
The algorithm implies that
b
may only have 0 and 1 as values. Thus this line should be equivalent tobut who knows what weird code paths lead here, so let's play it safe and use something completely equivalent. My little crypto: C is magic.
ssize_t
on WindowsFun fact: Windows does not have
<sys/types.h>
header and does not providessize_t
in<WinSock2.h>
. It is completely POSIX-specific. However, we use this type in Secure Session API.Provide our definition of ssize_t on Windows. We use actual size_t types from MSVC's <stddef.h>, but mark them as
signed
.An alternative approach is to replace ssize_t with something else, like int32_t. However, this will require massive changes in all language wrappers which all expect ssize_t. This might actually become necessary when we will be supporting Windows in language wrappers, but some of them may provide ssize_t in their FFI libraries so let's not jump the gun.
<unistd.h>
only for NISTCurrently NIST test suite runner is POSIX-specific (due to popen(), pathconf(), etc.) It does not compile on Windows with MSVC. Furthermore, Windows does not have <unistd.h> header.
Include <unistd.h> only when compiling NIST test runner. With this we can build Soter tests on Windows with NO_NIST_STS=1. We can add Windows support later.
MSVC does not support default initialization syntax. Initialize Secure Session callbacks explicitly to avoid compilation errors on Windows.