forked from dogecoin/dogecoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minimal code changes to allow msvc compilation.
Cherry-picked from: fbf327b
- Loading branch information
1 parent
29aa4e0
commit 99e0be1
Showing
7 changed files
with
56 additions
and
13 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,39 @@ | |
|
||
#include "cleanse.h" | ||
|
||
#include <openssl/crypto.h> | ||
#include <cstring> | ||
|
||
#if defined(_MSC_VER) | ||
#include <Windows.h> // For SecureZeroMemory. | ||
#endif | ||
|
||
/* Compilers have a bad habit of removing "superfluous" memset calls that | ||
* are trying to zero memory. For example, when memset()ing a buffer and | ||
* then free()ing it, the compiler might decide that the memset is | ||
* unobservable and thus can be removed. | ||
* | ||
* Previously we used OpenSSL which tried to stop this by a) implementing | ||
* memset in assembly on x86 and b) putting the function in its own file | ||
* for other platforms. | ||
* | ||
* This change removes those tricks in favour of using asm directives to | ||
* scare the compiler away. As best as our compiler folks can tell, this is | ||
* sufficient and will continue to be so. | ||
* | ||
* Adam Langley <[email protected]> | ||
* Commit: ad1907fe73334d6c696c8539646c21b11178f20f | ||
* BoringSSL (LICENSE: ISC) | ||
*/ | ||
void memory_cleanse(void *ptr, size_t len) | ||
{ | ||
OPENSSL_cleanse(ptr, len); | ||
std::memset(ptr, 0, len); | ||
|
||
/* As best as we can tell, this is sufficient to break any optimisations that | ||
might try to eliminate "superfluous" memsets. If there's an easy way to | ||
detect memset_s, it would be better to use that. */ | ||
#if defined(_MSC_VER) | ||
SecureZeroMemory(ptr, len); | ||
#else | ||
__asm__ __volatile__("" : : "r"(ptr) : "memory"); | ||
#endif | ||
} |
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