Skip to content

Commit

Permalink
Remove global optimizations for SHA1ProcessMessageBlock()
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenCWills authored and AJenbo committed Apr 17, 2024
1 parent 27e6ef5 commit bbda8dd
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Source/sha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ static void SHA1Init(SHA1Context *context)
context->state[4] = 0xC3D2E1F0;
}

// Global Optimizations (/Og) cause the compiler to interpret
// `SHA1CircularShift(5, A)` as `ror edx, 0x1b`, as if A were an unsigned integer.
// This results in save files being incompatible between vanilla and MSVC Release builds.
#if (_MSC_VER >= 1930) && NDEBUG
#pragma optimize("g", off)
#endif

static void SHA1ProcessMessageBlock(SHA1Context *context)
{
int i, temp;
Expand Down Expand Up @@ -87,6 +94,10 @@ static void SHA1ProcessMessageBlock(SHA1Context *context)
context->state[4] += E;
}

#if (_MSC_VER >= 1930) && NDEBUG
#pragma optimize("g", on)
#endif

static void SHA1Input(SHA1Context *context, const char *message_array, int len)
{
int i, count;
Expand Down

0 comments on commit bbda8dd

Please sign in to comment.